Submission #725946

# Submission time Handle Problem Language Result Execution time Memory
725946 2023-04-18T09:13:55 Z amunduzbaev Homework (CEOI22_homework) C++17
100 / 100
148 ms 147316 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef long long ll;
#define int ll

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	string s; cin >> s;
	int n = 0;
	vector<int> ss, t, par;
	for(int i=0;i<(int)s.size();i++){
		if(s[i] == '?'){
			n++;
		}
		if(s[i] == '('){
			t.push_back(s[i-1] == 'x');
			ss.push_back(par.size());
			par.push_back(0);
		}
		if(s[i] == ')'){
			par[ss.back()] = par.size();
			ss.pop_back();
		}
	}
	
	int sz = par.size();
	par.push_back(sz);
	function<ar<int, 2>(int, int)> get = [&](int l, int r) -> ar<int, 2>{
		if(l >= r){
			return {1, 1};
		}
		if(l + 1 == r){
			return (ar<int, 2>){1 + t[l], 1 + (!t[l])};
		}
		int mn = 0, mx = 0;
		ar<int, 2> L = get(l + 1, par[l + 1]), R = get(par[l + 1], r);
		if(t[l]){
			mx = min(L[1], R[1]);
			mn = L[0] + R[0];
		} else {
			mx = L[1] + R[1];
			mn = min(L[0], R[0]);
		}
		//~ cout<<l<<" "<<r<<" "<<mn<<" "<<mx<<endl;
		return (ar<int, 2>){mn, mx};
	};
	
	ar<int, 2> res = get(0, sz);
	int l = res[0], r = n - res[1] + 1;
	cout<<r - l + 1<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 228 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 228 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 316 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 324 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 224 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 147164 KB Output is correct
2 Correct 139 ms 147220 KB Output is correct
3 Correct 127 ms 147200 KB Output is correct
4 Correct 122 ms 147104 KB Output is correct
5 Correct 116 ms 147316 KB Output is correct
6 Correct 118 ms 147276 KB Output is correct
7 Correct 119 ms 147224 KB Output is correct
8 Correct 128 ms 147176 KB Output is correct
9 Correct 127 ms 147168 KB Output is correct
10 Correct 117 ms 147292 KB Output is correct
11 Correct 121 ms 147208 KB Output is correct
12 Correct 124 ms 147236 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 228 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 316 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 324 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 224 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 324 KB Output is correct
61 Correct 1 ms 324 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 240 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 448 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 456 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 320 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 228 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 316 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 324 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 224 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 122 ms 147164 KB Output is correct
58 Correct 139 ms 147220 KB Output is correct
59 Correct 127 ms 147200 KB Output is correct
60 Correct 122 ms 147104 KB Output is correct
61 Correct 116 ms 147316 KB Output is correct
62 Correct 118 ms 147276 KB Output is correct
63 Correct 119 ms 147224 KB Output is correct
64 Correct 128 ms 147176 KB Output is correct
65 Correct 127 ms 147168 KB Output is correct
66 Correct 117 ms 147292 KB Output is correct
67 Correct 121 ms 147208 KB Output is correct
68 Correct 124 ms 147236 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 324 KB Output is correct
74 Correct 1 ms 324 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 240 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 448 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 1 ms 456 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 0 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 320 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 63 ms 35160 KB Output is correct
101 Correct 64 ms 35120 KB Output is correct
102 Correct 61 ms 35128 KB Output is correct
103 Correct 66 ms 35084 KB Output is correct
104 Correct 60 ms 35140 KB Output is correct
105 Correct 83 ms 74756 KB Output is correct
106 Correct 83 ms 73900 KB Output is correct
107 Correct 88 ms 74072 KB Output is correct
108 Correct 81 ms 73980 KB Output is correct
109 Correct 81 ms 68824 KB Output is correct
110 Correct 72 ms 35140 KB Output is correct
111 Correct 71 ms 35144 KB Output is correct
112 Correct 66 ms 35132 KB Output is correct
113 Correct 68 ms 35144 KB Output is correct
114 Correct 66 ms 35064 KB Output is correct
115 Correct 124 ms 147168 KB Output is correct
116 Correct 120 ms 147224 KB Output is correct
117 Correct 121 ms 147224 KB Output is correct
118 Correct 148 ms 147196 KB Output is correct
119 Correct 131 ms 147240 KB Output is correct
120 Correct 84 ms 35192 KB Output is correct
121 Correct 75 ms 35084 KB Output is correct
122 Correct 71 ms 35088 KB Output is correct
123 Correct 75 ms 35224 KB Output is correct
124 Correct 96 ms 88520 KB Output is correct
125 Correct 85 ms 88604 KB Output is correct
126 Correct 84 ms 88500 KB Output is correct
127 Correct 86 ms 88512 KB Output is correct
128 Correct 31 ms 19080 KB Output is correct
129 Correct 28 ms 19100 KB Output is correct
130 Correct 24 ms 19052 KB Output is correct
131 Correct 1 ms 212 KB Output is correct