/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 560.0 KiB
#2 Wrong Answer 4ms 588.0 KiB
#3 Wrong Answer 4ms 772.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios ::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        string s1,t1;
        bool a=true,b=true;
        for(int i=0;i<n-1;i++)
        {
            if(s[i]<=s[i+1])
            {
                s1.push_back(s[i]);
            }
            else
            {
                if(t[i]<=s[i+1])
                {
                    s1.push_back(t[i]);
                }
                else
                {
                    a=false;
                    break;
                }
            }
        }
        if(s[n-1] <=s[n-2])
        {
            s1.push_back(s[n-2]);
        }
        else
        {
            if(t[n-1]<=s[n-2])
            {
                s1.push_back(t[n-1]);
            }
            else
            {
                a==false;
            }
        }
        for(int i=0;i<n-1;i++)
        {
            if(t[i]<=t[i+1])
            {
                t1.push_back(t[i]);
            }
            else
            {
                if(s[i]<=t[i+1])
                {
                    t1.push_back(s[i]);
                }
                else
                {
                    b=false;
                    break;
                }
            }
        }
        if(t[n-1] <=t[n-2])
        {
            t1.push_back(t[n-2]);
        }
        else
        {
            if(s[n-1]<=t[n-2])
            {
                t1.push_back(s[n-1]);
            }
            else
            {
                b==false;
            }
        }
       // cout<<s1<<" "<<t1<<'\n';
        if(s1.size()==n)
        {
            if(is_sorted(s1.begin(),s1.end()))
            {
                cout<<"Yes\n";
               
            }
            else
            {
                cout<<"No\n";
               
            }
        }
        else if(t1.size()==n)
        {
            if(is_sorted(t1.begin(),t1.end()))
            {
                cout<<"Yes\n";
            
            }
            else
            {
                cout<<"No\n";
               
            }
        }
        else if(a==false &&  b==false)
        {
            cout<<"No\n";
        }
        else if(a==true || b==true)
        {
            cout<<"Yes\n";
        }
    }
    return 0;
}

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 10:45:05
Judged At
2024-12-07 10:45:05
Judged By
Score
1
Total Time
4ms
Peak Memory
772.0 KiB