# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
925900 |
2024-02-12T10:33:47 Z |
ttamx |
Homework (CEOI22_homework) |
C++14 |
|
224 ms |
172080 KB |
#include<bits/stdc++.h>
using namespace std;
using pi = pair<int,int>;
const int N=2e6+5;
int n;
int t[N];
string s;
stack<int> st;
vector<int> adj[N];
struct Info{
int l,m,r;
Info():l(0),m(1),r(0){}
int sz(){
return l+m+r;
}
}dp[N];
void dfs(int u){
if(t[u]==0)return;
for(auto v:adj[u])dfs(v);
Info dl=dp[adj[u][0]],dr=dp[adj[u][1]];
int tot=dl.sz()+dr.sz();
if(t[u]==-1){
dp[u].l=min(dl.l,dr.l);
dp[u].m=dl.l+dl.m+dr.l+dr.m-1-dp[u].l;
dp[u].r=tot-dp[u].l-dp[u].m;
}else{
dp[u].r=min(dl.r,dr.r);
dp[u].m=dl.r+dl.m+dr.r+dr.m-1-dp[u].r;
dp[u].l=tot-dp[u].r-dp[u].m;
}
}
void pop(){
int u=st.top();
st.pop();
int p=st.top();
adj[p].emplace_back(u);
if(adj[p].size()==2)pop();
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> s;
st.emplace(0);
for(int i=0;i<s.size();i++){
if(s[i]==','||s[i]=='('||s[i]==')')continue;
st.emplace(++n);
if(s[i]=='?'){
t[n]=0;
pop();
}else if(s.substr(i,3)=="min"){
t[n]=-1;
i+=2;
}else{
t[n]=1;
i+=2;
}
}
dfs(1);
cout << dp[1].m;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
72280 KB |
Output is correct |
2 |
Correct |
15 ms |
72280 KB |
Output is correct |
3 |
Correct |
15 ms |
72284 KB |
Output is correct |
4 |
Correct |
16 ms |
72456 KB |
Output is correct |
5 |
Correct |
16 ms |
72284 KB |
Output is correct |
6 |
Correct |
15 ms |
72284 KB |
Output is correct |
7 |
Correct |
16 ms |
72452 KB |
Output is correct |
8 |
Correct |
15 ms |
72284 KB |
Output is correct |
9 |
Correct |
15 ms |
72404 KB |
Output is correct |
10 |
Correct |
16 ms |
72284 KB |
Output is correct |
11 |
Correct |
16 ms |
72460 KB |
Output is correct |
12 |
Correct |
16 ms |
72284 KB |
Output is correct |
13 |
Correct |
15 ms |
72280 KB |
Output is correct |
14 |
Correct |
16 ms |
72284 KB |
Output is correct |
15 |
Correct |
15 ms |
72284 KB |
Output is correct |
16 |
Correct |
15 ms |
72656 KB |
Output is correct |
17 |
Correct |
17 ms |
72288 KB |
Output is correct |
18 |
Correct |
15 ms |
72284 KB |
Output is correct |
19 |
Correct |
15 ms |
72280 KB |
Output is correct |
20 |
Correct |
15 ms |
72284 KB |
Output is correct |
21 |
Correct |
16 ms |
72284 KB |
Output is correct |
22 |
Correct |
15 ms |
72284 KB |
Output is correct |
23 |
Correct |
15 ms |
72292 KB |
Output is correct |
24 |
Correct |
15 ms |
72284 KB |
Output is correct |
25 |
Correct |
15 ms |
72284 KB |
Output is correct |
26 |
Correct |
16 ms |
72284 KB |
Output is correct |
27 |
Correct |
15 ms |
72284 KB |
Output is correct |
28 |
Correct |
15 ms |
72284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
72280 KB |
Output is correct |
2 |
Correct |
15 ms |
72280 KB |
Output is correct |
3 |
Correct |
15 ms |
72284 KB |
Output is correct |
4 |
Correct |
16 ms |
72456 KB |
Output is correct |
5 |
Correct |
16 ms |
72284 KB |
Output is correct |
6 |
Correct |
15 ms |
72284 KB |
Output is correct |
7 |
Correct |
16 ms |
72452 KB |
Output is correct |
8 |
Correct |
15 ms |
72284 KB |
Output is correct |
9 |
Correct |
15 ms |
72404 KB |
Output is correct |
10 |
Correct |
16 ms |
72284 KB |
Output is correct |
11 |
Correct |
16 ms |
72460 KB |
Output is correct |
12 |
Correct |
16 ms |
72284 KB |
Output is correct |
13 |
Correct |
15 ms |
72280 KB |
Output is correct |
14 |
Correct |
16 ms |
72284 KB |
Output is correct |
15 |
Correct |
15 ms |
72284 KB |
Output is correct |
16 |
Correct |
15 ms |
72656 KB |
Output is correct |
17 |
Correct |
17 ms |
72288 KB |
Output is correct |
18 |
Correct |
15 ms |
72284 KB |
Output is correct |
19 |
Correct |
15 ms |
72280 KB |
Output is correct |
20 |
Correct |
15 ms |
72284 KB |
Output is correct |
21 |
Correct |
16 ms |
72284 KB |
Output is correct |
22 |
Correct |
15 ms |
72284 KB |
Output is correct |
23 |
Correct |
15 ms |
72292 KB |
Output is correct |
24 |
Correct |
15 ms |
72284 KB |
Output is correct |
25 |
Correct |
15 ms |
72284 KB |
Output is correct |
26 |
Correct |
16 ms |
72284 KB |
Output is correct |
27 |
Correct |
15 ms |
72284 KB |
Output is correct |
28 |
Correct |
15 ms |
72284 KB |
Output is correct |
29 |
Correct |
15 ms |
72280 KB |
Output is correct |
30 |
Correct |
15 ms |
72380 KB |
Output is correct |
31 |
Correct |
16 ms |
72284 KB |
Output is correct |
32 |
Correct |
17 ms |
72452 KB |
Output is correct |
33 |
Correct |
15 ms |
72396 KB |
Output is correct |
34 |
Correct |
15 ms |
72284 KB |
Output is correct |
35 |
Correct |
16 ms |
72456 KB |
Output is correct |
36 |
Correct |
16 ms |
72460 KB |
Output is correct |
37 |
Correct |
15 ms |
72284 KB |
Output is correct |
38 |
Correct |
15 ms |
72280 KB |
Output is correct |
39 |
Correct |
15 ms |
72540 KB |
Output is correct |
40 |
Correct |
15 ms |
72284 KB |
Output is correct |
41 |
Correct |
15 ms |
72284 KB |
Output is correct |
42 |
Correct |
15 ms |
72284 KB |
Output is correct |
43 |
Correct |
15 ms |
72284 KB |
Output is correct |
44 |
Correct |
15 ms |
72284 KB |
Output is correct |
45 |
Correct |
16 ms |
72284 KB |
Output is correct |
46 |
Correct |
15 ms |
72408 KB |
Output is correct |
47 |
Correct |
15 ms |
72284 KB |
Output is correct |
48 |
Correct |
17 ms |
72280 KB |
Output is correct |
49 |
Correct |
16 ms |
72444 KB |
Output is correct |
50 |
Correct |
15 ms |
72424 KB |
Output is correct |
51 |
Correct |
15 ms |
72540 KB |
Output is correct |
52 |
Correct |
15 ms |
72284 KB |
Output is correct |
53 |
Correct |
16 ms |
72460 KB |
Output is correct |
54 |
Correct |
16 ms |
72280 KB |
Output is correct |
55 |
Correct |
15 ms |
72284 KB |
Output is correct |
56 |
Correct |
18 ms |
72280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
171488 KB |
Output is correct |
2 |
Correct |
198 ms |
171192 KB |
Output is correct |
3 |
Correct |
205 ms |
171216 KB |
Output is correct |
4 |
Correct |
203 ms |
171984 KB |
Output is correct |
5 |
Correct |
224 ms |
172004 KB |
Output is correct |
6 |
Correct |
193 ms |
172012 KB |
Output is correct |
7 |
Correct |
208 ms |
170956 KB |
Output is correct |
8 |
Correct |
198 ms |
171836 KB |
Output is correct |
9 |
Correct |
195 ms |
171460 KB |
Output is correct |
10 |
Correct |
187 ms |
172080 KB |
Output is correct |
11 |
Correct |
199 ms |
170952 KB |
Output is correct |
12 |
Correct |
221 ms |
171016 KB |
Output is correct |
13 |
Correct |
15 ms |
72408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
72280 KB |
Output is correct |
2 |
Correct |
15 ms |
72280 KB |
Output is correct |
3 |
Correct |
15 ms |
72284 KB |
Output is correct |
4 |
Correct |
16 ms |
72456 KB |
Output is correct |
5 |
Correct |
16 ms |
72284 KB |
Output is correct |
6 |
Correct |
15 ms |
72284 KB |
Output is correct |
7 |
Correct |
16 ms |
72452 KB |
Output is correct |
8 |
Correct |
15 ms |
72284 KB |
Output is correct |
9 |
Correct |
15 ms |
72404 KB |
Output is correct |
10 |
Correct |
16 ms |
72284 KB |
Output is correct |
11 |
Correct |
16 ms |
72460 KB |
Output is correct |
12 |
Correct |
16 ms |
72284 KB |
Output is correct |
13 |
Correct |
15 ms |
72280 KB |
Output is correct |
14 |
Correct |
16 ms |
72284 KB |
Output is correct |
15 |
Correct |
15 ms |
72284 KB |
Output is correct |
16 |
Correct |
15 ms |
72656 KB |
Output is correct |
17 |
Correct |
17 ms |
72288 KB |
Output is correct |
18 |
Correct |
15 ms |
72284 KB |
Output is correct |
19 |
Correct |
15 ms |
72280 KB |
Output is correct |
20 |
Correct |
15 ms |
72284 KB |
Output is correct |
21 |
Correct |
16 ms |
72284 KB |
Output is correct |
22 |
Correct |
15 ms |
72284 KB |
Output is correct |
23 |
Correct |
15 ms |
72292 KB |
Output is correct |
24 |
Correct |
15 ms |
72284 KB |
Output is correct |
25 |
Correct |
15 ms |
72284 KB |
Output is correct |
26 |
Correct |
16 ms |
72284 KB |
Output is correct |
27 |
Correct |
15 ms |
72284 KB |
Output is correct |
28 |
Correct |
15 ms |
72284 KB |
Output is correct |
29 |
Correct |
15 ms |
72280 KB |
Output is correct |
30 |
Correct |
15 ms |
72380 KB |
Output is correct |
31 |
Correct |
16 ms |
72284 KB |
Output is correct |
32 |
Correct |
17 ms |
72452 KB |
Output is correct |
33 |
Correct |
15 ms |
72396 KB |
Output is correct |
34 |
Correct |
15 ms |
72284 KB |
Output is correct |
35 |
Correct |
16 ms |
72456 KB |
Output is correct |
36 |
Correct |
16 ms |
72460 KB |
Output is correct |
37 |
Correct |
15 ms |
72284 KB |
Output is correct |
38 |
Correct |
15 ms |
72280 KB |
Output is correct |
39 |
Correct |
15 ms |
72540 KB |
Output is correct |
40 |
Correct |
15 ms |
72284 KB |
Output is correct |
41 |
Correct |
15 ms |
72284 KB |
Output is correct |
42 |
Correct |
15 ms |
72284 KB |
Output is correct |
43 |
Correct |
15 ms |
72284 KB |
Output is correct |
44 |
Correct |
15 ms |
72284 KB |
Output is correct |
45 |
Correct |
16 ms |
72284 KB |
Output is correct |
46 |
Correct |
15 ms |
72408 KB |
Output is correct |
47 |
Correct |
15 ms |
72284 KB |
Output is correct |
48 |
Correct |
17 ms |
72280 KB |
Output is correct |
49 |
Correct |
16 ms |
72444 KB |
Output is correct |
50 |
Correct |
15 ms |
72424 KB |
Output is correct |
51 |
Correct |
15 ms |
72540 KB |
Output is correct |
52 |
Correct |
15 ms |
72284 KB |
Output is correct |
53 |
Correct |
16 ms |
72460 KB |
Output is correct |
54 |
Correct |
16 ms |
72280 KB |
Output is correct |
55 |
Correct |
15 ms |
72284 KB |
Output is correct |
56 |
Correct |
18 ms |
72280 KB |
Output is correct |
57 |
Correct |
15 ms |
72484 KB |
Output is correct |
58 |
Correct |
16 ms |
72392 KB |
Output is correct |
59 |
Correct |
16 ms |
72752 KB |
Output is correct |
60 |
Correct |
16 ms |
72444 KB |
Output is correct |
61 |
Correct |
16 ms |
72284 KB |
Output is correct |
62 |
Correct |
16 ms |
72284 KB |
Output is correct |
63 |
Correct |
17 ms |
72284 KB |
Output is correct |
64 |
Correct |
16 ms |
72284 KB |
Output is correct |
65 |
Correct |
17 ms |
72520 KB |
Output is correct |
66 |
Correct |
16 ms |
72404 KB |
Output is correct |
67 |
Correct |
16 ms |
72400 KB |
Output is correct |
68 |
Correct |
17 ms |
72464 KB |
Output is correct |
69 |
Correct |
15 ms |
72424 KB |
Output is correct |
70 |
Correct |
16 ms |
72284 KB |
Output is correct |
71 |
Correct |
17 ms |
72512 KB |
Output is correct |
72 |
Correct |
16 ms |
72420 KB |
Output is correct |
73 |
Correct |
15 ms |
72552 KB |
Output is correct |
74 |
Correct |
16 ms |
72540 KB |
Output is correct |
75 |
Correct |
15 ms |
72540 KB |
Output is correct |
76 |
Correct |
15 ms |
72464 KB |
Output is correct |
77 |
Correct |
16 ms |
72284 KB |
Output is correct |
78 |
Correct |
15 ms |
72284 KB |
Output is correct |
79 |
Correct |
15 ms |
72384 KB |
Output is correct |
80 |
Correct |
16 ms |
72284 KB |
Output is correct |
81 |
Correct |
15 ms |
72284 KB |
Output is correct |
82 |
Correct |
15 ms |
72524 KB |
Output is correct |
83 |
Correct |
16 ms |
72408 KB |
Output is correct |
84 |
Correct |
17 ms |
72284 KB |
Output is correct |
85 |
Correct |
16 ms |
72456 KB |
Output is correct |
86 |
Correct |
15 ms |
72284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
72280 KB |
Output is correct |
2 |
Correct |
15 ms |
72280 KB |
Output is correct |
3 |
Correct |
15 ms |
72284 KB |
Output is correct |
4 |
Correct |
16 ms |
72456 KB |
Output is correct |
5 |
Correct |
16 ms |
72284 KB |
Output is correct |
6 |
Correct |
15 ms |
72284 KB |
Output is correct |
7 |
Correct |
16 ms |
72452 KB |
Output is correct |
8 |
Correct |
15 ms |
72284 KB |
Output is correct |
9 |
Correct |
15 ms |
72404 KB |
Output is correct |
10 |
Correct |
16 ms |
72284 KB |
Output is correct |
11 |
Correct |
16 ms |
72460 KB |
Output is correct |
12 |
Correct |
16 ms |
72284 KB |
Output is correct |
13 |
Correct |
15 ms |
72280 KB |
Output is correct |
14 |
Correct |
16 ms |
72284 KB |
Output is correct |
15 |
Correct |
15 ms |
72284 KB |
Output is correct |
16 |
Correct |
15 ms |
72656 KB |
Output is correct |
17 |
Correct |
17 ms |
72288 KB |
Output is correct |
18 |
Correct |
15 ms |
72284 KB |
Output is correct |
19 |
Correct |
15 ms |
72280 KB |
Output is correct |
20 |
Correct |
15 ms |
72284 KB |
Output is correct |
21 |
Correct |
16 ms |
72284 KB |
Output is correct |
22 |
Correct |
15 ms |
72284 KB |
Output is correct |
23 |
Correct |
15 ms |
72292 KB |
Output is correct |
24 |
Correct |
15 ms |
72284 KB |
Output is correct |
25 |
Correct |
15 ms |
72284 KB |
Output is correct |
26 |
Correct |
16 ms |
72284 KB |
Output is correct |
27 |
Correct |
15 ms |
72284 KB |
Output is correct |
28 |
Correct |
15 ms |
72284 KB |
Output is correct |
29 |
Correct |
15 ms |
72280 KB |
Output is correct |
30 |
Correct |
15 ms |
72380 KB |
Output is correct |
31 |
Correct |
16 ms |
72284 KB |
Output is correct |
32 |
Correct |
17 ms |
72452 KB |
Output is correct |
33 |
Correct |
15 ms |
72396 KB |
Output is correct |
34 |
Correct |
15 ms |
72284 KB |
Output is correct |
35 |
Correct |
16 ms |
72456 KB |
Output is correct |
36 |
Correct |
16 ms |
72460 KB |
Output is correct |
37 |
Correct |
15 ms |
72284 KB |
Output is correct |
38 |
Correct |
15 ms |
72280 KB |
Output is correct |
39 |
Correct |
15 ms |
72540 KB |
Output is correct |
40 |
Correct |
15 ms |
72284 KB |
Output is correct |
41 |
Correct |
15 ms |
72284 KB |
Output is correct |
42 |
Correct |
15 ms |
72284 KB |
Output is correct |
43 |
Correct |
15 ms |
72284 KB |
Output is correct |
44 |
Correct |
15 ms |
72284 KB |
Output is correct |
45 |
Correct |
16 ms |
72284 KB |
Output is correct |
46 |
Correct |
15 ms |
72408 KB |
Output is correct |
47 |
Correct |
15 ms |
72284 KB |
Output is correct |
48 |
Correct |
17 ms |
72280 KB |
Output is correct |
49 |
Correct |
16 ms |
72444 KB |
Output is correct |
50 |
Correct |
15 ms |
72424 KB |
Output is correct |
51 |
Correct |
15 ms |
72540 KB |
Output is correct |
52 |
Correct |
15 ms |
72284 KB |
Output is correct |
53 |
Correct |
16 ms |
72460 KB |
Output is correct |
54 |
Correct |
16 ms |
72280 KB |
Output is correct |
55 |
Correct |
15 ms |
72284 KB |
Output is correct |
56 |
Correct |
18 ms |
72280 KB |
Output is correct |
57 |
Correct |
200 ms |
171488 KB |
Output is correct |
58 |
Correct |
198 ms |
171192 KB |
Output is correct |
59 |
Correct |
205 ms |
171216 KB |
Output is correct |
60 |
Correct |
203 ms |
171984 KB |
Output is correct |
61 |
Correct |
224 ms |
172004 KB |
Output is correct |
62 |
Correct |
193 ms |
172012 KB |
Output is correct |
63 |
Correct |
208 ms |
170956 KB |
Output is correct |
64 |
Correct |
198 ms |
171836 KB |
Output is correct |
65 |
Correct |
195 ms |
171460 KB |
Output is correct |
66 |
Correct |
187 ms |
172080 KB |
Output is correct |
67 |
Correct |
199 ms |
170952 KB |
Output is correct |
68 |
Correct |
221 ms |
171016 KB |
Output is correct |
69 |
Correct |
15 ms |
72408 KB |
Output is correct |
70 |
Correct |
15 ms |
72484 KB |
Output is correct |
71 |
Correct |
16 ms |
72392 KB |
Output is correct |
72 |
Correct |
16 ms |
72752 KB |
Output is correct |
73 |
Correct |
16 ms |
72444 KB |
Output is correct |
74 |
Correct |
16 ms |
72284 KB |
Output is correct |
75 |
Correct |
16 ms |
72284 KB |
Output is correct |
76 |
Correct |
17 ms |
72284 KB |
Output is correct |
77 |
Correct |
16 ms |
72284 KB |
Output is correct |
78 |
Correct |
17 ms |
72520 KB |
Output is correct |
79 |
Correct |
16 ms |
72404 KB |
Output is correct |
80 |
Correct |
16 ms |
72400 KB |
Output is correct |
81 |
Correct |
17 ms |
72464 KB |
Output is correct |
82 |
Correct |
15 ms |
72424 KB |
Output is correct |
83 |
Correct |
16 ms |
72284 KB |
Output is correct |
84 |
Correct |
17 ms |
72512 KB |
Output is correct |
85 |
Correct |
16 ms |
72420 KB |
Output is correct |
86 |
Correct |
15 ms |
72552 KB |
Output is correct |
87 |
Correct |
16 ms |
72540 KB |
Output is correct |
88 |
Correct |
15 ms |
72540 KB |
Output is correct |
89 |
Correct |
15 ms |
72464 KB |
Output is correct |
90 |
Correct |
16 ms |
72284 KB |
Output is correct |
91 |
Correct |
15 ms |
72284 KB |
Output is correct |
92 |
Correct |
15 ms |
72384 KB |
Output is correct |
93 |
Correct |
16 ms |
72284 KB |
Output is correct |
94 |
Correct |
15 ms |
72284 KB |
Output is correct |
95 |
Correct |
15 ms |
72524 KB |
Output is correct |
96 |
Correct |
16 ms |
72408 KB |
Output is correct |
97 |
Correct |
17 ms |
72284 KB |
Output is correct |
98 |
Correct |
16 ms |
72456 KB |
Output is correct |
99 |
Correct |
15 ms |
72284 KB |
Output is correct |
100 |
Correct |
164 ms |
123572 KB |
Output is correct |
101 |
Correct |
160 ms |
124184 KB |
Output is correct |
102 |
Correct |
150 ms |
123508 KB |
Output is correct |
103 |
Correct |
152 ms |
123488 KB |
Output is correct |
104 |
Correct |
145 ms |
124736 KB |
Output is correct |
105 |
Correct |
169 ms |
140388 KB |
Output is correct |
106 |
Correct |
184 ms |
140784 KB |
Output is correct |
107 |
Correct |
164 ms |
139880 KB |
Output is correct |
108 |
Correct |
162 ms |
140496 KB |
Output is correct |
109 |
Correct |
166 ms |
139300 KB |
Output is correct |
110 |
Correct |
173 ms |
124264 KB |
Output is correct |
111 |
Correct |
166 ms |
124144 KB |
Output is correct |
112 |
Correct |
171 ms |
124612 KB |
Output is correct |
113 |
Correct |
165 ms |
124588 KB |
Output is correct |
114 |
Correct |
166 ms |
123560 KB |
Output is correct |
115 |
Correct |
202 ms |
170752 KB |
Output is correct |
116 |
Correct |
221 ms |
171564 KB |
Output is correct |
117 |
Correct |
217 ms |
171520 KB |
Output is correct |
118 |
Correct |
206 ms |
170696 KB |
Output is correct |
119 |
Correct |
204 ms |
171240 KB |
Output is correct |
120 |
Correct |
169 ms |
124612 KB |
Output is correct |
121 |
Correct |
165 ms |
124508 KB |
Output is correct |
122 |
Correct |
167 ms |
123632 KB |
Output is correct |
123 |
Correct |
170 ms |
123656 KB |
Output is correct |
124 |
Correct |
181 ms |
150392 KB |
Output is correct |
125 |
Correct |
182 ms |
150084 KB |
Output is correct |
126 |
Correct |
177 ms |
149224 KB |
Output is correct |
127 |
Correct |
180 ms |
150012 KB |
Output is correct |
128 |
Correct |
85 ms |
99960 KB |
Output is correct |
129 |
Correct |
81 ms |
99928 KB |
Output is correct |
130 |
Correct |
81 ms |
99980 KB |
Output is correct |
131 |
Correct |
19 ms |
72284 KB |
Output is correct |