結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int T;
    cin >> T;

    while (T--) {
        string S;
        cin >> S;

        auto type = [&](char c) {
            if (c == '?') return 0;
            if (c == '+' || c == '-') return 1;
            return 2;
        };

        bool plus = true;
        int N = ssize(S);
        for (int i = 0; i < N; i++) {
            if (S[i] == '+') {
                plus = true;
            } else if (S[i] == '-') {
                plus = false;
            }
            if (S[i] == '?') {
                if (!plus) {
                    if (i == N - 1 || type(S[i - 1]) == 1 || type(S[i + 1]) == 1) {
                        S[i] = '1';
                    } else {
                        S[i] = '+';
                        plus = true;
                    }
                } else {
                    S[i] = '9';
                }
            }
        }

        cout << S << '\n';
    }
}
0