/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 540.0 KiB
#2 Wrong Answer 23ms 572.0 KiB

Code

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


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

        string copys1 = s1, copys2 = s2;

        sort(copys1.begin(), copys1.end());
        sort(copys2.begin(), copys2.end());

        bool sorted = false;
        if(copys1 == s1 || copys2 == s2) {
            cout << "Yes" << endl;
            sorted = true;
        }
        else {
            for(int i = 0; i < n - 1; i++) {
                if(s1[i] > s1[i + 1]) {
                    if(s1[i] < s2[i]) {
                        swap(s1[i], s2[i]);
                        if(s1 == copys1 || s1 == copys2) {
                            cout << "Yes" << endl;
                            sorted = true;
                            break;
                        }
                        else {
                            swap(s1[i], s2[i]);
                        }
                    }
                }
            }
        }

        if(!sorted) {
            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:59:26
Judged At
2024-12-07 11:59:26
Judged By
Score
0
Total Time
23ms
Peak Memory
572.0 KiB