QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546837#855. A Very Different WordRafat_KabirAC ✓1ms3712kbC++206.8kb2024-09-04 14:32:332024-09-04 14:32:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-04 14:32:33]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3712kb
  • [2024-09-04 14:32:33]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
//#define MAXN 1000000

void solve(int it)
{
    ll n;
    char k;
    string a, b;
    cin >> n >> k >> a >> b;
    ll idx = 0;
    bool already = false;
    while(a[idx] == b[idx]){
        if(a[idx] == k) already = true;
        ++idx;
    }
    // if(idx == n){
    //     cout << "NO\n";
    //     return;
    // }
    if(a[idx] < k && k < b[idx]){
        FOR(0, idx-1, i) cout << a[i];
        FOR(idx, n-1, i) cout << k;
        cout << "\n";
        return;
    }
    if(already){
        if(idx == n - 1 && b[idx]-a[idx] == 1){
            cout << "NO\n";
            return;
        }
        if(b[idx]-a[idx] > 1){
            FOR(0, idx-1, i) cout << a[i];
            cout << (char)(a[idx]+1);
            FOR(idx+1, n - 1, i) cout << k;
            cout << "\n";
            return;
        }

    }else{
        if(idx == n - 1){
            cout << "NO\n";
            return;
        }
    }
    already = false;   
    FOR(0, idx, i){
        if(a[i] == k){
            already = true;
            break;
        }
    }
    if(already){
        bool doable = false;
        FOR(idx + 1, n - 1, i){
            if(a[i] != 'z'){
                doable = true;
                break;
            }
        }
        if(doable){
            FOR(0, idx, i) cout << a[i];
            FOR(idx + 1, n - 1, i){
                if(a[i] != 'z'){
                    cout << 'z';
                }else{
                    cout << a[i];
                }
            }
            cout << "\n";
            return;
        }
    }
    already = false;
    FOR(0, idx, i){
        if(b[i] == k){
            already = true;
            break;
        }
    }
    if(already){
        bool doable = false;
        FOR(idx + 1, n - 1, i){
            if(b[i] != 'a'){
                doable = true;
                break;
            }
        }
        if(doable){
            FOR(0, idx, i) cout << b[i];
            FOR(idx + 1, n - 1, i){
                if(b[i] != 'a'){
                    cout << 'a';
                }else{
                    cout << b[i];
                }
            }
            cout << "\n";
            return;
        }
    }
    if(idx == n - 1){
        cout << "NO\n";
        return;
    }
    if(b[idx]-a[idx] > 1){
        // if(idx == n-1){
        //     cout << "NO\n";
        //     return;
        // }
        FOR(0, idx - 1, i) cout << a[i];
        cout << (char)(a[idx]+1);
        FOR(idx + 1, n - 1, i) cout << k ;
        cout << "\n";
        return;
    }
    bool ok = false;
    ROF(n-2, idx+1, i){
        if(a[i] != 'z'){
            ok = true;
            break;
        }
    }
    if(ok){
        FOR(0, idx, i) cout << a[i];
        ok = false;
        FOR(idx + 1, n - 1, i){
            if(ok) cout << k;
            else if(a[i] != 'z'){
                cout << 'z';
                ok = true;
            }else cout << a[i];
        }
        cout << "\n";
        return;
    }
    ROF(n-2, idx+1, i){
        if(b[i] != 'a'){
            ok = true;
            break;
        }
    }
    if(ok){
        FOR(0, idx, i) cout << b[i];
        ok = false;
        FOR(idx + 1, n - 1, i){
            if(ok) cout << k;
            else if(b[i] != 'a'){
                cout << 'a';
                ok = true;
            }else cout << b[i];
        }
        cout << "\n";
        return;
    }
    if(a[idx] == k){
        FOR(idx + 1, n - 1, i){
            if(a[i] != 'z'){
                ok = true;
                break;
            }
        }
        if(ok){
            FOR(0, idx, i) cout << a[i];
            FOR(idx+1, n -1, i) cout << 'z';
            cout << "\n";
            return;
        }
    }
    if(b[idx] == k){
        FOR(idx + 1, n - 1, i){
            if(b[i] != 'a'){
                ok = true;
                break;
            }
        }
        if(ok){
            FOR(0, idx, i) cout << b[i];
            FOR(idx+1, n -1, i) cout << 'a';
            cout << "\n";
            return;
        }
    }
    cout << "NO\n";

}


int main()
{
    fast_cin();    
    ll t = 1;
    cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

4
10 m
christmasa
christmasx
6 m
spring
winter
21 a
ithinkthereforeisleep
ithinkthereforeithink
3 z
tcs
tcz

output:

christmasm
tmmmmm
ithinkthereforeiszaaa
NO

result:

ok OK!

Test #2:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

149
10 m
christmasa
christmasx
21 a
ithinkthereforeisleep
ithinkthereforeithink
3 z
tcs
tcz
6 m
spring
winter
8 b
aaaaaaaa
aaaaaaac
9 l
aaabbbccc
xxxyyyzzz
14 c
abcaxzzzzzzzzz
abcayyyyyyyyyy
10 a
christmasa
christmasx
16 x
abcabcxyyyyzlmnt
abcabcxyyyyzlmob
11 q
qwertyaaaau
qwertyaaaba
12 z
nomnomnom...

output:

christmasm
ithinkthereforeiszaaa
NO
tmmmmm
aaaaaaab
lllllllll
abcayaaaaaaaaa
christmasb
abcabcxyyyyzlmnz
qwertyaaaaz
NO
NO
NO
NO
y
NO
x
r
v
t
u
x
p
y
k
k
p
w
o
r
f
s
y
f
y
p
NO
p
g
o
k
y
m
NO
t
v
r
w
n
o
e
i
o
l
x
q
i
q
o
u
c
NO
h
n
f
f
j
w
y
s
v
y
h
i
n
NO
t
s
l
v
m
v
u
r
m
j
t
v
t
h
k
q
x
h
t
x
f
...

result:

ok OK!

Test #3:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

308
16 r
pppppppppppppppp
pppppppppppppppq
183 h
yadswtbucvyybqqbzelblcqjxodpsicgtjzagazrnqxycqhadpljbzlneduawfsfxxvoipdafjdpamgeydrjercplbvdbhieiofdgegkgxezghtwwhqzigfjgouvputfkmawngwgvgsknfkgupbwujaielpryeifgfukygdjxmvlkziruxbuxqz
yadswtbucvyybqqbzelblcqjxodpsicgtjzagazrnqxycqhadpljbzlneduawfsfxxv...

output:

NO
yadswtbucvyybqqbzelblcqjxodpsicgtjzagazrnqxycqhadpljbzlneduawfsfxxvoipdafjdpamgeydrjercplbvdbhieiofdgegkgxezghtwwhqzigfjgouvputfkmawngwgvgsknfkgupbwujaielpryeifhhhhhhhhhhhhhhhhhhhhhhh
rumrrrrrrrrrrrrrrr
lxnfntyxjpmtqnqubthagyufffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

result:

ok OK!

Test #4:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

2534
49 v
sttadpsqbqbrttbnnaudjbicnhslcmpgbfphuafaunknstbna
sttadpsqbqbrttbnnaudjbicnhslcmpgbfphuafaunknstbnf
31 y
jhbujlddqaseoestrlgmcaehcmakfdc
jhbujlddqaseoestrlgmcaehcmakfdt
19 w
dobmjbrdafhdglecfdf
dobmjbrdafhdglecfdi
45 v
dufgpssgnuhfehflqrmqpeijaskfsfrfpileifqmbsqia
dufgpssgnuhfehflqrmqpeija...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok OK!

Test #5:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

4
25000 h
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

NO
zxyyadswtbucvyybqqbzelblcqjxodpsicgtjzagazrnqxycqhadpljbzlneduawfsfxxvoipdafjdpamgeydrjercplbvdbhieiofdgegkgxezghtwwhqzigfjgouvputfkmawngwgvgsknfkgupbwujaielpryeiffukygdjxmvlkziruxbuxqzguhcevzputscajbughtgvtaevoywqbvkmgvtmitzclxnfntyxjpmtqnqubthagyoldfdqtcpsqwchxvlmenxfdstdfvlkwqzsygokkgimzsyprkc...

result:

ok OK!