/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 540.0 KiB
#2 Wrong Answer 20ms 780.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

int issorted(string s)
{
    string temps = s;
    sort(s.begin(), s.end());

    return temps == s;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        string s1, s2;
        cin >> s1 >> s2;

        string copys1 = s1, copys2 = s2;

        bool sorted = false;
        if (issorted(s1) || issorted(s2))
        {
            sorted = true;
        }

        if (!sorted)
        {
            sort(copys2.begin(), copys2.end());
            sort(copys1.begin(), copys1.end());
            for (int i = 0; i < n - 1; i++)
            {
                if (s1[i] > s1[i + 1])
                {
                    swap(s1[i], s2[i]);
                    if(copys1 == s1 || copys2 == s2) {
                        sorted = true;
                        break;
                    }
                    swap(s1[i], s2[i]);
                }
            }

            if (!sorted)
            {
                for (int i = 0; i < n - 1; i++)
                {
                    if (s2[i] > s2[i + 1])
                    {
                        swap(s2[i], s1[i]);
                        if(copys2 == s2 || copys1 == s1) {
                            sorted = true;
                            break;
                        }
                        swap(s2[i], s1[i]);
                    }
                }
            }
        }

        if(sorted) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1117 String Sorted
Contest
LU IUJPC : Sylhet Division 2024, Mock Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-07 11:47:50
Judged At
2024-12-07 11:47:50
Judged By
Score
0
Total Time
20ms
Peak Memory
780.0 KiB