Task: | Babaza Game |
Sender: | GPR |
Submission time: | 2024-09-03 12:10:18 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.02 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | ACCEPTED | 0.02 s | details |
#6 | ACCEPTED | 0.02 s | details |
#7 | ACCEPTED | 0.02 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.02 s | details |
#10 | ACCEPTED | 0.02 s | details |
#11 | ACCEPTED | 0.02 s | details |
#12 | ACCEPTED | 0.02 s | details |
#13 | ACCEPTED | 0.02 s | details |
#14 | ACCEPTED | 0.02 s | details |
Code
s = input() t = input() def is_valid(x): n = len(x) if n == 1: return True for i in range(1,n): if x[i] == x[i - 1]: return False return True def is_ok(cur, bef, aft): if bef != None and cur == bef: return False if aft != None and cur == aft: return False return True print(s) n = len(s) if n == 1: print(t) exit(0) pos = [] ok = True for i in range(n): if s[i] != t[i]: if len(pos) == 0: pos.append(i) elif abs(pos[-1] - i) <= 1: ok = False break if ok: print(t) exit(0) while s != t: c1 = list(s) for i in range(0, n, 2): if s[i] != t[i]: ok = True if 0 <= i - 1 and s[i - 1] == t[i]: ok = False if i + 1 < n and s[i + 1] == t[i]: ok = False if ok: c1[i] = t[i] c2 = list(s) for i in range(1, n, 2): if s[i] != t[i]: ok = True if 0 <= i - 1 and s[i - 1] == t[i]: ok = False if i + 1 < n and s[i + 1] == t[i]: ok = False if ok: c2[i] = t[i] dif1 = 0 dif2 = 0 for i in range(n): if c1[i] != t[i]: dif1 += 1 if c2[i] != t[i]: dif2 += 1 if dif1 < dif2: s = ''.join(c1) print(s) continue if dif1 > dif2: s = ''.join(c2) print(s) continue c3 = list(s) for i in range(0, n, 2): if s[i] != t[i]: ok = True if 0 <= i - 1 and s[i - 1] == t[i]: ok = False if i + 1 < n and s[i + 1] == t[i]: ok = False if ok: c3[i] = t[i] else: for kem in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": bef = None aft = None if 0 <= i - 1: bef = s[i - 1] if i + 1 < n: aft = s[i + 1] if is_ok(kem, bef, aft): c3[i] = kem s = ''.join(c3) print(s)
Test details
Test 1
Verdict: ACCEPTED
input |
---|
A B |
correct output |
---|
A B |
user output |
---|
A B |
Test 2
Verdict: ACCEPTED
input |
---|
BABAZA BACBCB |
correct output |
---|
BABAZA BACACA BACBCB |
user output |
---|
BABAZA BACACA BACBCB |
Test 3
Verdict: ACCEPTED
input |
---|
AB BA |
correct output |
---|
AB CB CA BA |
user output |
---|
AB ZB ZA BA |
Test 4
Verdict: ACCEPTED
input |
---|
ABC BCD |
correct output |
---|
ABC DBD DCD BCD |
user output |
---|
ABC ABD ACD BCD |
Test 5
Verdict: ACCEPTED
input |
---|
AXYB CXYD |
correct output |
---|
AXYB CXYD |
user output |
---|
AXYB CXYD |
Test 6
Verdict: ACCEPTED
input |
---|
LMIJLF PAQBMH |
correct output |
---|
LMIJLF PMQJMF PAQBMH |
user output |
---|
LMIJLF PMQJMF PAQBMH |
Test 7
Verdict: ACCEPTED
input |
---|
PNIWLSLIH CRLVPUFHD |
correct output |
---|
PNIWLSLIH CNLWPSFID CRLVPUFHD |
user output |
---|
PNIWLSLIH CNLWPSFID CRLVPUFHD |
Test 8
Verdict: ACCEPTED
input |
---|
ZDYIAVTKL ZJKVXGAUM |
correct output |
---|
ZDYIAVTKL ZJYVAGTUL ZJKVXGAUM |
user output |
---|
ZDYIAVTKL ZDKIXVAKM ZJKVXGAUM |
Test 9
Verdict: ACCEPTED
input |
---|
FBIXISJH NXZIESMG |
correct output |
---|
FBIXISJH NBZXESMH NXZIESMG |
user output |
---|
FBIXISJH NBZXESMH NXZIESMG |
Test 10
Verdict: ACCEPTED
input |
---|
OPGW QJIE |
correct output |
---|
OPGW QPIW QJIE |
user output |
---|
OPGW QPIW QJIE |
Test 11
Verdict: ACCEPTED
input |
---|
DUKNPKQZBL NZPBMOEBIC |
correct output |
---|
DUKNPKQZBL NUPNMKEZIL NZPBMOEBIC |
user output |
---|
DUKNPKQZBL NUPNMKEZIL NZPBMOEBIC |
Test 12
Verdict: ACCEPTED
input |
---|
ZWDTX HZOXI |
correct output |
---|
ZWDTX HWOTI HZOXI |
user output |
---|
ZWDTX HWOTI HZOXI |
Test 13
Verdict: ACCEPTED
input |
---|
URJF ITIQ |
correct output |
---|
URJF IRIF ITIQ |
user output |
---|
URJF IRIF ITIQ |
Test 14
Verdict: ACCEPTED
input |
---|
WYWBWU IRYVBA |
correct output |
---|
WYWBWU WRWVWA IRYVBA |
user output |
---|
WYWBWU WRWVWA IRYVBA |