結果

問題 No.1512 作文
ユーザー O2MTO2MT
提出日時 2021-05-21 23:16:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 833 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 185,236 KB
最終ジャッジ日時 2024-04-18 16:53:56
合計ジャッジ時間 8,299 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,480 KB
testcase_01 AC 43 ms
52,352 KB
testcase_02 AC 42 ms
52,224 KB
testcase_03 AC 43 ms
51,840 KB
testcase_04 AC 557 ms
136,060 KB
testcase_05 AC 557 ms
135,636 KB
testcase_06 AC 560 ms
136,008 KB
testcase_07 AC 565 ms
136,064 KB
testcase_08 AC 555 ms
136,392 KB
testcase_09 AC 54 ms
63,232 KB
testcase_10 AC 69 ms
64,768 KB
testcase_11 AC 63 ms
63,744 KB
testcase_12 AC 68 ms
64,384 KB
testcase_13 AC 60 ms
63,488 KB
testcase_14 AC 147 ms
86,428 KB
testcase_15 AC 141 ms
86,272 KB
testcase_16 AC 144 ms
86,568 KB
testcase_17 AC 147 ms
86,352 KB
testcase_18 AC 145 ms
86,400 KB
testcase_19 AC 146 ms
86,528 KB
testcase_20 AC 144 ms
86,348 KB
testcase_21 AC 46 ms
53,760 KB
testcase_22 AC 44 ms
52,352 KB
testcase_23 AC 48 ms
54,400 KB
testcase_24 AC 48 ms
54,016 KB
testcase_25 AC 47 ms
54,272 KB
testcase_26 AC 48 ms
52,096 KB
testcase_27 AC 43 ms
52,352 KB
testcase_28 AC 43 ms
52,096 KB
testcase_29 AC 43 ms
52,480 KB
testcase_30 AC 43 ms
52,480 KB
testcase_31 AC 46 ms
53,376 KB
testcase_32 AC 50 ms
59,392 KB
testcase_33 AC 44 ms
52,992 KB
testcase_34 AC 57 ms
62,848 KB
testcase_35 AC 74 ms
82,048 KB
testcase_36 AC 73 ms
82,048 KB
testcase_37 AC 55 ms
66,944 KB
testcase_38 AC 80 ms
83,088 KB
testcase_39 AC 82 ms
83,072 KB
testcase_40 AC 833 ms
185,236 KB
testcase_41 AC 641 ms
180,160 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