QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215708#6750. CalculateEunoiay#WA 7ms3824kbC++171.4kb2023-10-15 12:57:212023-10-15 12:57:21

Judging History

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

  • [2023-10-15 12:57:21]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3824kb
  • [2023-10-15 12:57:21]
  • 提交

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', '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 < 2; ++ i) {
			for (int j = 0; j < 2; ++ j) {
				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 = -1 << 30;
	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(); stk.pop();
				int y = stk.top(); stk.pop();
				cerr << "x y: " << x << " " << y << "\n";
				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 - '0');
			} else {
				op.push(c);
			}
		}
		eval();
		if (!stk.empty()) {
			ans = max(ans, stk.top());
		}
	}
	cout << ans << "\n";
}

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

	solve();

	return 0;
}

详细

Test #1:

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

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 3652kb

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:

-151

result:

wrong answer 1st numbers differ - expected: '-63', found: '-151'