結果

問題 No.1512 作文
ユーザー shotoyooshotoyoo
提出日時 2021-05-22 00:07:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2024-04-18 17:05:39
合計ジャッジ時間 4,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 38 ms
52,224 KB
testcase_02 AC 38 ms
52,608 KB
testcase_03 AC 41 ms
51,968 KB
testcase_04 AC 117 ms
76,152 KB
testcase_05 AC 124 ms
76,036 KB
testcase_06 AC 122 ms
76,508 KB
testcase_07 AC 119 ms
75,888 KB
testcase_08 AC 118 ms
76,032 KB
testcase_09 AC 48 ms
67,072 KB
testcase_10 AC 46 ms
67,328 KB
testcase_11 AC 48 ms
67,456 KB
testcase_12 AC 46 ms
67,712 KB
testcase_13 AC 46 ms
67,200 KB
testcase_14 AC 91 ms
76,284 KB
testcase_15 AC 87 ms
76,288 KB
testcase_16 AC 89 ms
76,180 KB
testcase_17 AC 86 ms
76,544 KB
testcase_18 AC 86 ms
76,288 KB
testcase_19 AC 86 ms
76,204 KB
testcase_20 AC 84 ms
76,084 KB
testcase_21 AC 40 ms
58,496 KB
testcase_22 AC 41 ms
57,984 KB
testcase_23 AC 43 ms
59,520 KB
testcase_24 AC 44 ms
59,648 KB
testcase_25 AC 45 ms
59,904 KB
testcase_26 AC 38 ms
52,224 KB
testcase_27 AC 37 ms
52,096 KB
testcase_28 AC 38 ms
52,096 KB
testcase_29 AC 39 ms
52,352 KB
testcase_30 AC 37 ms
51,968 KB
testcase_31 AC 44 ms
58,496 KB
testcase_32 AC 52 ms
60,928 KB
testcase_33 AC 43 ms
59,008 KB
testcase_34 AC 45 ms
60,800 KB
testcase_35 AC 58 ms
70,656 KB
testcase_36 AC 56 ms
70,656 KB
testcase_37 AC 47 ms
66,304 KB
testcase_38 AC 59 ms
75,392 KB
testcase_39 AC 65 ms
75,428 KB
testcase_40 AC 112 ms
75,864 KB
testcase_41 AC 114 ms
75,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

n = int(input())
vs = [[0]*26 for _ in range(26)]
oa = ord("a")
for i in range(n):
    s = [ord(c)-oa for c in input()]
    if any(s[i]>s[i+1] for i in range(len(s)-1)):
        continue
    if s[0]==s[-1]:
        i = s[0]
        vs[i][i] += len(s)
    else:
        assert s[0]<s[-1]
        i = s[0]
        j = s[-1]
        vs[i][j] = max(vs[i][j], len(s))
dp = [0]*26
for i in range(26):
    v = vs[i][i]
    val = 0
    for j in range(i):
        val = max(val, vs[j][i] + dp[j])
    dp[i] = val+v
ans = max(dp)
print(ans)
0