QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#510774 | #1194. Parehtneses Editor | yzkkai# | WA | 1ms | 3824kb | C++20 | 1.5kb | 2024-08-09 12:45:23 | 2024-08-09 12:45:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
#define sz(x) signed(size(x))
inline void solve() {
string s;
cin >> s;
vector<int> stk{0};
vector<tuple<char, int, int>> opers;
LL res = 0;
for (auto x : s) {
if (x == ')') {
if (sz(stk) == 1) {
opers.push_back({'?', 0, 0});
cout << res << '\n';
continue;
}
opers.emplace_back(')', stk.back(), res);
stk.pop_back();
res += ++stk.back();
}
if (x == '(') {
opers.emplace_back('(', 0, 0);
stk.push_back(0);
}
if (x == '-') {
auto [op, v, r] = opers.back();
opers.pop_back();
if (op == '?') {
cout << res << '\n';
continue;
}
if (op == '(') {
stk.pop_back();
cout << res << '\n';
continue;
}
if (op == ')') {
res = r;
stk.back()--;
stk.push_back(v);
cout << res << '\n';
continue;
}
}
cout << res << '\n';
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
(()())---)
output:
0 0 1 1 3 4 3 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
()--()()----)(()()))
output:
0 1 0 0 0 1 1 3 1 1 0 0 0 0 0 1 1 3 4 4
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3736kb
input:
))(((-)(()((---(-)(-())-(()()(-)--(())))--()((())-)(()(())((-))))(-(((()((()()()()))-(())((((--))-())-)(-(--))))((((-)(-(-)((((()--(---)(-))()(-)(()()-(())()(()()((()()))))(()(()(-(--)-()((()(((()-))-)(()-()()-(-((-)(-)(((()-)))))-())()-(()((()(-)()))((-))())))()()()(-(-(())-()(()-)-))((()))((--(-()...
output:
0 0 0 0 0 0 1 1 1 2 2 2 2 2 1 1 1 2 2 2 2 4 6 4 4 4 5 5 7 7 7 10 7 5 5 5 6 7 9 12 9 7 7 9 9 9 9 10 11 10 11 11 11 12 12 12 13 15 15 15 15 18 20 23 25 25 25 25 25 25 25 26 26 26 26 27 27 29 29 32 32 36 37 39 37 37 37 38 40 40 40 40 40 40 40 41 44 41 41 43 46 43 46 46 46 46 46 43 46 48 49 50 50 50 50 ...
result:
wrong answer 1207th numbers differ - expected: '773', found: '774'