QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215666#6750. CalculateEunoiay#WA 0ms3864kbC++201.4kb2023-10-15 12:38:382023-10-15 12:38:38

Judging History

你现在查看的是最新测评结果

  • [2023-10-15 12:38:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3864kb
  • [2023-10-15 12:38:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
	string s;
	cin >> s;	

	int n = s.size();

	array<char, 2> v = {'0', '9'};
	array<int , 2> k = {};
	vector<string> str;

	if (count(s.begin(), s.end(), '?')) {
		k[0] = find(s.begin(), s.end(), '?') - s.begin();
		k[1] = n - 1 - (find(s.rbegin(), s.rend(), '?') - s.rbegin());
		// cerr << k[0] << " " << k[1] << "\n";
		for (int i = 0; i < 2; ++ i) {
			for (int j = 0; j < 2; ++ j) {
				if (k[0] != -1) {
					s[k[0]] = v[i];
					s[k[1]] = v[j];
					str.push_back(s);
					// cerr << "s: " << s << "\n";
					s[k[0]] = '?';
					s[k[1]] = '?';
				}
			}
		}
	} else {
		str.push_back(s);
	}

	int ans = 0;
	for (const auto &t : str) {
		stack<char> op;
		stack<int> stk;

		auto eval = [&]() {
			while (!op.empty()) {
				char o = op.top();
				op.pop();

				if (o == '(') {
					break;
				}
				int x = stk.top() - '0'; stk.pop();
				int y = stk.top() - '0'; stk.pop();
				if (o == '+') {
					stk.push(x + y);
				} else {
					stk.push(y - x);
				}
			}
		};
		for (char c : t) {
			if (c == ')') {
				eval();
			} else if (isdigit(c)) {
				stk.push(c);
			} else {
				op.push(c);
			}
		}
		eval();
		ans = max(ans, stk.top());
	}
	cout << ans << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3660kb

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'