/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 18ms 564.0 KiB
#3 Wrong Answer 16ms 540.0 KiB

Code




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

int isSorted(string st, int n)
{
    if (n == 1)
    {
        return 1;
    }

    for (int i = 0; i < n - 1; i++)
    {
        if (st[i] > st[i + 1])
        {
            return 0;
        }
    }

    return 1;
}

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

        // cout << isSorted(s1, n) << endl;

        int flag = 1;
        for (int i = 0; i < n; i++)
        {
            swap(s1[i], s2[i]);
            if (isSorted(s1, n) || isSorted(s2, n))
            {
                cout << "Yes" << endl;
                flag = 0;
                break;
            }
            else
            {
                swap(s1[i], s2[i]);
            }
            
        }

        if (flag)
        {
            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:37:54
Judged At
2024-12-07 11:37:54
Judged By
Score
1
Total Time
18ms
Peak Memory
564.0 KiB