QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864231 | #1194. Parehtneses Editor | cocoa_chan# | WA | 7ms | 41696kb | C++14 | 1.6kb | 2025-01-20 12:30:29 | 2025-01-20 12:30: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++;
rollback[t].push_back({inf,s});
s+=b[z];
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++;
rollback[t].push_back({z,b[z]});
b[z]=0;
z--;
rollback[t].push_back({inf,s});
s+=b[z];
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]);
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 38740kb
input:
(()())---)
output:
0 0 1 1 3 4 3 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 3ms
memory: 39284kb
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: 7ms
memory: 41696kb
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 678th numbers differ - expected: '400', found: '401'