QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#864226 | #1194. Parehtneses Editor | cocoa_chan# | WA | 4ms | 40148kb | C++14 | 1.6kb | 2025-01-20 12:24:38 | 2025-01-20 12:24:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
ll n,a[1100000],b[1100000],m,i,j,k,l,r,x,y,z,w,s,t,ans[1100000],query[1100000];
vector<pair<ll,ll>> rollback[1100000];
char c[1100000];
int main()
{
scanf("%s",c);
n=strlen(c);
for(i=1;i<=n;i++)
{
if(c[i-1]=='(')
a[i]=1;
if(c[i-1]==')')
a[i]=-1;
if(c[i-1]=='-')
a[i]=0;
}
t=0;
z=500000;
b[z]=1;
for(i=1;i<=n;i++)
{
if(a[i]==1)
{
t++;
z++;
s+=b[z];
rollback[t].push_back({inf,s});
rollback[t].push_back({z,b[z]});
b[z]=1;
ans[t]=s;
query[t]=1;
printf("%lld\n",s);
}
if(a[i]==-1)
{
t++;
b[z]=0;
rollback[t].push_back({z,b[z]});
z--;
s+=b[z];
rollback[t].push_back({inf,s});
b[z]++;
rollback[t].push_back({z,b[z]-1});
ans[t]=s;
query[t]=-1;
printf("%lld\n",s);
}
if(a[i]==0)
{
for(auto pp:rollback[t])
{
if(pp.first==inf)
{
s=pp.second;
continue;
}
b[pp.first]=pp.second;
}
if(query[t]==1)
z--;
else
z++;
t--;
printf("%lld\n",ans[t]);
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 38732kb
input:
(()())---)
output:
0 0 1 1 3 4 3 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 3ms
memory: 39128kb
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: 3ms
memory: 40148kb
input:
))(((-)(()((---(-)(-())-(()()(-)--(())))--()((())-)(()(())((-))))(-(((()((()()()()))-(())((((--))-())-)(-(--))))((((-)(-(-)((((()--(---)(-))()(-)(()()-(())()(()()((()()))))(()(()(-(--)-()((()(((()-))-)(()-()()-(-((-)(-)(((()-)))))-())()-(()((()(-)()))((-))())))()()()(-(-(())-()(()-)-))((()))((--(-()...
output:
0 0 0 0 0 0 1 1 1 2 2 2 2 2 1 2 1 3 3 3 3 5 7 5 7 7 8 8 10 10 10 10 10 8 10 10 11 11 13 13 13 11 13 13 13 13 13 14 15 14 16 16 16 17 17 17 18 20 20 20 20 23 25 26 28 28 28 28 28 28 28 29 29 29 29 30 30 32 32 35 35 39 40 42 40 42 42 43 43 43 43 43 43 43 43 44 45 44 45 45 46 45 47 47 47 47 47 45 48 50...
result:
wrong answer 16th numbers differ - expected: '1', found: '2'