提出 #6366134
ソースコード 拡げる
import sys
input = sys.stdin.readline
S = [ord(s) - ord('a') for s in input().rstrip()]
INF = 10 ** 9
N = len(S)
dp = [None] * (N+1)
# そこから始めたとき、次にxが現れる位置、および、次にxをとった場合に長さLのものが全て作れる
dp[N] = [[INF] * 26, [0] * 26, 0]
for n in range(N-1,-1,-1):
prev = dp[n+1]
cur = [prev[0].copy(), prev[1].copy(), prev[2]]
s = S[n]
cur[0][s] = n
cur[1][s] = prev[2] // 26 + 1
cur[2] = prev[2] + cur[1][s] - prev[1][s]
dp[n] = cur
answer = []
i = 0
while i < N:
# 辞書順で、作れる長さが一番短い文字
L = dp[i][2] // 26
for x in range(26):
if dp[i][1][x] == L:
break
answer.append(chr(ord('a') + x))
# その文字の場所に移動
i = dp[i][0][x]
i += 1
print(''.join(answer))
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Don't Be a Subsequence |
| ユーザ | maspy |
| 言語 | Python (3.4.3) |
| 得点 | 600 |
| コード長 | 875 Byte |
| 結果 | AC |
| 実行時間 | 1069 ms |
| メモリ | 156836 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample1.txt, sample2.txt, sample3.txt |
| All | sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 1.txt | AC | 17 ms | 3064 KiB |
| 10.txt | AC | 1045 ms | 156192 KiB |
| 11.txt | AC | 1047 ms | 156192 KiB |
| 12.txt | AC | 1053 ms | 155172 KiB |
| 13.txt | AC | 1043 ms | 156188 KiB |
| 14.txt | AC | 1049 ms | 156192 KiB |
| 15.txt | AC | 1065 ms | 156196 KiB |
| 16.txt | AC | 1037 ms | 156196 KiB |
| 17.txt | AC | 1040 ms | 156452 KiB |
| 18.txt | AC | 1036 ms | 156484 KiB |
| 19.txt | AC | 1048 ms | 156692 KiB |
| 2.txt | AC | 20 ms | 3700 KiB |
| 20.txt | AC | 1048 ms | 156804 KiB |
| 21.txt | AC | 1069 ms | 156836 KiB |
| 22.txt | AC | 1045 ms | 156836 KiB |
| 23.txt | AC | 1051 ms | 156836 KiB |
| 24.txt | AC | 1031 ms | 154660 KiB |
| 25.txt | AC | 1037 ms | 150036 KiB |
| 26.txt | AC | 1030 ms | 144624 KiB |
| 27.txt | AC | 1019 ms | 148052 KiB |
| 28.txt | AC | 1044 ms | 147652 KiB |
| 29.txt | AC | 1029 ms | 144232 KiB |
| 3.txt | AC | 46 ms | 10356 KiB |
| 30.txt | AC | 1019 ms | 144260 KiB |
| 4.txt | AC | 46 ms | 10360 KiB |
| 5.txt | AC | 433 ms | 79144 KiB |
| 6.txt | AC | 433 ms | 79148 KiB |
| 7.txt | AC | 1037 ms | 156196 KiB |
| 8.txt | AC | 1044 ms | 156188 KiB |
| 9.txt | AC | 1050 ms | 156196 KiB |
| sample1.txt | AC | 17 ms | 3064 KiB |
| sample2.txt | AC | 17 ms | 3064 KiB |
| sample3.txt | AC | 17 ms | 3064 KiB |