/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Accepted 3ms 540.0 KiB
#3 Accepted 4ms 540.0 KiB
#4 Accepted 3ms 768.0 KiB
#5 Accepted 2ms 772.0 KiB
#6 Accepted 2ms 540.0 KiB
#7 Accepted 2ms 540.0 KiB
#8 Accepted 4ms 1.008 MiB
#9 Accepted 4ms 804.0 KiB
#10 Accepted 4ms 716.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define all(v) v.begin(), v.end()
#define endl '\n'
#define nl '\n'
// vector<int> primes;
// bool is_prime[(int)1e7 + 10];
using namespace std;
void solve();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // cout<<"Case "<<i<<": ";
        solve();
    }
}
// seive here
//  void seive(int n)
//  {
//      is_prime[0] = is_prime[1] = 1;
//      for (int i = 4; i <= 1e7 + 10; i += 2)
//      {
//          is_prime[i] = 1;
//      }
//      for (int i = 3; i * i <= 1e7 + 10; i += 2)
//      {
//          if (is_prime[i] == 0)
//          {
//              for (int j = i + i; j <= 1e7 + 10; j += i)
//              {
//                  is_prime[j] = 1;
//              }
//          }
//      }

//     //for finding primes in a single vector
//     // for (int i = 0; i <= 1e7 + 10; i++)
//     // {
//     //     if (is_prime[i] == 0)
//     //     {
//     //         primes.push_back(i);
//     //     }
//     // }

//     //return;
// }

void solve()
{
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    string res;
    res.push_back(min(a[0], b[0]));
    for (int i = 1; i < n; i++)
    {
        char mnm = min(a[i], b[i]);
        if (mnm >= res[i - 1])
        {
            res.push_back(mnm);
        }
        else
        {
            if (max(a[i], b[i]) < res[i - 1])
            {
                cout << "No\n";
                return;
            }else{
                res.push_back(max(a[i],b[i]));
            }
        }
    }
    cout << "Yes\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:24:07
Judged At
2024-12-07 10:24:07
Judged By
Score
100
Total Time
4ms
Peak Memory
1.008 MiB