結果
| 問題 |
No.3308 One-time Changed Formula
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-24 22:19:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 810 bytes |
| コンパイル時間 | 1,209 ms |
| コンパイル使用メモリ | 163,464 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-24 22:19:55 |
| 合計ジャッジ時間 | 2,070 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
int main(void){
cin.tie(nullptr); ios_base::sync_with_stdio(false);
ll i,j;
int T;
cin >> T;
while(T--){
ll N;
string S;
cin >> N >> S;
ll p=1;
ll ans=0;
REP(i,N){
if(S[i]=='*') continue;
else if(S[i]=='+') p=1;
else if(S[i]=='-') p=-1;
else{
if(p==1){
ans+='9'-S[i];
}
else{
ans+=S[i]-'1';
}
}
}
p=1;
REP(i,N){
if(S[i]=='*'){
if(p==1) ans+=9;
else continue;
}
else if(S[i]=='+'){
if(p==1) ans+=9;
p=1;
}
else if(S[i]=='-'){
if(p==1){
ans+=9;
p=-1;
}
else continue;
}
}
cout << ans << endl;
}
return 0;
}