Wrong Answer
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])
{
if(t[n-1]<=s[n-2])
{
s1.push_back(t[n-1]);
}
else
{
a==false;
}
}
else
{
s1.push_back(s[n-2]);
}
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])
{
if(s[n-1]<=t[n-2])
{
t1.push_back(s[n-1]);
}
else
{
b==false;
}
}
else
{
t1.push_back(t[n-2]);
}
//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 11:07:24
- Judged At
- 2024-12-07 11:07:24
- Judged By
- Score
- 1
- Total Time
- 4ms
- Peak Memory
- 796.0 KiB