QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#37356#1194. Parehtneses EditorNaCly_FishWA 3ms6840kbC++141.3kb2022-07-01 11:08:142022-07-01 11:08:17

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-01 11:08:17]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6840kb
  • [2022-07-01 11:08:14]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#define p 1000000007
#define N 300007
#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;
				top--;
            }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: 2ms
memory: 6108kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 3ms
memory: 6840kb

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: 6040kb

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'