QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808762#4237. Word LadderTenshi#AC ✓20ms11840kbPython31.4kb2024-12-11 01:47:452024-12-11 01:47:59

Judging History

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

  • [2024-12-11 01:47:59]
  • 评测
  • 测评结果:AC
  • 用时:20ms
  • 内存:11840kb
  • [2024-12-11 01:47:45]
  • 提交

answer

import sys
sys.setrecursionlimit(5010)

def f(n, s):
    if n==0:
        return
    if s[0]!=s[1]:
        new = s[1]+s[1]+s[2:]
        print(new)
        f(n-1, new)
        return
    if s[2]!=s[3]:
        new = s[:2]+s[3]+s[3]+s[4:]
        print(new)
        f(n-1, new)
        return
    if s[4]!=s[5]:
        new = s[:4]+s[5]+s[5]
        print(new)
        f(n-1, new)
        return
    
    inv1 = ((ord(s[3])-ord('a'))%2)==1
    inv2 = ((ord(s[1])-ord('a'))%2)==1
    # print(inv2)
    if s[5]!=('a' if inv1 else 'z'):
        new = s[:5]+chr(ord(s[5])+(-1 if inv1 else 1))
        print(new)
        f(n-1, new)
        return
    if s[3]!=('a' if inv2 else 'z'):
        new = s[:3]+chr(ord(s[3])+(-1 if inv2 else 1))+s[4:]
        print(new)
        f(n-1, new)
        return
    new = s[0]+chr(ord(s[1])+1)+s[2:]
    print(new)
    f(n-1, new)

    # if (ord(s[5])-ord('a'))%2==1: invert = True

    # for i in range(0, 4):
    #     if s[i]!=s[i+1]:
    #         new = s[:i+1]+s[i]+s[i+2:]
    #         print(new)
    #         f(n-1, new)
    #         return
    
    # if ('a' if invert else 'z')==s[0]:
    #     new = s[:5]+chr(ord(s[5])+1)+s[6:]
    #     print(new)
    #     f(n-1, new)
    # else:
    #     new = chr((ord(s[0])-ord('a')+(-1 if invert else 1))%26+ord('a'))+s[1:]
    #     print(new)
    #     f(n-1, new)
        

n = int(input())

f(n, 'aaaaaa')

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 10524kb

input:

5

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd

result:

ok good solution

Test #2:

score: 0
Accepted
time: 11ms
memory: 10708kb

input:

3

output:

aaaaab
aaaabb
aaaabc

result:

ok good solution

Test #3:

score: 0
Accepted
time: 13ms
memory: 10612kb

input:

4

output:

aaaaab
aaaabb
aaaabc
aaaacc

result:

ok good solution

Test #4:

score: 0
Accepted
time: 12ms
memory: 10716kb

input:

6

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd

result:

ok good solution

Test #5:

score: 0
Accepted
time: 13ms
memory: 10584kb

input:

7

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade

result:

ok good solution

Test #6:

score: 0
Accepted
time: 12ms
memory: 10648kb

input:

8

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee

result:

ok good solution

Test #7:

score: 0
Accepted
time: 17ms
memory: 10584kb

input:

9

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef

result:

ok good solution

Test #8:

score: 0
Accepted
time: 12ms
memory: 10712kb

input:

10

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff

result:

ok good solution

Test #9:

score: 0
Accepted
time: 11ms
memory: 10612kb

input:

64

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #10:

score: 0
Accepted
time: 10ms
memory: 10716kb

input:

51

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #11:

score: 0
Accepted
time: 8ms
memory: 10588kb

input:

97

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #12:

score: 0
Accepted
time: 12ms
memory: 10628kb

input:

100

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #13:

score: 0
Accepted
time: 18ms
memory: 10884kb

input:

1000

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #14:

score: 0
Accepted
time: 17ms
memory: 10812kb

input:

1001

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #15:

score: 0
Accepted
time: 17ms
memory: 10748kb

input:

1024

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #16:

score: 0
Accepted
time: 10ms
memory: 10768kb

input:

1025

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #17:

score: 0
Accepted
time: 20ms
memory: 11840kb

input:

5000

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #18:

score: 0
Accepted
time: 14ms
memory: 11776kb

input:

4999

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #19:

score: 0
Accepted
time: 9ms
memory: 11588kb

input:

4096

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #20:

score: 0
Accepted
time: 20ms
memory: 11624kb

input:

4097

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #21:

score: 0
Accepted
time: 12ms
memory: 11520kb

input:

4098

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution

Test #22:

score: 0
Accepted
time: 11ms
memory: 11456kb

input:

3751

output:

aaaaab
aaaabb
aaaabc
aaaacc
aaaacd
aaaadd
aaaade
aaaaee
aaaaef
aaaaff
aaaafg
aaaagg
aaaagh
aaaahh
aaaahi
aaaaii
aaaaij
aaaajj
aaaajk
aaaakk
aaaakl
aaaall
aaaalm
aaaamm
aaaamn
aaaann
aaaano
aaaaoo
aaaaop
aaaapp
aaaapq
aaaaqq
aaaaqr
aaaarr
aaaars
aaaass
aaaast
aaaatt
aaaatu
aaaauu
aaaauv
aaaavv
aaaavw...

result:

ok good solution