結果

問題 No.1512 作文
ユーザー O2MTO2MT
提出日時 2021-05-21 23:05:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 833 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 170,028 KB
最終ジャッジ日時 2024-04-18 16:39:36
合計ジャッジ時間 7,848 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,620 KB
testcase_01 AC 37 ms
52,948 KB
testcase_02 AC 38 ms
53,016 KB
testcase_03 AC 35 ms
53,540 KB
testcase_04 AC 543 ms
124,776 KB
testcase_05 AC 542 ms
124,376 KB
testcase_06 AC 545 ms
124,460 KB
testcase_07 AC 530 ms
124,064 KB
testcase_08 AC 545 ms
124,632 KB
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 37 ms
52,544 KB
testcase_27 AC 38 ms
52,272 KB
testcase_28 AC 39 ms
53,216 KB
testcase_29 AC 37 ms
52,780 KB
testcase_30 AC 37 ms
52,336 KB
testcase_31 AC 39 ms
53,660 KB
testcase_32 AC 44 ms
60,360 KB
testcase_33 AC 38 ms
53,164 KB
testcase_34 AC 56 ms
62,996 KB
testcase_35 AC 39 ms
54,404 KB
testcase_36 AC 40 ms
54,728 KB
testcase_37 AC 38 ms
54,544 KB
testcase_38 AC 57 ms
67,224 KB
testcase_39 AC 54 ms
66,288 KB
testcase_40 AC 879 ms
170,028 KB
testcase_41 AC 614 ms
162,264 KB
権限があれば一括ダウンロードができます

ソースコード

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(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 i in range(N):
  a,b,c = l[i]
  for j in range(27):
    dp[i+1][j] = max(dp[i][j], dp[i+1][j])
  for j in range(a+1):
    dp[i+1][b] = max(dp[i][j]+c, dp[i][b],dp[i+1][b])
for i in range(N):
  a,b,c = l[i]
  for j in range(27):
    dp[i+1][j] = max(dp[i][j], dp[i+1][j])
  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