結果

問題 No.3021 Maximize eval
コンテスト
ユーザー Rumain831
提出日時 2026-08-29 03:28:47
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 19 ms / 2,000 ms
+ 305µs
コード長 756 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,985 ms
コンパイル使用メモリ 173,252 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-29 03:29:04
合計ジャッジ時間 5,530 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

void solve(){
  string s; cin >> s;
  ll ans=0, n=s.size(), id=0;
  auto ok=[&](int i){
    if(i<0||i>=n) return false;
    if(s[i]=='-'||s[i]=='+') return false;
    return true;
  };
  while(id<n){
    int sg=1;
    if(s[id]=='-'||s[id]=='+'){
      if(s[id]=='-') sg*=-1;
      id++;
    }
    while(id<n){
      if(s[id]=='+'||s[id]=='-') break;
      if(s[id]=='?'){
        if(sg==1) s[id]='9';
        else{
          if(ok(id-1)&&ok(id+1)){
            s[id]='+'; break;
          }
          s[id]='1';
        }
      }
      id++;
    }
  }
  cout << s << endl;
}

int main(void){
  int t; cin >> t;
  while(t--){
    solve();
  }
  return 0; 
}
0