/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 27ms 544.0 KiB
#3 Wrong Answer 30ms 556.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)
        {
            for (int i = 0; i < n - 1; i++)
            {
                if (s1[i] > s1[i + 1])
                {
                    swap(s1[i], s2[i]);
                    if (issorted(s1) || issorted(s2))
                    {
                        sorted = true;
                        break;
                    }
                }
            }

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

        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:34:59
Judged At
2024-12-07 11:34:59
Judged By
Score
1
Total Time
30ms
Peak Memory
556.0 KiB