結果

問題 No.1609 String Division Machine
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-14 16:42:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,559 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 86,648 KB
最終ジャッジ日時 2023-09-20 12:39:44
合計ジャッジ時間 7,450 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,128 KB
testcase_01 AC 74 ms
71,408 KB
testcase_02 AC 73 ms
71,388 KB
testcase_03 AC 74 ms
71,284 KB
testcase_04 AC 75 ms
71,408 KB
testcase_05 AC 74 ms
71,292 KB
testcase_06 AC 74 ms
71,364 KB
testcase_07 AC 80 ms
75,608 KB
testcase_08 AC 74 ms
71,136 KB
testcase_09 AC 75 ms
71,388 KB
testcase_10 AC 75 ms
71,300 KB
testcase_11 AC 74 ms
71,268 KB
testcase_12 AC 74 ms
71,432 KB
testcase_13 AC 78 ms
76,152 KB
testcase_14 AC 82 ms
76,364 KB
testcase_15 AC 81 ms
76,308 KB
testcase_16 AC 81 ms
76,284 KB
testcase_17 AC 83 ms
76,776 KB
testcase_18 AC 79 ms
76,360 KB
testcase_19 AC 80 ms
76,288 KB
testcase_20 AC 80 ms
76,424 KB
testcase_21 AC 78 ms
76,500 KB
testcase_22 AC 81 ms
76,400 KB
testcase_23 AC 108 ms
77,352 KB
testcase_24 AC 115 ms
77,596 KB
testcase_25 AC 106 ms
77,560 KB
testcase_26 AC 107 ms
77,172 KB
testcase_27 AC 109 ms
77,352 KB
testcase_28 AC 108 ms
77,384 KB
testcase_29 AC 109 ms
77,440 KB
testcase_30 AC 107 ms
77,252 KB
testcase_31 AC 111 ms
77,340 KB
testcase_32 AC 109 ms
77,412 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

想定誤解法 TLE
分割時にO(N^2)

"""

import bisect
import sys


alp = "abcdefghijklmnopqrstuvwxyz?"
cd = {} #文字→数字にする辞書型
for i in range(-1,26):
    cd[alp[i]] = i

#N = int(input())
S = list(input())

#制約チェック
#assert N == len(S)
for i in S:
    assert i in cd
N = len(S)
assert 1 <= N <= 10**5

#全て?の場合を処理する
allq = True #全て?かどうかのフラグ

for i in S:
    if i != "?":
        allq = False
        break

if allq:
    print ("a"*N)
    sys.exit()


#文字列を貪欲に分割する。
#後ろに、自分より辞書順で大きいのが無ければ取る

cnt = 1
splis = [None] * N #何回目で取り除かれるか?

while True:

    chflag = False #1つでも今回取るのがあった場合はTrueにする
    #nmax = -1 #今回取った最大の文字の番号

    for i in range(len(S)):
        if S[i] != "?" and splis[i] == None: # and cd[S[i]] >= nmax:
            flag = True
            for j in range(i+1,len(S)):
                if splis[j] == None and cd[S[j]] > cd[S[i]]:
                    flag = False
                    break

            if flag:
                splis[i] = cnt
                chflag = True

    if not chflag:
        break
    cnt += 1

spmax = cnt - 1 #splisの最大値

#print (splis,spmax,file=sys.stderr)

lastc = "a" #splis[i]がspmaxと同じ文字で、最後に見た文字

for i in range(len(S)-1,-1,-1):

    if splis[i] == spmax:
        lastc = S[i]
    elif S[i] == "?":
        S[i] = lastc

print ("".join(S))
0