QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#37340 | #1194. Parehtneses Editor | NaCly_Fish | WA | 5ms | 6956kb | C++14 | 1.3kb | 2022-07-01 10:40:34 | 2022-07-01 10:40:36 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#define p 1000000007
#define N 300005
#define ll long long
using namespace std;
struct oper{
char type;
int lst;
inline oper(char _type=0,int _lst=0):type(_type),lst(_lst){}
};
oper stk2[N];
char str[N];
int stk[N];
int n,top = 100000,lef,top2;
ll ans;
int main(){
scanf("%s",str);
n = strlen(str);
for(int i=0;i<n;++i){
if(str[i]=='('){
stk2[++top2] = oper('(',stk[top+1]);
stk[++top] = 0;
++lef;
}else if(str[i]==')'){
if(lef==0){
stk2[++top2] = oper(')',stk[top]);
stk[top] = 0;
}else{
top--;
stk[top]++;
ans += stk[top];
--lef;
stk2[++top2] = oper(')',0);
}
}else{
oper op = stk2[top2--];
if(op.type=='('){
--lef;
stk[top--] = op.lst;
}else{
if(op.lst!=0) stk[top] = op.lst;
else{
++lef;
ans -= stk[top];
stk[top]--;
top++;
}
}
}
printf("%lld\n",ans);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 6956kb
input:
(()())---)
output:
0 0 1 1 3 4 3 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 2ms
memory: 6808kb
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: 5ms
memory: 6356kb
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 8989th numbers differ - expected: '5324', found: '5325'