秋祭 | 静岡高校工学部



卬高杯


提出詳細

提出id提出時刻ユーザー名問題言語判定状況判定実行時間
1149852023-10-25 09:08:08loop0919Hpython19/19RE659

from string import ascii_letters
ascii_index = {c : i for i, c in enumerate(ascii_letters)}
N = int(input())
S = input().split()

dp = [[0 for _ in range(len(ascii_letters))] for _ in range(1<<N)]

for bit in range(1<<N):
    for i, s in enumerate(S):
        if (bit >> i) & 1 == 1:
            continue

        j = ascii_index[S[0]]
        bit_next = bit | (1<<i)
        idx = ascii_index[s[-1]]
        dp[bit_next][idx] = max(dp[bit_next][idx], dp[bit][j] + len(s))

print(max(max(row) for row in dp))

sample1.txt RE 74
sample2.txt WA 20
sample3.txt AC 27
case1.txt RE 247
case2.txt RE 245
case3.txt RE 228
case4.txt RE 229
case5.txt RE 232
case6.txt AC 659
case7.txt RE 230
case8.txt RE 76
case9.txt RE 83
case10.txt RE 83
case11.txt RE 78
case12.txt RE 76
case13.txt RE 82
case14.txt RE 74
case15.txt RE 75
case16.txt RE 230
659 RE
Traceback (most recent call last):
  File "/var/www/judge/submit2/114985/a.py", line 13, in <module>
    j = ascii_index[S[0]]
KeyError: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'