QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424017 | #6750. Calculate | HUY1# | WA | 0ms | 3776kb | C++14 | 1.2kb | 2024-05-28 20:51:17 | 2024-05-28 20:51:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e6+10;
ll vis[N];
void solve(){
string s;
cin>>s;
ll n=s.length();
for(int i=1;i<=n;i++) vis[i]=1;
s=" "+s+" ";
for(int i=1;i<=n;i++){
if(s[i]=='-'){
if((s[i+1]<='9'&&s[i+1]>='0')||s[i+1]=='?') {vis[i+1]*=-1;continue;}
ll as1=0,as2=0;
ll jl=i;
while(jl<=n){
// cout<<i<<" "<<jl<<endl;
if(s[jl]=='?'||(s[jl]<='9'&&s[jl]!='0')){
vis[jl]*=-1;
}else if(s[jl]=='(') as1++;
else if(s[jl]==')') as2++;
if(as1==as2&&as1!=0) break;
jl++;
}
}
}
ll ans=0;
for(int i=1;i<=n;i++){
if(s[i]=='?'){
if(vis[i]==-1) ans+=0;
else ans+=9;
//cout<<i<<" "<<vis[i]<<endl;
}else if(s[i]<='9'&&s[i]>='0') ans+=vis[i]*(s[i]-'0');
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
?+?
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
(?+9)-(?+1)
output:
17
result:
ok 1 number(s): "17"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3676kb
input:
((9)-(((8)-(2))+(((1+(1))-(1+((2)+2+2)))+(5)+4))+(((7)-((9)+3))-((8)-(0-(2))+0))+((6)-(6+(((4)-(9))-(8-((9)+(1))+(0)))+(2-((9)+7))-(1)))-((((7)+(1))-((3)+(3)))-((2)-((6)-((3)-(8)))))+(2+0-((6)-(1))))-((((3)-(((0)+((4)-(9))+((6+8)+4)+(5)-(4-(3)-(8)))-((8)-(2))))+(((2)-(4))+(6)-(2))+(6-(1))-((2+9)-(3+...
output:
42
result:
wrong answer 1st numbers differ - expected: '-63', found: '42'