結果
問題 | No.1512 作文 |
ユーザー | c-yan |
提出日時 | 2021-05-21 21:56:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 647 ms / 2,000 ms |
コード長 | 703 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 85,376 KB |
最終ジャッジ日時 | 2024-10-10 08:33:19 |
合計ジャッジ時間 | 6,697 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
N = int(input()) S = [input() for _ in range(N)] S.sort() dp = {} #for c in 'abcdefghijklmnopqrstuvwxyz': # dp[c] = -1 dp[chr(ord('a')-1)]=0 for l in S: #print("*", l) if ''.join(sorted(l)) != l: continue lc = l[-1] for c in reversed('abcdefghijklmnopqrstuvwxyz'): if c not in dp: continue if l[0] < c: continue #print(c, dp[lc]) if lc not in dp: dp[lc] = dp[c] + len(l) else: dp[lc] = max(dp[lc], dp[c] + len(l)) #print(c, dp[lc]) if lc not in dp: dp[lc] = len(l) else: dp[lc] = max(dp[lc], len(l)) #print(l) #print(dp) print(max(dp.values()))