結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
75,752 KB
testcase_01 AC 74 ms
71,604 KB
testcase_02 AC 73 ms
71,572 KB
testcase_03 AC 75 ms
71,300 KB
testcase_04 AC 74 ms
71,304 KB
testcase_05 AC 75 ms
71,376 KB
testcase_06 AC 74 ms
71,408 KB
testcase_07 AC 76 ms
75,812 KB
testcase_08 AC 73 ms
71,140 KB
testcase_09 AC 73 ms
71,496 KB
testcase_10 AC 73 ms
71,472 KB
testcase_11 AC 73 ms
71,340 KB
testcase_12 AC 73 ms
71,420 KB
testcase_13 AC 77 ms
75,904 KB
testcase_14 AC 78 ms
76,228 KB
testcase_15 AC 78 ms
75,652 KB
testcase_16 AC 77 ms
75,972 KB
testcase_17 AC 80 ms
76,048 KB
testcase_18 AC 76 ms
75,896 KB
testcase_19 AC 78 ms
76,172 KB
testcase_20 AC 79 ms
76,048 KB
testcase_21 AC 75 ms
75,956 KB
testcase_22 AC 77 ms
76,232 KB
testcase_23 AC 86 ms
76,776 KB
testcase_24 AC 87 ms
76,396 KB
testcase_25 AC 88 ms
76,852 KB
testcase_26 AC 87 ms
76,488 KB
testcase_27 AC 87 ms
76,228 KB
testcase_28 AC 86 ms
76,732 KB
testcase_29 AC 86 ms
76,408 KB
testcase_30 AC 85 ms
76,784 KB
testcase_31 AC 87 ms
76,796 KB
testcase_32 AC 89 ms
76,920 KB
testcase_33 AC 208 ms
82,684 KB
testcase_34 AC 213 ms
83,316 KB
testcase_35 AC 213 ms
83,036 KB
testcase_36 AC 279 ms
82,624 KB
testcase_37 AC 204 ms
83,232 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

誤解法想定 TLE
?を置き換える際にO(|S|^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:

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

    for i in range(len(S)-1,-1,-1):
        if S[i] != "?" and splis[i] == None and cd[S[i]] >= nmax:
            splis[i] = cnt
            nmax = cd[S[i]]
            flag = True

    if not flag:
        break
    cnt += 1

spmax = cnt - 1 #splisの最大値

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

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

for i in range(len(S)):

    if S[i] == "?":
        for j in range(i+1,len(S),1):
            if splis[j] == spmax:
                S[i] = S[j]
                break
        else:
            S[i] = "a"

print ("".join(S))
0