QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#440370 | #1194. Parehtneses Editor | LR | WA | 2ms | 3996kb | C++20 | 1.2kb | 2024-06-13 17:05:09 | 2024-06-13 17:05:10 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
string s; cin >> s;
stack<int> st;
st.emplace(0);
vector<tuple<char, int,int>> op;
int ans = 0;
for (char c : s)
{
if (c != '-')
op.emplace_back(c, 0, ans);
else
{
auto [ch, val, pre] = op.back();
op.pop_back();
ans = pre;
if (ch == '(') st.pop();
else
{
int x = st.top();
st.pop();
st.emplace(x - 1);
st.emplace(val);
}
}
if (c == '(')
st.emplace(0);
if (c == ')')
{
if (st.size() > 1)
{
int pre = st.top();
op.pop_back();
op.emplace_back(c, pre, ans);
st.pop();
int x = st.top() + 1;
st.pop();
st.emplace(x);
ans += x;
}
}
cout << ans << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
input:
(()())---)
output:
0 0 1 1 3 4 3 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3488kb
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: 2ms
memory: 3996kb
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'