結果

問題 No.1512 作文
ユーザー O2MTO2MT
提出日時 2021-05-21 22:43:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 715 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,904 KB
実行使用メモリ 132,152 KB
最終ジャッジ日時 2024-04-18 16:09:34
合計ジャッジ時間 3,933 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
68,736 KB
testcase_01 AC 42 ms
58,368 KB
testcase_02 AC 43 ms
59,008 KB
testcase_03 AC 39 ms
52,608 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
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