結果

問題 No.1609 String Division Machine
ユーザー tute7627
提出日時 2021-05-17 01:33:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 199,668 KB
最終ジャッジ日時 2025-01-21 13:21:43
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#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