QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271746 | #6750. Calculate | mobbb# | WA | 15ms | 3840kb | C++17 | 1.1kb | 2023-12-02 14:23:20 | 2023-12-02 14:23:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s;
int calc(int l,int r){
for (int i = r,j = 0;i >= l;i--){
if (s[i] == '(') j++;
if (s[i] == ')') j--;
if (j == 0 && s[i] == '+') return calc(l,i - 1) + calc(i + 1,r);
if (j == 0 && s[i] == '-') return calc(l,i - 1) - calc(i + 1,r);
}
if (s[l] == '(' && s[r] == ')') return calc(l + 1,r - 1);
int ans = 0;
for (int i = l;i <= r;i++) ans = ans * 10 + s[i] - '0';
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
//string s;
cin >> s;
auto n = s.size();
vector<int> q;
for (int i = 0;i < n;i++){
if (s[i] == '?') q.push_back(i);
}
//cout << q.size() << endl;
int res = 0;
for (int i = 0;i <= 9;i++){
for (int j = 0;j <= 9;j++){
if (q.size() == 0){
res = max(res,calc(0,n - 1));
}
else if (q.size() == 1){
s[q[0]] = '0' + i;
res = max(res,calc(0,n - 1));
}else if (q.size() == 2){
s[q[0]] = '0' + i;
s[q[1]] = '0' + j;
res = max(res,calc(0,n - 1));
//cout << s[i] << endl;
}
}
}
cout << res << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
input:
?+?
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
(?+9)-(?+1)
output:
17
result:
ok 1 number(s): "17"
Test #3:
score: -100
Wrong Answer
time: 15ms
memory: 3840kb
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:
0
result:
wrong answer 1st numbers differ - expected: '-63', found: '0'