結果

問題 No.3021 Maximize eval
ユーザー Iroha_3856
提出日時 2025-02-10 00:25:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,676 bytes
コンパイル時間 4,063 ms
コンパイル使用メモリ 286,016 KB
実行使用メモリ 22,336 KB
最終ジャッジ日時 2025-02-10 00:25:19
合計ジャッジ時間 5,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long

string replace(string s, char x, char y) {
    for (char& c : s) {
        if (c == x) c = y;
    }
    return s;
}

void solve() {
    string S; cin >> S;
    S += "+";
    vector<pair<string, string>> T;
    string last = "+";
    string now = "";
    rep(i, 0, S.size()) {
        if (S[i] == '+' or S[i] == '-') {
            T.emplace_back(last, now);
            last = S[i];
            now.clear();
        }
        else {
            now += S[i];
        }
    }
    string ans = "";
    for (auto[c, s] : T) {
        // cout << c << " " << s << endl;
        ans += c;
        if (c == "+") {
            ans += replace(s, '?', '9');
        }
        else {
            if ((int)s.size() <= 2) {
                ans += replace(s, '?', '1');
            }
            else {
                bool f = false;
                for (int i = 1; i < (int)s.size()-1; i++) {
                    if (s[i] == '?') {
                        string l = s.substr(0, i);
                        string r = s.substr(i+1, (int)s.size());
                        ans += replace(l, '?', '1');
                        ans += "+";
                        ans += replace(r, '?', '9');
                        f = true;
                        break;
                    }
                }
                if (!f) {
                    ans += replace(s, '?', '1');
                }
            }
        }
    }
    for (int i = 1; i < (int)ans.size(); i++) cout << ans[i];
    cout << endl;
}

int main() {
    int T; cin >> T;
    while(T--) solve();
}
0