답안 #950598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950598 2024-03-20T13:22:39 Z Vladth11 Homework (CEOI22_homework) C++14
100 / 100
180 ms 164052 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
 
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
 
const ll NMAX = 2000001;
const ll INF = (1LL << 58);
const ll nrbits = 20;
const ll MOD = 998244353;
 
vector <int> v[NMAX];
int pa[NMAX];
int op[NMAX];
pii sol[NMAX];
int nr;
int sz[NMAX];
 
pii combine(int a, int b, int o){
    if(sol[a].first > sol[a].second){
        return sol[a]; /// daca scorul e -1/0 continui
    }
    if(sol[b].first > sol[b].second){
        return sol[b]; /// daca scorul e -1/0 continui
    }
 
 
    if(o == 1){
        return {sol[a].first + sol[b].first, max(sz[a] + sol[b].second, sz[b] + sol[a].second)};
    }else{
        return {min(sol[a].first, sol[b].first), sol[a].second + sol[b].second - 1};
    }
}
 
void DFS(int node){
    if(!v[node].size()){
        sol[node] = {1, 1};
        sz[node] = 1;
        return;
    }
    DFS(v[node][0]);
    DFS(v[node][1]);
    sz[node] += sz[v[node][0]] + sz[v[node][1]];
    sol[node] = combine(v[node][0], v[node][1], op[node]);
}
 
signed main() {
#ifdef HOME
    ifstream cin(".in");
    ofstream cout(".out");
#endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int curent = 1, cnt = 1;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == ','){
            v[curent].push_back(++cnt);
            pa[cnt] = curent;
            curent = cnt;
        }
        if(s[i] == '('){
            v[curent].push_back(++cnt);
            pa[cnt] = curent;
            curent = cnt;
        }
        if(s[i] == ')'){
            curent = pa[curent];
        }
        if(s[i] == '?') {
            nr++;
            curent = pa[curent];
        }
        if(s[i] == 'm'){
            if(s[i + 1] == 'a'){
                op[curent] = 1;
            }
            i += 2;
        }
    }
    DFS(1);
    cout << max(0, sol[1].second - sol[1].first + 1);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55608 KB Output is correct
2 Correct 12 ms 55388 KB Output is correct
3 Correct 12 ms 53340 KB Output is correct
4 Correct 12 ms 55388 KB Output is correct
5 Correct 12 ms 55384 KB Output is correct
6 Correct 14 ms 55604 KB Output is correct
7 Correct 12 ms 55388 KB Output is correct
8 Correct 14 ms 55388 KB Output is correct
9 Correct 12 ms 55388 KB Output is correct
10 Correct 18 ms 55388 KB Output is correct
11 Correct 13 ms 55388 KB Output is correct
12 Correct 12 ms 55388 KB Output is correct
13 Correct 12 ms 55388 KB Output is correct
14 Correct 12 ms 55496 KB Output is correct
15 Correct 13 ms 55388 KB Output is correct
16 Correct 12 ms 55388 KB Output is correct
17 Correct 12 ms 55388 KB Output is correct
18 Correct 12 ms 53560 KB Output is correct
19 Correct 13 ms 55388 KB Output is correct
20 Correct 12 ms 55388 KB Output is correct
21 Correct 13 ms 53468 KB Output is correct
22 Correct 12 ms 55388 KB Output is correct
23 Correct 13 ms 55388 KB Output is correct
24 Correct 12 ms 55604 KB Output is correct
25 Correct 12 ms 55388 KB Output is correct
26 Correct 12 ms 53560 KB Output is correct
27 Correct 12 ms 55388 KB Output is correct
28 Correct 12 ms 55388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55608 KB Output is correct
2 Correct 12 ms 55388 KB Output is correct
3 Correct 12 ms 53340 KB Output is correct
4 Correct 12 ms 55388 KB Output is correct
5 Correct 12 ms 55384 KB Output is correct
6 Correct 14 ms 55604 KB Output is correct
7 Correct 12 ms 55388 KB Output is correct
8 Correct 14 ms 55388 KB Output is correct
9 Correct 12 ms 55388 KB Output is correct
10 Correct 18 ms 55388 KB Output is correct
11 Correct 13 ms 55388 KB Output is correct
12 Correct 12 ms 55388 KB Output is correct
13 Correct 12 ms 55388 KB Output is correct
14 Correct 12 ms 55496 KB Output is correct
15 Correct 13 ms 55388 KB Output is correct
16 Correct 12 ms 55388 KB Output is correct
17 Correct 12 ms 55388 KB Output is correct
18 Correct 12 ms 53560 KB Output is correct
19 Correct 13 ms 55388 KB Output is correct
20 Correct 12 ms 55388 KB Output is correct
21 Correct 13 ms 53468 KB Output is correct
22 Correct 12 ms 55388 KB Output is correct
23 Correct 13 ms 55388 KB Output is correct
24 Correct 12 ms 55604 KB Output is correct
25 Correct 12 ms 55388 KB Output is correct
26 Correct 12 ms 53560 KB Output is correct
27 Correct 12 ms 55388 KB Output is correct
28 Correct 12 ms 55388 KB Output is correct
29 Correct 14 ms 55388 KB Output is correct
30 Correct 13 ms 55528 KB Output is correct
31 Correct 13 ms 55388 KB Output is correct
32 Correct 13 ms 55388 KB Output is correct
33 Correct 13 ms 55388 KB Output is correct
34 Correct 12 ms 55560 KB Output is correct
35 Correct 12 ms 55388 KB Output is correct
36 Correct 13 ms 55596 KB Output is correct
37 Correct 12 ms 55384 KB Output is correct
38 Correct 13 ms 55388 KB Output is correct
39 Correct 12 ms 55800 KB Output is correct
40 Correct 13 ms 55388 KB Output is correct
41 Correct 13 ms 55384 KB Output is correct
42 Correct 12 ms 55388 KB Output is correct
43 Correct 14 ms 55388 KB Output is correct
44 Correct 12 ms 55388 KB Output is correct
45 Correct 12 ms 55388 KB Output is correct
46 Correct 12 ms 55388 KB Output is correct
47 Correct 12 ms 55536 KB Output is correct
48 Correct 12 ms 55536 KB Output is correct
49 Correct 12 ms 53476 KB Output is correct
50 Correct 12 ms 55384 KB Output is correct
51 Correct 12 ms 55588 KB Output is correct
52 Correct 12 ms 55388 KB Output is correct
53 Correct 13 ms 55600 KB Output is correct
54 Correct 12 ms 53444 KB Output is correct
55 Correct 12 ms 55388 KB Output is correct
56 Correct 12 ms 55388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 148428 KB Output is correct
2 Correct 163 ms 163528 KB Output is correct
3 Correct 164 ms 164052 KB Output is correct
4 Correct 159 ms 162812 KB Output is correct
5 Correct 155 ms 163020 KB Output is correct
6 Correct 164 ms 162876 KB Output is correct
7 Correct 159 ms 162704 KB Output is correct
8 Correct 158 ms 162768 KB Output is correct
9 Correct 156 ms 162924 KB Output is correct
10 Correct 180 ms 162612 KB Output is correct
11 Correct 153 ms 162764 KB Output is correct
12 Correct 153 ms 162992 KB Output is correct
13 Correct 13 ms 55388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55608 KB Output is correct
2 Correct 12 ms 55388 KB Output is correct
3 Correct 12 ms 53340 KB Output is correct
4 Correct 12 ms 55388 KB Output is correct
5 Correct 12 ms 55384 KB Output is correct
6 Correct 14 ms 55604 KB Output is correct
7 Correct 12 ms 55388 KB Output is correct
8 Correct 14 ms 55388 KB Output is correct
9 Correct 12 ms 55388 KB Output is correct
10 Correct 18 ms 55388 KB Output is correct
11 Correct 13 ms 55388 KB Output is correct
12 Correct 12 ms 55388 KB Output is correct
13 Correct 12 ms 55388 KB Output is correct
14 Correct 12 ms 55496 KB Output is correct
15 Correct 13 ms 55388 KB Output is correct
16 Correct 12 ms 55388 KB Output is correct
17 Correct 12 ms 55388 KB Output is correct
18 Correct 12 ms 53560 KB Output is correct
19 Correct 13 ms 55388 KB Output is correct
20 Correct 12 ms 55388 KB Output is correct
21 Correct 13 ms 53468 KB Output is correct
22 Correct 12 ms 55388 KB Output is correct
23 Correct 13 ms 55388 KB Output is correct
24 Correct 12 ms 55604 KB Output is correct
25 Correct 12 ms 55388 KB Output is correct
26 Correct 12 ms 53560 KB Output is correct
27 Correct 12 ms 55388 KB Output is correct
28 Correct 12 ms 55388 KB Output is correct
29 Correct 14 ms 55388 KB Output is correct
30 Correct 13 ms 55528 KB Output is correct
31 Correct 13 ms 55388 KB Output is correct
32 Correct 13 ms 55388 KB Output is correct
33 Correct 13 ms 55388 KB Output is correct
34 Correct 12 ms 55560 KB Output is correct
35 Correct 12 ms 55388 KB Output is correct
36 Correct 13 ms 55596 KB Output is correct
37 Correct 12 ms 55384 KB Output is correct
38 Correct 13 ms 55388 KB Output is correct
39 Correct 12 ms 55800 KB Output is correct
40 Correct 13 ms 55388 KB Output is correct
41 Correct 13 ms 55384 KB Output is correct
42 Correct 12 ms 55388 KB Output is correct
43 Correct 14 ms 55388 KB Output is correct
44 Correct 12 ms 55388 KB Output is correct
45 Correct 12 ms 55388 KB Output is correct
46 Correct 12 ms 55388 KB Output is correct
47 Correct 12 ms 55536 KB Output is correct
48 Correct 12 ms 55536 KB Output is correct
49 Correct 12 ms 53476 KB Output is correct
50 Correct 12 ms 55384 KB Output is correct
51 Correct 12 ms 55588 KB Output is correct
52 Correct 12 ms 55388 KB Output is correct
53 Correct 13 ms 55600 KB Output is correct
54 Correct 12 ms 53444 KB Output is correct
55 Correct 12 ms 55388 KB Output is correct
56 Correct 12 ms 55388 KB Output is correct
57 Correct 12 ms 55644 KB Output is correct
58 Correct 13 ms 55640 KB Output is correct
59 Correct 13 ms 55896 KB Output is correct
60 Correct 12 ms 55664 KB Output is correct
61 Correct 12 ms 55644 KB Output is correct
62 Correct 12 ms 55672 KB Output is correct
63 Correct 12 ms 55644 KB Output is correct
64 Correct 12 ms 55644 KB Output is correct
65 Correct 14 ms 55644 KB Output is correct
66 Correct 13 ms 55644 KB Output is correct
67 Correct 13 ms 55644 KB Output is correct
68 Correct 12 ms 55640 KB Output is correct
69 Correct 12 ms 55664 KB Output is correct
70 Correct 12 ms 55660 KB Output is correct
71 Correct 12 ms 55660 KB Output is correct
72 Correct 14 ms 55492 KB Output is correct
73 Correct 12 ms 55644 KB Output is correct
74 Correct 12 ms 55528 KB Output is correct
75 Correct 13 ms 55644 KB Output is correct
76 Correct 12 ms 55640 KB Output is correct
77 Correct 12 ms 53596 KB Output is correct
78 Correct 13 ms 55660 KB Output is correct
79 Correct 13 ms 55644 KB Output is correct
80 Correct 13 ms 55644 KB Output is correct
81 Correct 12 ms 55644 KB Output is correct
82 Correct 12 ms 55644 KB Output is correct
83 Correct 13 ms 55644 KB Output is correct
84 Correct 12 ms 55516 KB Output is correct
85 Correct 12 ms 55384 KB Output is correct
86 Correct 12 ms 55388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55608 KB Output is correct
2 Correct 12 ms 55388 KB Output is correct
3 Correct 12 ms 53340 KB Output is correct
4 Correct 12 ms 55388 KB Output is correct
5 Correct 12 ms 55384 KB Output is correct
6 Correct 14 ms 55604 KB Output is correct
7 Correct 12 ms 55388 KB Output is correct
8 Correct 14 ms 55388 KB Output is correct
9 Correct 12 ms 55388 KB Output is correct
10 Correct 18 ms 55388 KB Output is correct
11 Correct 13 ms 55388 KB Output is correct
12 Correct 12 ms 55388 KB Output is correct
13 Correct 12 ms 55388 KB Output is correct
14 Correct 12 ms 55496 KB Output is correct
15 Correct 13 ms 55388 KB Output is correct
16 Correct 12 ms 55388 KB Output is correct
17 Correct 12 ms 55388 KB Output is correct
18 Correct 12 ms 53560 KB Output is correct
19 Correct 13 ms 55388 KB Output is correct
20 Correct 12 ms 55388 KB Output is correct
21 Correct 13 ms 53468 KB Output is correct
22 Correct 12 ms 55388 KB Output is correct
23 Correct 13 ms 55388 KB Output is correct
24 Correct 12 ms 55604 KB Output is correct
25 Correct 12 ms 55388 KB Output is correct
26 Correct 12 ms 53560 KB Output is correct
27 Correct 12 ms 55388 KB Output is correct
28 Correct 12 ms 55388 KB Output is correct
29 Correct 14 ms 55388 KB Output is correct
30 Correct 13 ms 55528 KB Output is correct
31 Correct 13 ms 55388 KB Output is correct
32 Correct 13 ms 55388 KB Output is correct
33 Correct 13 ms 55388 KB Output is correct
34 Correct 12 ms 55560 KB Output is correct
35 Correct 12 ms 55388 KB Output is correct
36 Correct 13 ms 55596 KB Output is correct
37 Correct 12 ms 55384 KB Output is correct
38 Correct 13 ms 55388 KB Output is correct
39 Correct 12 ms 55800 KB Output is correct
40 Correct 13 ms 55388 KB Output is correct
41 Correct 13 ms 55384 KB Output is correct
42 Correct 12 ms 55388 KB Output is correct
43 Correct 14 ms 55388 KB Output is correct
44 Correct 12 ms 55388 KB Output is correct
45 Correct 12 ms 55388 KB Output is correct
46 Correct 12 ms 55388 KB Output is correct
47 Correct 12 ms 55536 KB Output is correct
48 Correct 12 ms 55536 KB Output is correct
49 Correct 12 ms 53476 KB Output is correct
50 Correct 12 ms 55384 KB Output is correct
51 Correct 12 ms 55588 KB Output is correct
52 Correct 12 ms 55388 KB Output is correct
53 Correct 13 ms 55600 KB Output is correct
54 Correct 12 ms 53444 KB Output is correct
55 Correct 12 ms 55388 KB Output is correct
56 Correct 12 ms 55388 KB Output is correct
57 Correct 153 ms 148428 KB Output is correct
58 Correct 163 ms 163528 KB Output is correct
59 Correct 164 ms 164052 KB Output is correct
60 Correct 159 ms 162812 KB Output is correct
61 Correct 155 ms 163020 KB Output is correct
62 Correct 164 ms 162876 KB Output is correct
63 Correct 159 ms 162704 KB Output is correct
64 Correct 158 ms 162768 KB Output is correct
65 Correct 156 ms 162924 KB Output is correct
66 Correct 180 ms 162612 KB Output is correct
67 Correct 153 ms 162764 KB Output is correct
68 Correct 153 ms 162992 KB Output is correct
69 Correct 13 ms 55388 KB Output is correct
70 Correct 12 ms 55644 KB Output is correct
71 Correct 13 ms 55640 KB Output is correct
72 Correct 13 ms 55896 KB Output is correct
73 Correct 12 ms 55664 KB Output is correct
74 Correct 12 ms 55644 KB Output is correct
75 Correct 12 ms 55672 KB Output is correct
76 Correct 12 ms 55644 KB Output is correct
77 Correct 12 ms 55644 KB Output is correct
78 Correct 14 ms 55644 KB Output is correct
79 Correct 13 ms 55644 KB Output is correct
80 Correct 13 ms 55644 KB Output is correct
81 Correct 12 ms 55640 KB Output is correct
82 Correct 12 ms 55664 KB Output is correct
83 Correct 12 ms 55660 KB Output is correct
84 Correct 12 ms 55660 KB Output is correct
85 Correct 14 ms 55492 KB Output is correct
86 Correct 12 ms 55644 KB Output is correct
87 Correct 12 ms 55528 KB Output is correct
88 Correct 13 ms 55644 KB Output is correct
89 Correct 12 ms 55640 KB Output is correct
90 Correct 12 ms 53596 KB Output is correct
91 Correct 13 ms 55660 KB Output is correct
92 Correct 13 ms 55644 KB Output is correct
93 Correct 13 ms 55644 KB Output is correct
94 Correct 12 ms 55644 KB Output is correct
95 Correct 12 ms 55644 KB Output is correct
96 Correct 13 ms 55644 KB Output is correct
97 Correct 12 ms 55516 KB Output is correct
98 Correct 12 ms 55384 KB Output is correct
99 Correct 12 ms 55388 KB Output is correct
100 Correct 147 ms 131540 KB Output is correct
101 Correct 142 ms 131628 KB Output is correct
102 Correct 142 ms 131392 KB Output is correct
103 Correct 131 ms 132136 KB Output is correct
104 Correct 132 ms 131384 KB Output is correct
105 Correct 152 ms 142544 KB Output is correct
106 Correct 151 ms 143220 KB Output is correct
107 Correct 149 ms 142488 KB Output is correct
108 Correct 144 ms 141968 KB Output is correct
109 Correct 158 ms 142068 KB Output is correct
110 Correct 142 ms 132044 KB Output is correct
111 Correct 143 ms 132884 KB Output is correct
112 Correct 137 ms 131468 KB Output is correct
113 Correct 160 ms 131320 KB Output is correct
114 Correct 136 ms 132036 KB Output is correct
115 Correct 162 ms 163820 KB Output is correct
116 Correct 162 ms 162712 KB Output is correct
117 Correct 154 ms 163928 KB Output is correct
118 Correct 156 ms 163496 KB Output is correct
119 Correct 152 ms 163980 KB Output is correct
120 Correct 134 ms 124040 KB Output is correct
121 Correct 141 ms 132556 KB Output is correct
122 Correct 142 ms 131408 KB Output is correct
123 Correct 142 ms 131536 KB Output is correct
124 Correct 136 ms 148160 KB Output is correct
125 Correct 138 ms 146128 KB Output is correct
126 Correct 136 ms 147440 KB Output is correct
127 Correct 135 ms 145044 KB Output is correct
128 Correct 72 ms 99804 KB Output is correct
129 Correct 74 ms 99916 KB Output is correct
130 Correct 67 ms 99796 KB Output is correct
131 Correct 12 ms 55388 KB Output is correct