結果

問題 No.1512 作文
ユーザー O2MTO2MT
提出日時 2021-05-21 23:16:50
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 763 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 184,992 KB
最終ジャッジ日時 2023-07-31 16:51:26
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,020 KB
testcase_01 AC 71 ms
71,376 KB
testcase_02 AC 71 ms
71,428 KB
testcase_03 AC 73 ms
71,300 KB
testcase_04 AC 535 ms
137,044 KB
testcase_05 AC 527 ms
137,332 KB
testcase_06 AC 526 ms
136,956 KB
testcase_07 AC 528 ms
137,448 KB
testcase_08 AC 527 ms
137,188 KB
testcase_09 AC 78 ms
71,736 KB
testcase_10 AC 90 ms
72,256 KB
testcase_11 AC 88 ms
71,636 KB
testcase_12 AC 91 ms
72,880 KB
testcase_13 AC 80 ms
71,472 KB
testcase_14 AC 158 ms
87,488 KB
testcase_15 AC 156 ms
87,556 KB
testcase_16 AC 158 ms
87,668 KB
testcase_17 AC 158 ms
87,140 KB
testcase_18 AC 158 ms
87,104 KB
testcase_19 AC 160 ms
87,612 KB
testcase_20 AC 156 ms
87,352 KB
testcase_21 AC 72 ms
71,264 KB
testcase_22 AC 70 ms
71,160 KB
testcase_23 AC 76 ms
71,156 KB
testcase_24 AC 74 ms
71,188 KB
testcase_25 AC 73 ms
71,196 KB
testcase_26 AC 72 ms
71,436 KB
testcase_27 AC 72 ms
71,052 KB
testcase_28 AC 72 ms
71,456 KB
testcase_29 AC 70 ms
71,424 KB
testcase_30 AC 71 ms
71,300 KB
testcase_31 AC 72 ms
71,420 KB
testcase_32 AC 76 ms
75,768 KB
testcase_33 AC 69 ms
71,520 KB
testcase_34 AC 79 ms
76,008 KB
testcase_35 AC 90 ms
82,816 KB
testcase_36 AC 90 ms
82,704 KB
testcase_37 AC 77 ms
74,136 KB
testcase_38 AC 102 ms
84,388 KB
testcase_39 AC 101 ms
84,264 KB
testcase_40 AC 763 ms
184,992 KB
testcase_41 AC 616 ms
180,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = [list(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:
    r = sorted(S[i])
    if S[i] == r:
      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])
  
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