結果
| 問題 |
No.1609 String Division Machine
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-07-17 01:35:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 1,686 bytes |
| コンパイル時間 | 903 ms |
| コンパイル使用メモリ | 97,000 KB |
| 最終ジャッジ日時 | 2025-01-23 02:51:30 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
string s; cin >> s;
int n = s.size();
vector<int> ord(n);
auto ok = [&](){
for(int i = 0; i < n; i++){
if(ord[i] == 0 && s[i] != '?') return false;
}
return true;
};
for(int j = 1; !ok(); j++){
vector<bool> appear(26);
for(int i = n-1; i >= 0; i--){
if(s[i] == '?') continue;
if(ord[i] != 0) continue;
bool f = true;
for(int k = s[i]-'a'+1; k < 26; k++){
if(appear[k]) f = false;
}
if(f) ord[i] = j;
appear[s[i]-'a'] = true;
}
}
vector<int> v;
int mx = *max_element(ord.begin(), ord.end());
if(mx == 0) mx = 1;
for(int i = 0; i < n; i++){
if(ord[i] == mx) v.push_back(i);
}
for(int i = 0; i < n; i++){
if(s[i] == '?'){
auto p = lower_bound(v.begin(), v.end(), i);
if(p == v.end()) s[i] = 'a';
else s[i] = s[*p];
}
}
cout << s << endl;
}
milanis48663220