結果

問題 No.1609 String Division Machine
コンテスト
ユーザー tute7627
提出日時 2021-05-17 01:33:02
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 18 ms / 2,000 ms
+ 374µs
コード長 731 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,152 ms
コンパイル使用メモリ 217,324 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-17 00:09:25
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
}
0