結果

問題 No.1512 作文
ユーザー tcltktcltk
提出日時 2021-06-25 16:41:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 613 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 132,316 KB
最終ジャッジ日時 2023-09-07 13:37:01
合計ジャッジ時間 12,032 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
80,976 KB
testcase_01 AC 182 ms
80,920 KB
testcase_02 AC 179 ms
80,700 KB
testcase_03 AC 180 ms
80,724 KB
testcase_04 AC 499 ms
113,200 KB
testcase_05 AC 483 ms
113,396 KB
testcase_06 AC 479 ms
113,988 KB
testcase_07 AC 472 ms
113,164 KB
testcase_08 AC 473 ms
113,816 KB
testcase_09 AC 170 ms
80,808 KB
testcase_10 AC 168 ms
81,040 KB
testcase_11 AC 170 ms
80,720 KB
testcase_12 AC 174 ms
80,700 KB
testcase_13 AC 167 ms
80,808 KB
testcase_14 AC 215 ms
85,716 KB
testcase_15 AC 215 ms
85,704 KB
testcase_16 AC 221 ms
86,060 KB
testcase_17 AC 212 ms
85,688 KB
testcase_18 AC 210 ms
85,928 KB
testcase_19 AC 218 ms
85,688 KB
testcase_20 AC 216 ms
85,768 KB
testcase_21 AC 179 ms
80,916 KB
testcase_22 AC 175 ms
80,708 KB
testcase_23 AC 178 ms
80,800 KB
testcase_24 AC 179 ms
80,808 KB
testcase_25 AC 175 ms
80,888 KB
testcase_26 AC 174 ms
80,808 KB
testcase_27 AC 179 ms
80,816 KB
testcase_28 AC 175 ms
80,728 KB
testcase_29 AC 188 ms
81,000 KB
testcase_30 AC 181 ms
80,700 KB
testcase_31 AC 184 ms
81,552 KB
testcase_32 AC 181 ms
81,480 KB
testcase_33 AC 180 ms
81,508 KB
testcase_34 AC 199 ms
83,888 KB
testcase_35 AC 188 ms
83,852 KB
testcase_36 AC 196 ms
83,764 KB
testcase_37 AC 185 ms
83,512 KB
testcase_38 AC 189 ms
84,132 KB
testcase_39 AC 203 ms
83,900 KB
testcase_40 AC 613 ms
127,232 KB
testcase_41 AC 427 ms
132,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """4
# abc
# ab
# bbccdd
# de
# """
# sys.stdin = io.StringIO(_INPUT)


N = int(input())
S = [input() for _ in range(N)]
L = []
for s in S:
    ok = True
    for i in range(len(s)-1):
        if s[i] > s[i+1]:
            ok = False
            break
    if ok:
        L.append((ord(s[0])-ord('a'), ord(s[-1])-ord('a'), len(s)))
L.sort(key=lambda x: (x[0], x[1], -x[2]))

dp = [0] * 26
for k1, k2, l in L:

    dp1 = [0] * 26
    for k in range(26):
        dp1[k] = max(dp1[k], dp[k])
        if k <= k1:
            dp1[k2] = max(dp1[k2], dp[k]+l)
    dp = dp1

ans = max(dp)
print(ans)
0