CSES - Aalto Competitive Programming 2024 - wk1 - Mon - Results
Submission details
Task:Babaza Game
Sender:GPR
Submission time:2024-09-02 17:50:43 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.02 sdetails
#4ACCEPTED0.02 sdetails
#50.02 sdetails
#6ACCEPTED0.02 sdetails
#7ACCEPTED0.02 sdetails
#8ACCEPTED0.02 sdetails
#9ACCEPTED0.02 sdetails
#10ACCEPTED0.02 sdetails
#11ACCEPTED0.02 sdetails
#12ACCEPTED0.02 sdetails
#13ACCEPTED0.02 sdetails
#14ACCEPTED0.02 sdetails

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)
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]
                    cc = list(''.join(c3))
                    if is_ok(kem, bef, aft):
                        cc[i] = kem
                        if is_valid(cc):
                            c3 = cc
 
 
    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:

input
AXYB
CXYD

correct output
AXYB
CXYD

user output
AXYB
CXYB
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