結果

問題 No.1609 String Division Machine
ユーザー milanis48663220milanis48663220
提出日時 2021-07-17 01:35:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,686 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 100,948 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 18:01:01
合計ジャッジ時間 2,891 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 30 ms
4,376 KB
testcase_34 AC 60 ms
4,376 KB
testcase_35 AC 48 ms
4,376 KB
testcase_36 AC 22 ms
4,376 KB
testcase_37 AC 60 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 72 ms
4,376 KB
testcase_41 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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