結果

問題 No.1512 作文
ユーザー O2MTO2MT
提出日時 2021-05-21 22:43:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 721 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 172,112 KB
最終ジャッジ日時 2024-04-18 16:10:09
合計ジャッジ時間 20,721 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 42 ms
59,912 KB
testcase_02 AC 43 ms
59,500 KB
testcase_03 AC 38 ms
53,436 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 42 ms
59,960 KB
testcase_27 AC 37 ms
52,864 KB
testcase_28 AC 44 ms
59,660 KB
testcase_29 AC 43 ms
58,996 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 40 ms
54,644 KB
testcase_36 AC 44 ms
54,044 KB
testcase_37 AC 39 ms
53,616 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 TLE -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = [str(input()) for _ in range(N)]
def getIndex(s):
  return ord(s)-96

l = []
for i in range(N):
  a,b = getIndex(S[i][0]),getIndex(S[i][-1])
  if a <= b:
    l.append((a,b,len(S[i])))

# l.sort(reverse=True,key=lambda x: x[2])
# l.sort(key=lambda x: x[1])
# l.sort(key=lambda x: x[0])
N = len(l)

dp = [[0 for _ in range(27)] for _ in range(N+1)]
for j in range(1,27):
  for i in range(N):
    a,b,c = l[i]
    for k in range(27):
      dp[i+1][k] = max(dp[i][k], dp[i+1][k],dp[i][k-1])
    for j in range(a+1):
      dp[i+1][b] = max(dp[i][j]+c, dp[i][b],dp[i+1][b])
  
ans = 0
for i in range(N+1):
  for j in range(27):
    ans = max(ans,dp[i][j])
# print(l)
# for d in dp:
#   print(*d)
print(ans)
0