結果
| 問題 | No.1609 String Division Machine |
| コンテスト | |
| ユーザー |
tute7627
|
| 提出日時 | 2021-05-17 01:33:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 731 bytes |
| 記録 | |
| コンパイル時間 | 2,055 ms |
| コンパイル使用メモリ | 199,608 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-11-27 10:59:06 |
| 合計ジャッジ時間 | 3,635 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 38 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int n = s.size();
vector<int>last;
int cnt = 0;
for(auto c:s){
if(c != '?')cnt++;
}
vector<bool>used(n);
while(cnt){
last.clear();
for(int i = n - 1; i >= 0; i--){
if(used[i] || s[i] == '?')continue;
if(last.empty() || s[last.back()] <= s[i]){
last.push_back(i);
used[i] = true;
cnt--;
}
}
}
reverse(last.begin(), last.end());
string ans;
for(int i = 0; i < n; i++){
if(s[i] == '?'){
auto nxt = lower_bound(last.begin(), last.end(), i);
if(nxt == last.end())ans += 'a';
else ans += s[*nxt];
}
else ans += s[i];
}
cout << ans << endl;
}
tute7627