結果

問題 No.1512 作文
ユーザー raven7959raven7959
提出日時 2021-08-28 10:53:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 99,456 KB
最終ジャッジ日時 2024-05-01 15:47:35
合計ジャッジ時間 5,078 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,864 KB
testcase_01 AC 42 ms
54,144 KB
testcase_02 AC 42 ms
53,632 KB
testcase_03 AC 45 ms
54,144 KB
testcase_04 AC 246 ms
87,216 KB
testcase_05 AC 244 ms
88,064 KB
testcase_06 AC 250 ms
87,808 KB
testcase_07 AC 271 ms
87,864 KB
testcase_08 AC 246 ms
87,212 KB
testcase_09 AC 45 ms
55,040 KB
testcase_10 AC 42 ms
55,292 KB
testcase_11 AC 43 ms
55,168 KB
testcase_12 AC 44 ms
55,168 KB
testcase_13 AC 44 ms
55,040 KB
testcase_14 AC 97 ms
76,680 KB
testcase_15 AC 123 ms
77,568 KB
testcase_16 AC 99 ms
76,700 KB
testcase_17 AC 96 ms
76,672 KB
testcase_18 AC 100 ms
77,056 KB
testcase_19 AC 96 ms
76,928 KB
testcase_20 AC 97 ms
76,624 KB
testcase_21 AC 43 ms
54,272 KB
testcase_22 AC 42 ms
54,016 KB
testcase_23 AC 44 ms
54,912 KB
testcase_24 AC 43 ms
54,784 KB
testcase_25 AC 44 ms
54,912 KB
testcase_26 AC 41 ms
53,632 KB
testcase_27 AC 42 ms
53,888 KB
testcase_28 AC 42 ms
53,888 KB
testcase_29 AC 42 ms
53,888 KB
testcase_30 AC 41 ms
54,144 KB
testcase_31 AC 45 ms
59,776 KB
testcase_32 AC 45 ms
60,032 KB
testcase_33 AC 45 ms
59,648 KB
testcase_34 AC 49 ms
61,824 KB
testcase_35 AC 51 ms
73,600 KB
testcase_36 AC 52 ms
73,344 KB
testcase_37 AC 50 ms
67,840 KB
testcase_38 AC 59 ms
75,244 KB
testcase_39 AC 65 ms
75,416 KB
testcase_40 AC 212 ms
99,456 KB
testcase_41 AC 200 ms
98,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N=int(input())
G=[[] for _ in range(26)]
num=[0]*26 #入次数を記録
for i in range(25):
  G[i].append([i+1,0])
  num[i+1]+=1
for i in range(N):
  S=input()
  n=len(S)
  flg=True
  for j in range(n-1):
    if S[j+1]<S[j]:
      flg=False
      break
  if flg:
    G[ord(S[0])-97].append([ord(S[-1])-97,n])
    if S[0]!=S[-1]:
      num[ord(S[-1])-97]+=1
for i in range(26): #あとで取り出すときに自己ループを先に取り出せるように
  G[i]=sorted(G[i])
D=deque()
DP=[0]*26
for i in range(26):
  if not num[i]:
    D.append(i)
while D:
  v=D.popleft()
  for nv,cost in G[v]:
    if nv==v:
      DP[v]+=cost
    else:
      DP[nv]=max(DP[nv],DP[v]+cost)
      num[nv]-=1
      if num[nv]==0:
        D.append(nv)
print(max(DP))
0