/ SeriousOJ /

Record Detail

Wrong Answer


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

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define all(v) v.begin(),v.end()
#define FIO \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);\
    cout.tie(NULL);

void solve()
{
    
  ll n; cin >> n;

  string s,t; cin >> s >> t;

  string s1 = s;

    s = "A" + s;
    t = "A" + t;

  bool check1 = false, check2 = false;

  for(ll i = 1; i <= n; i++)
  {
    char c1 = s[i], c2 = t[i];

     if(c1 >= s[i - 1] && c2 >= s[i - 1])
     {
         s[i] = min(c1,c2);
     }
     else if(c1 >= s[i - 1])
     {
         s[i] = c1;
     }
     else if(c2 >= s[i - 1])
     {
         s[i] = c2;
     }

     else 
     {
        check1 = true;
        break;
     }
  }


  for(ll i = 1; i <= n; i++)
  {
    char c1 = t[i], c2 = s1[i];

     if(c1 >= t[i - 1] && c2 >= t[i - 1])
     {
         t[i] = min(c1,c2);
     }
     else if(c1 >= t[i - 1])
     {
         t[i] = c1;
     }
     else if(c2 >= t[i - 1])
     {
        t[i] = c2;
     }

     else 
     {
        check2 = true;
        break;
     }
  }

  cout << (check1 && check2 ? "No" : "Yes") << "\n";

}

int32_t main()
{
    ll t=1;
    cin>>t;
    for(ll i=1;i<=t;i++)
    {
        // cout<<"Case "<<i<<": ";
        solve();
    }
}

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:49:14
Judged At
2024-12-07 10:49:14
Judged By
Score
1
Total Time
18ms
Peak Memory
564.0 KiB