/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 5ms 580.0 KiB
#3 Accepted 5ms 584.0 KiB
#4 Accepted 5ms 588.0 KiB
#5 Accepted 3ms 564.0 KiB
#6 Accepted 3ms 488.0 KiB
#7 Accepted 3ms 580.0 KiB
#8 Accepted 4ms 852.0 KiB
#9 Accepted 3ms 704.0 KiB
#10 Accepted 4ms 788.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using minheap = priority_queue<long long, vector<long long>, greater<long long>>;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define ll long long
#define ld long double
#define MOD 1000000007
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl '\n'
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define print(v) for(auto e:v) cout<<e<<" "; cout<<endl;
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);

void solve(int tc)
{
    //cout<<"Case "<<tc<<": ";
    int n; cin >>n;
    string a,b,c; cin>> a >> b;
    c.push_back(min(a[0],b[0]));
    for(int i=1;i<n;i++)
    {
        char c1 = a[i], c2 = b[i];
        char mn = min(c1,c2);
        char mx = max(c1,c2);
        if(mn >= c[i-1]) c.push_back(mn);
        else c.push_back(mx);
    }
    string d = c;
    sort(d.begin(),d.end());
    if(c==d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main()
{
    life_is_a_race
    int t=1; 
    cin>>t;
    for(int i=1;i<=t;i++) solve(i);
}

Information

Submit By
Type
Submission
Problem
P1117 String Sorted
Contest
Lockout contest round-1 ( Mazharul Islam vs Thakur Emon)
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-04 17:14:51
Judged At
2024-11-11 02:33:44
Judged By
Score
100
Total Time
5ms
Peak Memory
852.0 KiB