답안 #798172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798172 2023-07-30T12:40:35 Z IvanJ Homework (CEOI22_homework) C++17
53 / 100
166 ms 97776 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 = 1e6 + 5;

int sz, n;
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 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23820 KB Output is correct
5 Correct 11 ms 23792 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23788 KB Output is correct
9 Correct 11 ms 23740 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 11 ms 23788 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23792 KB Output is correct
15 Correct 10 ms 23808 KB Output is correct
16 Correct 11 ms 23776 KB Output is correct
17 Correct 11 ms 23792 KB Output is correct
18 Correct 10 ms 23824 KB Output is correct
19 Correct 10 ms 23764 KB Output is correct
20 Correct 11 ms 23764 KB Output is correct
21 Correct 11 ms 23792 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 11 ms 23792 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 12 ms 23752 KB Output is correct
27 Correct 11 ms 23764 KB Output is correct
28 Correct 12 ms 23792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23820 KB Output is correct
5 Correct 11 ms 23792 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23788 KB Output is correct
9 Correct 11 ms 23740 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 11 ms 23788 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23792 KB Output is correct
15 Correct 10 ms 23808 KB Output is correct
16 Correct 11 ms 23776 KB Output is correct
17 Correct 11 ms 23792 KB Output is correct
18 Correct 10 ms 23824 KB Output is correct
19 Correct 10 ms 23764 KB Output is correct
20 Correct 11 ms 23764 KB Output is correct
21 Correct 11 ms 23792 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 11 ms 23792 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 12 ms 23752 KB Output is correct
27 Correct 11 ms 23764 KB Output is correct
28 Correct 12 ms 23792 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 11 ms 23764 KB Output is correct
32 Correct 11 ms 23700 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 12 ms 23704 KB Output is correct
35 Correct 11 ms 23720 KB Output is correct
36 Correct 11 ms 23792 KB Output is correct
37 Correct 11 ms 23804 KB Output is correct
38 Correct 11 ms 23788 KB Output is correct
39 Correct 11 ms 23764 KB Output is correct
40 Correct 11 ms 23764 KB Output is correct
41 Correct 12 ms 23792 KB Output is correct
42 Correct 11 ms 23788 KB Output is correct
43 Correct 11 ms 23736 KB Output is correct
44 Correct 12 ms 23832 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23788 KB Output is correct
47 Correct 11 ms 23792 KB Output is correct
48 Correct 12 ms 23792 KB Output is correct
49 Correct 11 ms 23764 KB Output is correct
50 Correct 11 ms 23772 KB Output is correct
51 Correct 16 ms 23896 KB Output is correct
52 Correct 12 ms 23788 KB Output is correct
53 Correct 11 ms 23764 KB Output is correct
54 Correct 11 ms 23824 KB Output is correct
55 Correct 12 ms 23764 KB Output is correct
56 Correct 11 ms 23824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 166 ms 97776 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23820 KB Output is correct
5 Correct 11 ms 23792 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23788 KB Output is correct
9 Correct 11 ms 23740 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 11 ms 23788 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23792 KB Output is correct
15 Correct 10 ms 23808 KB Output is correct
16 Correct 11 ms 23776 KB Output is correct
17 Correct 11 ms 23792 KB Output is correct
18 Correct 10 ms 23824 KB Output is correct
19 Correct 10 ms 23764 KB Output is correct
20 Correct 11 ms 23764 KB Output is correct
21 Correct 11 ms 23792 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 11 ms 23792 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 12 ms 23752 KB Output is correct
27 Correct 11 ms 23764 KB Output is correct
28 Correct 12 ms 23792 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 11 ms 23764 KB Output is correct
32 Correct 11 ms 23700 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 12 ms 23704 KB Output is correct
35 Correct 11 ms 23720 KB Output is correct
36 Correct 11 ms 23792 KB Output is correct
37 Correct 11 ms 23804 KB Output is correct
38 Correct 11 ms 23788 KB Output is correct
39 Correct 11 ms 23764 KB Output is correct
40 Correct 11 ms 23764 KB Output is correct
41 Correct 12 ms 23792 KB Output is correct
42 Correct 11 ms 23788 KB Output is correct
43 Correct 11 ms 23736 KB Output is correct
44 Correct 12 ms 23832 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23788 KB Output is correct
47 Correct 11 ms 23792 KB Output is correct
48 Correct 12 ms 23792 KB Output is correct
49 Correct 11 ms 23764 KB Output is correct
50 Correct 11 ms 23772 KB Output is correct
51 Correct 16 ms 23896 KB Output is correct
52 Correct 12 ms 23788 KB Output is correct
53 Correct 11 ms 23764 KB Output is correct
54 Correct 11 ms 23824 KB Output is correct
55 Correct 12 ms 23764 KB Output is correct
56 Correct 11 ms 23824 KB Output is correct
57 Correct 11 ms 23892 KB Output is correct
58 Correct 11 ms 23892 KB Output is correct
59 Correct 11 ms 23792 KB Output is correct
60 Correct 11 ms 23892 KB Output is correct
61 Correct 11 ms 23904 KB Output is correct
62 Correct 14 ms 23936 KB Output is correct
63 Correct 12 ms 23800 KB Output is correct
64 Correct 11 ms 23892 KB Output is correct
65 Correct 11 ms 23896 KB Output is correct
66 Correct 11 ms 23892 KB Output is correct
67 Correct 12 ms 23840 KB Output is correct
68 Correct 12 ms 23824 KB Output is correct
69 Correct 11 ms 23884 KB Output is correct
70 Correct 11 ms 23892 KB Output is correct
71 Correct 11 ms 23892 KB Output is correct
72 Correct 12 ms 23916 KB Output is correct
73 Correct 12 ms 23920 KB Output is correct
74 Correct 11 ms 23924 KB Output is correct
75 Correct 11 ms 23892 KB Output is correct
76 Correct 13 ms 23892 KB Output is correct
77 Correct 13 ms 23892 KB Output is correct
78 Correct 11 ms 23788 KB Output is correct
79 Correct 12 ms 23892 KB Output is correct
80 Correct 12 ms 23852 KB Output is correct
81 Correct 11 ms 23892 KB Output is correct
82 Correct 12 ms 23844 KB Output is correct
83 Correct 12 ms 23792 KB Output is correct
84 Correct 11 ms 23788 KB Output is correct
85 Correct 12 ms 23796 KB Output is correct
86 Correct 11 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23820 KB Output is correct
5 Correct 11 ms 23792 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23788 KB Output is correct
9 Correct 11 ms 23740 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 11 ms 23788 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23792 KB Output is correct
15 Correct 10 ms 23808 KB Output is correct
16 Correct 11 ms 23776 KB Output is correct
17 Correct 11 ms 23792 KB Output is correct
18 Correct 10 ms 23824 KB Output is correct
19 Correct 10 ms 23764 KB Output is correct
20 Correct 11 ms 23764 KB Output is correct
21 Correct 11 ms 23792 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 11 ms 23792 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 12 ms 23752 KB Output is correct
27 Correct 11 ms 23764 KB Output is correct
28 Correct 12 ms 23792 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 11 ms 23764 KB Output is correct
32 Correct 11 ms 23700 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 12 ms 23704 KB Output is correct
35 Correct 11 ms 23720 KB Output is correct
36 Correct 11 ms 23792 KB Output is correct
37 Correct 11 ms 23804 KB Output is correct
38 Correct 11 ms 23788 KB Output is correct
39 Correct 11 ms 23764 KB Output is correct
40 Correct 11 ms 23764 KB Output is correct
41 Correct 12 ms 23792 KB Output is correct
42 Correct 11 ms 23788 KB Output is correct
43 Correct 11 ms 23736 KB Output is correct
44 Correct 12 ms 23832 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23788 KB Output is correct
47 Correct 11 ms 23792 KB Output is correct
48 Correct 12 ms 23792 KB Output is correct
49 Correct 11 ms 23764 KB Output is correct
50 Correct 11 ms 23772 KB Output is correct
51 Correct 16 ms 23896 KB Output is correct
52 Correct 12 ms 23788 KB Output is correct
53 Correct 11 ms 23764 KB Output is correct
54 Correct 11 ms 23824 KB Output is correct
55 Correct 12 ms 23764 KB Output is correct
56 Correct 11 ms 23824 KB Output is correct
57 Runtime error 166 ms 97776 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -