Accepted
Code
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define opt() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+10 ;
const int mod= 1e9+7 ;
#define pb push_back
#define mp make_pair
int32_t main()
{
opt();
int tt=1;
cin>>tt;
for(int tc=1; tc<=tt; tc++)
{
int n ;
cin>>n ;
string s1,s2 ;
cin>>s1 >>s2 ;
string ans ;
if(s1[0]>s2[0])ans.pb(s2[0]);
else ans.pb(s1[0]);
bool f=false;
for(int i=1; i<n-1; i++)
{
bool ok=false;
char tm,tmp1;
if(s1[i]>s2[i])tm=s2[i],tmp1=s1[i];
else tm=s1[i],tmp1=s2[i];
if(tm>=ans.back() ||tm>=ans.back() )
{
if(tm<=s1[i+1] || tm<=s2[i+1])
{
ok=true;
ans.pb(tm);
}
}
if(!ok)
{
if(tmp1>=ans.back() ||tmp1>=ans.back() )
{
if(tmp1<=s1[i+1] || tmp1<=s2[i+1])
{
ok=true;
ans.pb(tmp1);
}
}
}
if(!ok)
{
f=true;
break;
}
}
//cout << ans <<"\n" ;
if(s1[n-1]<=s2[n-1])ans.pb(s2[n-1]);
else ans.pb(s1[n-1]);
if (!(is_sorted (ans.begin () ,ans.end ())) )f=true;
cout<<(f?"No":"Yes")<<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 10:43:42
- Judged At
- 2024-12-07 10:43:42
- Judged By
- Score
- 100
- Total Time
- 12ms
- Peak Memory
- 1.027 MiB