QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415458#855. A Very Different WordAtalasion#AC ✓1ms3796kbC++142.1kb2024-05-20 21:44:132024-05-20 21:44:15

Judging History

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

  • [2024-05-20 21:44:15]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3796kb
  • [2024-05-20 21:44:13]
  • 提交

answer


#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
const int H = 313;

int Main(){
	string s, t;
	int n;
	char k;
	cin >> n >> k >> s >> t;
	int koj = -1;
	bool f = 0;
	for (int i = 0; i < n - 1; i++){
		if (t[i] == s[i] && s[i] == k) f = 1;
		if (t[i] != s[i] && koj == -1) koj = i;
		if (t[i] - s[i] > 1){
			for (int j = 0; j < i; j++) cout << s[j];
			cout << char(s[i] + 1);
			for (int j = i + 1; j < n; j++) cout << k;
			cout << '\n';
			return 0;
		}
		if (koj != -1) break;
	}
	if (koj == -1){
		for (int i = s[n - 1] - 'a' + 1; i < t[n - 1] - 'a'; i++){
			if (i == k - 'a' || f){
				for (int j = 0; j < n - 1; j ++) cout << s[j];
				cout << char(i + 'a');
				cout << '\n';
				return 0;
			}
		}
		return cout << "NO\n", 0;
	}
	for (int i = s[n - 1] - 'a' + 1; i < 26; i++){
		if (i == k - 'a' || f || s[koj] == k){
			for (int j = 0; j < n - 1; j++) cout << s[j];
			cout << char(i + 'a') << '\n';
			return 0;
		}
	}
	
	for (int i = n - 2 ; i > koj; i--){
		if (s[i] != 'z'){
			for (int j = 0; j < i; j++) cout << s[j];
			cout << 'z';
			for (int j = i + 1; j < n; j++) cout << k;
			cout << '\n';
			return 0;
		}
	}
	for (int i = 0; i < t[n - 1] - 'a'; i++){
		if (i == k - 'a' || f || t[koj] == k){
			for (int j = 0; j < n - 1; j++) cout << t[j];
			cout << char(i + 'a') << '\n';
			return 0;
		}
	}
	for (int i = n - 2; i > koj; i--){
		if (t[i] != 'a'){
			for (int j = 0; j < i; j++) cout << t[j];
			cout << 'a';
			for (int j = i + 1; j < n; j++) cout << k;
			cout << '\n';
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--) Main();
	



}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

christmasb
tmmmmm
ithinkthereforeisleza
NO

result:

ok OK!

Test #2:

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

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:

christmasb
ithinkthereforeisleza
NO
tmmmmm
aaaaaaab
bllllllll
abcayyyyyyyyya
christmasb
abcabcxyyyyzlmnu
qwertyaaaav
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: 0ms
memory: 3796kb

input:

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

output:

NO
yadswtbucvyybqqbzelblcqjxodpsicgtjzagazrnqxycqhadpljbzlneduawfsfxxvoipdafjdpamgeydrjercplbvdbhieiofdgegkgxezghtwwhqzigfjgouvputfkmawngwgvgsknfkgupbwujaielpryeifhhhhhhhhhhhhhhhhhhhhhhh
rumgrrrrrrrrrrrrrr
lxnfntyxjpmtqnqubthagyufffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

result:

ok OK!

Test #4:

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

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: 3648kb

input:

4
25000 h
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

NO
zxyyadswtbucvyybqqbzelblcqjxodpsicgtjzagazrnqxycqhadpljbzlneduawfsfxxvoipdafjdpamgeydrjercplbvdbhieiofdgegkgxezghtwwhqzigfjgouvputfkmawngwgvgsknfkgupbwujaielpryeiffukygdjxmvlkziruxbuxqzguhcevzputscajbughtgvtaevoywqbvkmgvtmitzclxnfntyxjpmtqnqubthagyoldfdqtcpsqwchxvlmenxfdstdfvlkwqzsygokkgimzsyprkc...

result:

ok OK!