結果

問題 No.1512 作文
コンテスト
ユーザー otsuneko
提出日時 2021-05-21 23:02:32
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 759 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 394 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 1,343,040 KB
最終ジャッジ日時 2026-04-26 11:50:38
合計ジャッジ時間 2,421 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 4 MLE * 2 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from operator import itemgetter
import sys
input = lambda: sys.stdin.readline().rstrip()
#INF = 10**18

N = int(input())
l = []
total = 0
for i in range(N):
    S = input()
    for i in range(len(S)-1):
        if S[i] > S[i+1]:
            break
    else:
        l.append([S[0],S[-1],-len(S),S])
        total += len(S)
l.sort(key=itemgetter(0,1,2))

dp = [[0]*(len(l)+1) for i in range(len(l)+1)]

last = "a"
for i in range(len(l)):
    flag = False
    for j in range(len(l)):
        if l[i][0] >= last:
            dp[i+1][j+1] = max(dp[i][j] - l[i][2], dp[i+1][j])
            flag = True
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
    if flag:
        last = l[i][1]

print(dp[len(l)][len(l)])
0