結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー Leal-0
提出日時 2025-10-24 23:01:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,523 bytes
コンパイル時間 3,583 ms
コンパイル使用メモリ 308,000 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-24 23:01:21
合計ジャッジ時間 4,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define srep(i,l,r) for(ll i=l;i<=r;i++)
#define irep(i,r,l) for(ll i=r;i>=l;i--)
using ll = long long;
using ld = long double;
const ll mod=998244353;
#define vout(v) for(auto i :v) cout<<i<<" ";
#define INF 9223300000000000000ll
#define Winf 5e12
#define nl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vl vector<ll>
#define pb push_back
#define vc vector<char>
#define vb vector<bool>
#define uniq(x) sort((x).begin(),(x).end());(x).erase(unique((x).begin(),(x).end()),(x).end())
#define eb emplace_back



void no(void) { cout<<"No"<<nl;}
void yes(void) {cout<<"Yes"<<nl;}
void yn(bool a) {
    cout<<(a ? "Yes":"No")<<nl;
}


vector<ll> dx={-1,0,1,0,1,1,-1,-1};
vector<ll> dy={0,-1,0,1,-1,1,-1,1};

bool isin(ll i,ll j,ll h,ll w) {
    if(i<0 || i>=h || j<0 || j>=w) return false;
    return true;
}

template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}


template<class T>T vecmax(const vector<T>&v){return *max_element(all(v));}
template<class T>T vecmin(const vector<T>&v){return *min_element(all(v));}

ll safemod(ll num,ll rule) {
    return (num%rule+rule)%rule;
}

ll sum(vector<ll> &a) {
    return accumulate(all(a),0ll);
}
template<class T>void vvpr(vector<vector<T>> g) {
    rep(i,g.size()) {
        rep(j,g[i].size()) {
            cout<<g[i][j]<<(j==g[i].size()-1 ? "\n":" ");
        }
    }
}
//ファイル読み込みは第二フォルダから ex:include "mathtype/hoge.hpp"
bool isnum(char c) {
    return ('0'<=c && c<='9');
}

int main() {
    ll t; cin>>t;
    vl anss(t);
    rep(tt,t) {
        ll n; string f; cin>>n>>f;
        vl beforeplus(n);
        ll plus=1;
        ll ans=0;
        rep(i,n) {
            if(f[i]=='+') {
                beforeplus[i]=plus;
                plus=1;
            }
            else if(f[i]=='-') {
                beforeplus[i]=plus;
                plus=0;
            }
            else beforeplus[i]=plus;
        }
        rep(i,n) {
            if(beforeplus[i]) {
                if(isnum(f[i])) ans+='9'-f[i];
                else ans+=9;
            }
            else {
                if(isnum(f[i])) ans+=f[i]-'1';
                else ans+=0;
            }
        }
        anss[tt]=ans;
    }
    rep(tt,t) cout<<anss[tt]<<nl;
}
0