CSES - Aalto Competitive Programming 2024 - wk1 - Mon - Results
Submission details
Task:Babaza Game
Sender:GPR
Submission time:2024-09-02 18:32:33 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.02 sdetails
#4--details
#5ACCEPTED0.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
#140.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:
    pos = []
    for i in range(n):
        if s[i] != t[i]:
            if len(pos) == 0:
                pos.append(i)
            else:
                if abs(pos[-1] - i) > 1:
                    pos.append(i)

    c = list(s)
    for p in pos:
        ok = True
        if 0 <= p - 1 and s[p - 1] == t[p]:
            ok = False
        if p + 1 < n and s[p + 1] == t[p]:
            ok = False

        if ok:
            c[p] = t[p]
            continue

        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):
                c[i] = kem

    s = ''.join(c)
    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
AZ
BZ
BA

Test 4

Verdict:

input
ABC
BCD

correct output
ABC
DBD
DCD
BCD

user output
(empty)

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
ZJYVAGTUL
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:

input
WYWBWU
IRYVBA

correct output
WYWBWU
WRWVWA
IRYVBA

user output
WYWBWU
IYWBWZ
IRWVWA
IRYVBA