답안 #798173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798173 2023-07-30T12:41:54 Z IvanJ Homework (CEOI22_homework) C++17
100 / 100
262 ms 162756 KB
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e6 + 5;

int sz;
string s;
int type[maxn];
int l[maxn], r[maxn];
int L[maxn], R[maxn];
vector<int> adj[maxn];

void solve(int x) {
	if(adj[x].size() == 0) {
		l[x] = r[x] = L[x] = R[x] = 1;
		return;
	} 
	
	int y = adj[x][0], z = adj[x][1];
	solve(y), solve(z);
	L[x] = 1, R[x] = R[y] + R[z];
	
	if(type[x] == 0) {
		l[x] = min(l[y], l[z]);
		r[x] = r[y] + r[z] - 1;
	}
	if(type[x] == 1) {
		l[x] = l[y] + l[z];
		r[x] = max(r[y] + R[z], r[z] + R[y]);
	}
}

int main() {
	cin >> s;
	sz = (int)s.size();
	int idx = 0;
	vector<int> st;
	for(int i = sz - 1;i >= 0;i--) {
		if(s[i] == '?') st.pb(idx++);
		if(s[i] == 'i' || s[i] == 'a') {
			type[idx] = (s[i] == 'a');
			adj[idx].pb(st.back()), st.pop_back();
			adj[idx].pb(st.back()), st.pop_back();
			st.pb(idx++);
		}
	}
	
	idx--;
	solve(idx);
	printf("%d\n", r[idx] - l[idx] + 1);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47188 KB Output is correct
2 Correct 21 ms 47236 KB Output is correct
3 Correct 20 ms 47232 KB Output is correct
4 Correct 20 ms 47312 KB Output is correct
5 Correct 21 ms 47288 KB Output is correct
6 Correct 21 ms 47188 KB Output is correct
7 Correct 24 ms 47232 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 23 ms 47236 KB Output is correct
10 Correct 20 ms 47300 KB Output is correct
11 Correct 21 ms 47260 KB Output is correct
12 Correct 21 ms 47264 KB Output is correct
13 Correct 25 ms 47332 KB Output is correct
14 Correct 21 ms 47300 KB Output is correct
15 Correct 21 ms 47188 KB Output is correct
16 Correct 20 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47260 KB Output is correct
19 Correct 21 ms 47288 KB Output is correct
20 Correct 24 ms 47308 KB Output is correct
21 Correct 26 ms 47248 KB Output is correct
22 Correct 22 ms 47188 KB Output is correct
23 Correct 22 ms 47308 KB Output is correct
24 Correct 21 ms 47292 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 21 ms 47312 KB Output is correct
27 Correct 21 ms 47304 KB Output is correct
28 Correct 22 ms 47312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47188 KB Output is correct
2 Correct 21 ms 47236 KB Output is correct
3 Correct 20 ms 47232 KB Output is correct
4 Correct 20 ms 47312 KB Output is correct
5 Correct 21 ms 47288 KB Output is correct
6 Correct 21 ms 47188 KB Output is correct
7 Correct 24 ms 47232 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 23 ms 47236 KB Output is correct
10 Correct 20 ms 47300 KB Output is correct
11 Correct 21 ms 47260 KB Output is correct
12 Correct 21 ms 47264 KB Output is correct
13 Correct 25 ms 47332 KB Output is correct
14 Correct 21 ms 47300 KB Output is correct
15 Correct 21 ms 47188 KB Output is correct
16 Correct 20 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47260 KB Output is correct
19 Correct 21 ms 47288 KB Output is correct
20 Correct 24 ms 47308 KB Output is correct
21 Correct 26 ms 47248 KB Output is correct
22 Correct 22 ms 47188 KB Output is correct
23 Correct 22 ms 47308 KB Output is correct
24 Correct 21 ms 47292 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 21 ms 47312 KB Output is correct
27 Correct 21 ms 47304 KB Output is correct
28 Correct 22 ms 47312 KB Output is correct
29 Correct 25 ms 47268 KB Output is correct
30 Correct 26 ms 47188 KB Output is correct
31 Correct 22 ms 47312 KB Output is correct
32 Correct 22 ms 47312 KB Output is correct
33 Correct 22 ms 47308 KB Output is correct
34 Correct 22 ms 47268 KB Output is correct
35 Correct 23 ms 47188 KB Output is correct
36 Correct 21 ms 47220 KB Output is correct
37 Correct 22 ms 47316 KB Output is correct
38 Correct 21 ms 47312 KB Output is correct
39 Correct 21 ms 47272 KB Output is correct
40 Correct 21 ms 47188 KB Output is correct
41 Correct 22 ms 47316 KB Output is correct
42 Correct 21 ms 47228 KB Output is correct
43 Correct 21 ms 47308 KB Output is correct
44 Correct 22 ms 47220 KB Output is correct
45 Correct 22 ms 47268 KB Output is correct
46 Correct 23 ms 47304 KB Output is correct
47 Correct 22 ms 47276 KB Output is correct
48 Correct 21 ms 47284 KB Output is correct
49 Correct 22 ms 47312 KB Output is correct
50 Correct 21 ms 47312 KB Output is correct
51 Correct 22 ms 47316 KB Output is correct
52 Correct 21 ms 47184 KB Output is correct
53 Correct 21 ms 47236 KB Output is correct
54 Correct 23 ms 47224 KB Output is correct
55 Correct 22 ms 47232 KB Output is correct
56 Correct 21 ms 47272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 155840 KB Output is correct
2 Correct 262 ms 162688 KB Output is correct
3 Correct 257 ms 162752 KB Output is correct
4 Correct 249 ms 162756 KB Output is correct
5 Correct 247 ms 162600 KB Output is correct
6 Correct 253 ms 162672 KB Output is correct
7 Correct 249 ms 162608 KB Output is correct
8 Correct 249 ms 162664 KB Output is correct
9 Correct 258 ms 162608 KB Output is correct
10 Correct 245 ms 162656 KB Output is correct
11 Correct 251 ms 162628 KB Output is correct
12 Correct 252 ms 162676 KB Output is correct
13 Correct 22 ms 47276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47188 KB Output is correct
2 Correct 21 ms 47236 KB Output is correct
3 Correct 20 ms 47232 KB Output is correct
4 Correct 20 ms 47312 KB Output is correct
5 Correct 21 ms 47288 KB Output is correct
6 Correct 21 ms 47188 KB Output is correct
7 Correct 24 ms 47232 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 23 ms 47236 KB Output is correct
10 Correct 20 ms 47300 KB Output is correct
11 Correct 21 ms 47260 KB Output is correct
12 Correct 21 ms 47264 KB Output is correct
13 Correct 25 ms 47332 KB Output is correct
14 Correct 21 ms 47300 KB Output is correct
15 Correct 21 ms 47188 KB Output is correct
16 Correct 20 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47260 KB Output is correct
19 Correct 21 ms 47288 KB Output is correct
20 Correct 24 ms 47308 KB Output is correct
21 Correct 26 ms 47248 KB Output is correct
22 Correct 22 ms 47188 KB Output is correct
23 Correct 22 ms 47308 KB Output is correct
24 Correct 21 ms 47292 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 21 ms 47312 KB Output is correct
27 Correct 21 ms 47304 KB Output is correct
28 Correct 22 ms 47312 KB Output is correct
29 Correct 25 ms 47268 KB Output is correct
30 Correct 26 ms 47188 KB Output is correct
31 Correct 22 ms 47312 KB Output is correct
32 Correct 22 ms 47312 KB Output is correct
33 Correct 22 ms 47308 KB Output is correct
34 Correct 22 ms 47268 KB Output is correct
35 Correct 23 ms 47188 KB Output is correct
36 Correct 21 ms 47220 KB Output is correct
37 Correct 22 ms 47316 KB Output is correct
38 Correct 21 ms 47312 KB Output is correct
39 Correct 21 ms 47272 KB Output is correct
40 Correct 21 ms 47188 KB Output is correct
41 Correct 22 ms 47316 KB Output is correct
42 Correct 21 ms 47228 KB Output is correct
43 Correct 21 ms 47308 KB Output is correct
44 Correct 22 ms 47220 KB Output is correct
45 Correct 22 ms 47268 KB Output is correct
46 Correct 23 ms 47304 KB Output is correct
47 Correct 22 ms 47276 KB Output is correct
48 Correct 21 ms 47284 KB Output is correct
49 Correct 22 ms 47312 KB Output is correct
50 Correct 21 ms 47312 KB Output is correct
51 Correct 22 ms 47316 KB Output is correct
52 Correct 21 ms 47184 KB Output is correct
53 Correct 21 ms 47236 KB Output is correct
54 Correct 23 ms 47224 KB Output is correct
55 Correct 22 ms 47232 KB Output is correct
56 Correct 21 ms 47272 KB Output is correct
57 Correct 22 ms 47380 KB Output is correct
58 Correct 22 ms 47316 KB Output is correct
59 Correct 23 ms 47312 KB Output is correct
60 Correct 22 ms 47316 KB Output is correct
61 Correct 23 ms 47392 KB Output is correct
62 Correct 22 ms 47348 KB Output is correct
63 Correct 21 ms 47316 KB Output is correct
64 Correct 22 ms 47276 KB Output is correct
65 Correct 22 ms 47368 KB Output is correct
66 Correct 22 ms 47316 KB Output is correct
67 Correct 22 ms 47364 KB Output is correct
68 Correct 21 ms 47384 KB Output is correct
69 Correct 22 ms 47388 KB Output is correct
70 Correct 22 ms 47292 KB Output is correct
71 Correct 23 ms 47268 KB Output is correct
72 Correct 22 ms 47316 KB Output is correct
73 Correct 23 ms 47408 KB Output is correct
74 Correct 21 ms 47300 KB Output is correct
75 Correct 22 ms 47316 KB Output is correct
76 Correct 22 ms 47316 KB Output is correct
77 Correct 22 ms 47316 KB Output is correct
78 Correct 21 ms 47384 KB Output is correct
79 Correct 22 ms 47296 KB Output is correct
80 Correct 22 ms 47336 KB Output is correct
81 Correct 22 ms 47328 KB Output is correct
82 Correct 22 ms 47316 KB Output is correct
83 Correct 22 ms 47324 KB Output is correct
84 Correct 22 ms 47240 KB Output is correct
85 Correct 22 ms 47352 KB Output is correct
86 Correct 22 ms 47212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47188 KB Output is correct
2 Correct 21 ms 47236 KB Output is correct
3 Correct 20 ms 47232 KB Output is correct
4 Correct 20 ms 47312 KB Output is correct
5 Correct 21 ms 47288 KB Output is correct
6 Correct 21 ms 47188 KB Output is correct
7 Correct 24 ms 47232 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 23 ms 47236 KB Output is correct
10 Correct 20 ms 47300 KB Output is correct
11 Correct 21 ms 47260 KB Output is correct
12 Correct 21 ms 47264 KB Output is correct
13 Correct 25 ms 47332 KB Output is correct
14 Correct 21 ms 47300 KB Output is correct
15 Correct 21 ms 47188 KB Output is correct
16 Correct 20 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47260 KB Output is correct
19 Correct 21 ms 47288 KB Output is correct
20 Correct 24 ms 47308 KB Output is correct
21 Correct 26 ms 47248 KB Output is correct
22 Correct 22 ms 47188 KB Output is correct
23 Correct 22 ms 47308 KB Output is correct
24 Correct 21 ms 47292 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 21 ms 47312 KB Output is correct
27 Correct 21 ms 47304 KB Output is correct
28 Correct 22 ms 47312 KB Output is correct
29 Correct 25 ms 47268 KB Output is correct
30 Correct 26 ms 47188 KB Output is correct
31 Correct 22 ms 47312 KB Output is correct
32 Correct 22 ms 47312 KB Output is correct
33 Correct 22 ms 47308 KB Output is correct
34 Correct 22 ms 47268 KB Output is correct
35 Correct 23 ms 47188 KB Output is correct
36 Correct 21 ms 47220 KB Output is correct
37 Correct 22 ms 47316 KB Output is correct
38 Correct 21 ms 47312 KB Output is correct
39 Correct 21 ms 47272 KB Output is correct
40 Correct 21 ms 47188 KB Output is correct
41 Correct 22 ms 47316 KB Output is correct
42 Correct 21 ms 47228 KB Output is correct
43 Correct 21 ms 47308 KB Output is correct
44 Correct 22 ms 47220 KB Output is correct
45 Correct 22 ms 47268 KB Output is correct
46 Correct 23 ms 47304 KB Output is correct
47 Correct 22 ms 47276 KB Output is correct
48 Correct 21 ms 47284 KB Output is correct
49 Correct 22 ms 47312 KB Output is correct
50 Correct 21 ms 47312 KB Output is correct
51 Correct 22 ms 47316 KB Output is correct
52 Correct 21 ms 47184 KB Output is correct
53 Correct 21 ms 47236 KB Output is correct
54 Correct 23 ms 47224 KB Output is correct
55 Correct 22 ms 47232 KB Output is correct
56 Correct 21 ms 47272 KB Output is correct
57 Correct 244 ms 155840 KB Output is correct
58 Correct 262 ms 162688 KB Output is correct
59 Correct 257 ms 162752 KB Output is correct
60 Correct 249 ms 162756 KB Output is correct
61 Correct 247 ms 162600 KB Output is correct
62 Correct 253 ms 162672 KB Output is correct
63 Correct 249 ms 162608 KB Output is correct
64 Correct 249 ms 162664 KB Output is correct
65 Correct 258 ms 162608 KB Output is correct
66 Correct 245 ms 162656 KB Output is correct
67 Correct 251 ms 162628 KB Output is correct
68 Correct 252 ms 162676 KB Output is correct
69 Correct 22 ms 47276 KB Output is correct
70 Correct 22 ms 47380 KB Output is correct
71 Correct 22 ms 47316 KB Output is correct
72 Correct 23 ms 47312 KB Output is correct
73 Correct 22 ms 47316 KB Output is correct
74 Correct 23 ms 47392 KB Output is correct
75 Correct 22 ms 47348 KB Output is correct
76 Correct 21 ms 47316 KB Output is correct
77 Correct 22 ms 47276 KB Output is correct
78 Correct 22 ms 47368 KB Output is correct
79 Correct 22 ms 47316 KB Output is correct
80 Correct 22 ms 47364 KB Output is correct
81 Correct 21 ms 47384 KB Output is correct
82 Correct 22 ms 47388 KB Output is correct
83 Correct 22 ms 47292 KB Output is correct
84 Correct 23 ms 47268 KB Output is correct
85 Correct 22 ms 47316 KB Output is correct
86 Correct 23 ms 47408 KB Output is correct
87 Correct 21 ms 47300 KB Output is correct
88 Correct 22 ms 47316 KB Output is correct
89 Correct 22 ms 47316 KB Output is correct
90 Correct 22 ms 47316 KB Output is correct
91 Correct 21 ms 47384 KB Output is correct
92 Correct 22 ms 47296 KB Output is correct
93 Correct 22 ms 47336 KB Output is correct
94 Correct 22 ms 47328 KB Output is correct
95 Correct 22 ms 47316 KB Output is correct
96 Correct 22 ms 47324 KB Output is correct
97 Correct 22 ms 47240 KB Output is correct
98 Correct 22 ms 47352 KB Output is correct
99 Correct 22 ms 47212 KB Output is correct
100 Correct 228 ms 131332 KB Output is correct
101 Correct 230 ms 131344 KB Output is correct
102 Correct 232 ms 131396 KB Output is correct
103 Correct 224 ms 131372 KB Output is correct
104 Correct 225 ms 131340 KB Output is correct
105 Correct 232 ms 142380 KB Output is correct
106 Correct 234 ms 142372 KB Output is correct
107 Correct 232 ms 142464 KB Output is correct
108 Correct 230 ms 142380 KB Output is correct
109 Correct 229 ms 142372 KB Output is correct
110 Correct 227 ms 131300 KB Output is correct
111 Correct 227 ms 131368 KB Output is correct
112 Correct 224 ms 131344 KB Output is correct
113 Correct 225 ms 131320 KB Output is correct
114 Correct 226 ms 131288 KB Output is correct
115 Correct 247 ms 162600 KB Output is correct
116 Correct 246 ms 162680 KB Output is correct
117 Correct 247 ms 162656 KB Output is correct
118 Correct 249 ms 162708 KB Output is correct
119 Correct 246 ms 162640 KB Output is correct
120 Correct 224 ms 131420 KB Output is correct
121 Correct 226 ms 131300 KB Output is correct
122 Correct 227 ms 131324 KB Output is correct
123 Correct 230 ms 131300 KB Output is correct
124 Correct 228 ms 147012 KB Output is correct
125 Correct 219 ms 146944 KB Output is correct
126 Correct 232 ms 147032 KB Output is correct
127 Correct 223 ms 146980 KB Output is correct
128 Correct 120 ms 91292 KB Output is correct
129 Correct 122 ms 91316 KB Output is correct
130 Correct 122 ms 91384 KB Output is correct
131 Correct 20 ms 47268 KB Output is correct