QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#260166#1194. Parehtneses Editorlemonilemon#WA 2ms3632kbC++201.8kb2023-11-21 21:31:482023-11-21 21:31:48

Judging History

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

  • [2023-11-21 21:31:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3632kb
  • [2023-11-21 21:31:48]
  • 提交

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<tuple<int, char, int>> rec;
    tuple<int, char, int> last(){
        if (rec.empty()) return make_tuple(-1, '*', 0);
        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 = get<0>(rec.back().last()) + 1;
            if (i <= 0){
                rec.push_back(good());
                i = 1;
            }
            ++rec.back().cnt[i-1];
            rec.back().rec.push_back(make_tuple(i, c, 0));
        }
        else if (c == ')'){
            int i = get<0>(rec.back().last()) - 1;
            if (i >= 0){
                ans += rec.back().cnt[i];
            }
            rec.back().rec.push_back(make_tuple(i, c, rec.back().cnt[i+1]));
            rec.back().cnt[i+1] = 0;
        }
        else{
            if (get<1>(rec.back().last()) == '('){
                int i = get<0>(rec.back().last());
                --rec.back().cnt[i-1];
            }
            else{
                int i = get<0>(rec.back().last());
                if (i >= 0){
                    ans -= rec.back().cnt[i];
                    rec.back().cnt[i+1] = get<2>(rec.back().last());
                }
            }
            rec.back().rec.pop_back();

            if (rec.back().rec.empty()) 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: 3428kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 3388kb

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

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 1252nd numbers differ - expected: '803', found: '802'