QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#260149#1194. Parehtneses Editorlemonilemon#WA 2ms3808kbC++201.6kb2023-11-21 21:04:572023-11-21 21:04:57

Judging History

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

  • [2023-11-21 21:04:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3808kb
  • [2023-11-21 21:04:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifdef genshin
#include <experimental/iterator>
#endif
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using uint = unsigned int;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 46 * ll(1e17);
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 25;

struct good{
    map<int,int> cnt;
    vector<pair<int, char>> rec;
    pair<int, char> last(){
        if (rec.empty()) return make_pair(-2, '*');
        else return rec.back();
    }
};
vector <good> rec; 
signed main() { ios::sync_with_stdio(0); cin.tie(0);
    char c;
    ll ans = 0;
    rec.push_back(good());

    while (cin >> c){
        if (c == '('){
            int i = rec.back().last().first + 1;
            if (i <= 0){
                rec.push_back(good());
                i = 1;
            }
            ++rec.back().cnt[i-1];
            rec.back().rec.push_back(make_pair(i, c));
        }
        else if (c == ')'){
            int i = rec.back().last().first - 1;
            if (i >= 0){
                ans += rec.back().cnt[i];
            }
            rec.back().rec.push_back(make_pair(i, c));
        }
        else{
            if (rec.back().last().second == '('){
                int i = rec.back().last().first;
                --rec.back().cnt[i-1];
            }
            else{
                int i = rec.back().last().first;
                if (i >= 0){
                    ans -= rec.back().cnt[i];
                }
            }
            rec.back().rec.pop_back();

            if (rec.back().last().first == -2) rec.pop_back();
        }
        cout << ans << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3504kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

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

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
12
10
12
12
12
14
14
14
15
18
18
18
18
22
25
28
30
30
30
30
30
30
30
35
35
35
35
36
36
38
38
41
41
45
47
53
47
47
47
52
55
55
55
55
55
55
55
61
65
61
61
68
72
68
72
72
72
72
72
68
72
78
82
86
86
86
86
...

result:

wrong answer 49th numbers differ - expected: '11', found: '12'