結果
問題 |
No.1609 String Division Machine
|
ユーザー |
👑 ![]() |
提出日時 | 2021-07-14 15:21:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,467 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 82,500 KB |
実行使用メモリ | 83,632 KB |
最終ジャッジ日時 | 2024-07-06 07:59:01 |
合計ジャッジ時間 | 6,376 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 33 TLE * 1 -- * 3 |
ソースコード
""" 誤解法想定 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))