QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215677#6750. CalculateEunoiay#WA 2ms3876kbC++171.3kb2023-10-15 12:43:422023-10-15 12:43:42

Judging History

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

  • [2023-10-15 12:43:42]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3876kb
  • [2023-10-15 12:43:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

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

	int n = s.size();

	array<char, 10> v = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '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());
		for (int i = 0; i < 10; ++ i) {
			for (int j = 0; j < 10; ++ j) {
				s[k[0]] = v[i];
				s[k[1]] = v[j];
				str.push_back(s);
				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: 3804kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3876kb

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'