結果

問題 No.1512 作文
ユーザー raven7959raven7959
提出日時 2021-08-28 10:51:47
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 778 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 100,588 KB
最終ジャッジ日時 2024-05-01 15:47:30
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,020 KB
testcase_01 AC 40 ms
54,296 KB
testcase_02 AC 41 ms
55,540 KB
testcase_03 AC 39 ms
55,864 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 41 ms
55,896 KB
testcase_10 AC 40 ms
55,920 KB
testcase_11 AC 40 ms
56,464 KB
testcase_12 AC 41 ms
55,696 KB
testcase_13 AC 40 ms
55,840 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 40 ms
54,372 KB
testcase_27 AC 40 ms
54,184 KB
testcase_28 AC 40 ms
54,556 KB
testcase_29 AC 39 ms
54,308 KB
testcase_30 AC 40 ms
54,000 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 43 ms
61,664 KB
testcase_34 RE -
testcase_35 AC 49 ms
73,012 KB
testcase_36 AC 50 ms
73,456 KB
testcase_37 AC 45 ms
69,416 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

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(N):
  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