/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 19ms 768.0 KiB
#3 Wrong Answer 20ms 564.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        long long n,i,j,k,cnt=0,f=0,ans=0;
        cin>>n;
        string a,b,c,d,e,g;
        cin>>a>>b;
        c=a;
        d=b;
        sort(c.begin(),c.end());
        sort(d.begin(),d.end());
        if(a==c || b==d){
            cout<<"Yes"<<"\n";
        }else{
            for(i=0;i<n-1;i++){
               if(a[i]>a[i+1]){
                 if(b[i]>a[i+1]){
                    f=1;
                    break;
                 }else{
                    e.push_back(b[i]);
                 }
               }else{
                e.push_back(a[i]);
               }
            }
            e.push_back(a.back());
            if(f==1 || !is_sorted(g.begin(),g.end())){
                for(i=0;i<n-1;i++){
                    if(b[i]>b[i+1]){
                        if(a[i]>b[i+1]){
                            cnt=1;
                            break;
                        }else{
                            g.push_back(a[i]);
                        }
                    }else{
                        g.push_back(b[i]);
                    }
                }g.push_back(b.back());
                if(cnt==1){
                    cout<<"No"<<"\n";
                }else{
                    //cout<<g<<"\n";
                    if(is_sorted(g.begin(),g.end())){
                    cout<<"Yes"<<"\n";}
                    else{
                        cout<<"No"<<"\n";
                    }
                }
            }else{
               // cout<<e<<"\n";
                 if(is_sorted(e.begin(),e.end())){
                    cout<<"Yes"<<"\n";}
                    else{
                        cout<<"No"<<"\n";
                    }
            }
        }

    }
}

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:52:59
Judged At
2024-12-07 10:52:59
Judged By
Score
1
Total Time
20ms
Peak Memory
768.0 KiB