Submission #955146

# Submission time Handle Problem Language Result Execution time Memory
955146 2024-03-29T13:20:38 Z PoPularPlusPlus Homework (CEOI22_homework) C++17
100 / 100
211 ms 183824 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define vf first 
#define vs second
const int mod = 1000000007;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2000009;

vector<pair<int,int>> adj[N];
int dp[N][2], siz[N];

void dfs(int node){
	if(adj[node].size() == 0){
		siz[node] = 1;
		dp[node][0] = dp[node][1] = 1;
		return;
	}
	siz[node] = 0;
	for(auto i : adj[node]){
		dfs(i.vf);
		siz[node] += siz[i.vf];
	}
	int u = adj[node][0].vf , v = adj[node][1].vf;
	if(adj[node][0].vs == 0){
		dp[node][0] = min(dp[u][0] , dp[v][0]);
		dp[node][1] = dp[v][1] + dp[u][1] - 1;
	}
	else {
		dp[node][0] = dp[u][0] + dp[v][0];
		dp[node][1] = max(siz[u] + dp[v][1] , siz[v] + dp[u][1]);
	}
}

void solve(){
	string s;
	cin >> s;
	int n = 0;
	int siz = s.size();
	for(int i = 0; i < siz; i++){
		if(s[i] == '?')
			n++;
	}
	stack<pair<int,int>> st;
	int cur = n;
	int cnt = 0;
	for(int i = 0; i < siz; i++){
		if(s[i] == 'm'){
			if(st.size()){
				int u = st.top().vf , w = st.top().vs, v = cur;
				st.pop();
				adj[u].pb(mp(v,w));
			}
			int w = 1;
			if(s[i + 1] == 'i')
				w = 0;
			st.push(mp(cur,w));
			st.push(mp(cur++,w));
		}
		else if(s[i] == '?'){
			int u = st.top().vf , w = st.top().vs, v = cnt++;
			st.pop();
			adj[u].pb(mp(v,w));
		}
	}
	dfs(n);
	cout << (dp[n][1] - dp[n][0]) + 1 << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int t;cin>>t;
	//while(t--) 
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50008 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 16 ms 50012 KB Output is correct
4 Correct 12 ms 50008 KB Output is correct
5 Correct 12 ms 50012 KB Output is correct
6 Correct 11 ms 50008 KB Output is correct
7 Correct 12 ms 50012 KB Output is correct
8 Correct 11 ms 50136 KB Output is correct
9 Correct 11 ms 50216 KB Output is correct
10 Correct 12 ms 50012 KB Output is correct
11 Correct 13 ms 50220 KB Output is correct
12 Correct 12 ms 50012 KB Output is correct
13 Correct 11 ms 50012 KB Output is correct
14 Correct 12 ms 50220 KB Output is correct
15 Correct 11 ms 50012 KB Output is correct
16 Correct 11 ms 50136 KB Output is correct
17 Correct 11 ms 50012 KB Output is correct
18 Correct 11 ms 50012 KB Output is correct
19 Correct 11 ms 50012 KB Output is correct
20 Correct 12 ms 50012 KB Output is correct
21 Correct 11 ms 50012 KB Output is correct
22 Correct 11 ms 50012 KB Output is correct
23 Correct 12 ms 50012 KB Output is correct
24 Correct 12 ms 50220 KB Output is correct
25 Correct 11 ms 50012 KB Output is correct
26 Correct 12 ms 50008 KB Output is correct
27 Correct 11 ms 50012 KB Output is correct
28 Correct 11 ms 50224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50008 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 16 ms 50012 KB Output is correct
4 Correct 12 ms 50008 KB Output is correct
5 Correct 12 ms 50012 KB Output is correct
6 Correct 11 ms 50008 KB Output is correct
7 Correct 12 ms 50012 KB Output is correct
8 Correct 11 ms 50136 KB Output is correct
9 Correct 11 ms 50216 KB Output is correct
10 Correct 12 ms 50012 KB Output is correct
11 Correct 13 ms 50220 KB Output is correct
12 Correct 12 ms 50012 KB Output is correct
13 Correct 11 ms 50012 KB Output is correct
14 Correct 12 ms 50220 KB Output is correct
15 Correct 11 ms 50012 KB Output is correct
16 Correct 11 ms 50136 KB Output is correct
17 Correct 11 ms 50012 KB Output is correct
18 Correct 11 ms 50012 KB Output is correct
19 Correct 11 ms 50012 KB Output is correct
20 Correct 12 ms 50012 KB Output is correct
21 Correct 11 ms 50012 KB Output is correct
22 Correct 11 ms 50012 KB Output is correct
23 Correct 12 ms 50012 KB Output is correct
24 Correct 12 ms 50220 KB Output is correct
25 Correct 11 ms 50012 KB Output is correct
26 Correct 12 ms 50008 KB Output is correct
27 Correct 11 ms 50012 KB Output is correct
28 Correct 11 ms 50224 KB Output is correct
29 Correct 11 ms 50012 KB Output is correct
30 Correct 11 ms 50220 KB Output is correct
31 Correct 11 ms 50012 KB Output is correct
32 Correct 11 ms 50144 KB Output is correct
33 Correct 11 ms 50012 KB Output is correct
34 Correct 12 ms 50012 KB Output is correct
35 Correct 11 ms 50012 KB Output is correct
36 Correct 11 ms 50012 KB Output is correct
37 Correct 11 ms 50012 KB Output is correct
38 Correct 11 ms 50012 KB Output is correct
39 Correct 11 ms 50176 KB Output is correct
40 Correct 11 ms 50012 KB Output is correct
41 Correct 12 ms 50012 KB Output is correct
42 Correct 11 ms 50012 KB Output is correct
43 Correct 12 ms 50012 KB Output is correct
44 Correct 13 ms 50268 KB Output is correct
45 Correct 11 ms 50172 KB Output is correct
46 Correct 12 ms 50012 KB Output is correct
47 Correct 11 ms 50012 KB Output is correct
48 Correct 11 ms 50220 KB Output is correct
49 Correct 11 ms 50012 KB Output is correct
50 Correct 11 ms 50008 KB Output is correct
51 Correct 11 ms 50012 KB Output is correct
52 Correct 11 ms 50012 KB Output is correct
53 Correct 11 ms 50012 KB Output is correct
54 Correct 12 ms 50012 KB Output is correct
55 Correct 11 ms 50012 KB Output is correct
56 Correct 11 ms 50012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 183092 KB Output is correct
2 Correct 192 ms 183484 KB Output is correct
3 Correct 182 ms 183824 KB Output is correct
4 Correct 186 ms 182480 KB Output is correct
5 Correct 190 ms 182792 KB Output is correct
6 Correct 178 ms 183400 KB Output is correct
7 Correct 174 ms 183416 KB Output is correct
8 Correct 182 ms 182408 KB Output is correct
9 Correct 190 ms 183632 KB Output is correct
10 Correct 174 ms 182892 KB Output is correct
11 Correct 177 ms 182480 KB Output is correct
12 Correct 186 ms 182512 KB Output is correct
13 Correct 12 ms 50008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50008 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 16 ms 50012 KB Output is correct
4 Correct 12 ms 50008 KB Output is correct
5 Correct 12 ms 50012 KB Output is correct
6 Correct 11 ms 50008 KB Output is correct
7 Correct 12 ms 50012 KB Output is correct
8 Correct 11 ms 50136 KB Output is correct
9 Correct 11 ms 50216 KB Output is correct
10 Correct 12 ms 50012 KB Output is correct
11 Correct 13 ms 50220 KB Output is correct
12 Correct 12 ms 50012 KB Output is correct
13 Correct 11 ms 50012 KB Output is correct
14 Correct 12 ms 50220 KB Output is correct
15 Correct 11 ms 50012 KB Output is correct
16 Correct 11 ms 50136 KB Output is correct
17 Correct 11 ms 50012 KB Output is correct
18 Correct 11 ms 50012 KB Output is correct
19 Correct 11 ms 50012 KB Output is correct
20 Correct 12 ms 50012 KB Output is correct
21 Correct 11 ms 50012 KB Output is correct
22 Correct 11 ms 50012 KB Output is correct
23 Correct 12 ms 50012 KB Output is correct
24 Correct 12 ms 50220 KB Output is correct
25 Correct 11 ms 50012 KB Output is correct
26 Correct 12 ms 50008 KB Output is correct
27 Correct 11 ms 50012 KB Output is correct
28 Correct 11 ms 50224 KB Output is correct
29 Correct 11 ms 50012 KB Output is correct
30 Correct 11 ms 50220 KB Output is correct
31 Correct 11 ms 50012 KB Output is correct
32 Correct 11 ms 50144 KB Output is correct
33 Correct 11 ms 50012 KB Output is correct
34 Correct 12 ms 50012 KB Output is correct
35 Correct 11 ms 50012 KB Output is correct
36 Correct 11 ms 50012 KB Output is correct
37 Correct 11 ms 50012 KB Output is correct
38 Correct 11 ms 50012 KB Output is correct
39 Correct 11 ms 50176 KB Output is correct
40 Correct 11 ms 50012 KB Output is correct
41 Correct 12 ms 50012 KB Output is correct
42 Correct 11 ms 50012 KB Output is correct
43 Correct 12 ms 50012 KB Output is correct
44 Correct 13 ms 50268 KB Output is correct
45 Correct 11 ms 50172 KB Output is correct
46 Correct 12 ms 50012 KB Output is correct
47 Correct 11 ms 50012 KB Output is correct
48 Correct 11 ms 50220 KB Output is correct
49 Correct 11 ms 50012 KB Output is correct
50 Correct 11 ms 50008 KB Output is correct
51 Correct 11 ms 50012 KB Output is correct
52 Correct 11 ms 50012 KB Output is correct
53 Correct 11 ms 50012 KB Output is correct
54 Correct 12 ms 50012 KB Output is correct
55 Correct 11 ms 50012 KB Output is correct
56 Correct 11 ms 50012 KB Output is correct
57 Correct 13 ms 50268 KB Output is correct
58 Correct 11 ms 50264 KB Output is correct
59 Correct 12 ms 50264 KB Output is correct
60 Correct 12 ms 50268 KB Output is correct
61 Correct 12 ms 50268 KB Output is correct
62 Correct 12 ms 50176 KB Output is correct
63 Correct 13 ms 50268 KB Output is correct
64 Correct 12 ms 50128 KB Output is correct
65 Correct 18 ms 50268 KB Output is correct
66 Correct 13 ms 50224 KB Output is correct
67 Correct 11 ms 50268 KB Output is correct
68 Correct 11 ms 50268 KB Output is correct
69 Correct 12 ms 50268 KB Output is correct
70 Correct 11 ms 50268 KB Output is correct
71 Correct 11 ms 50268 KB Output is correct
72 Correct 12 ms 50168 KB Output is correct
73 Correct 12 ms 50220 KB Output is correct
74 Correct 12 ms 50268 KB Output is correct
75 Correct 12 ms 50268 KB Output is correct
76 Correct 13 ms 50220 KB Output is correct
77 Correct 11 ms 50268 KB Output is correct
78 Correct 12 ms 50264 KB Output is correct
79 Correct 12 ms 50268 KB Output is correct
80 Correct 12 ms 50216 KB Output is correct
81 Correct 11 ms 50300 KB Output is correct
82 Correct 11 ms 50268 KB Output is correct
83 Correct 11 ms 50216 KB Output is correct
84 Correct 12 ms 50108 KB Output is correct
85 Correct 12 ms 50012 KB Output is correct
86 Correct 13 ms 50012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50008 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 16 ms 50012 KB Output is correct
4 Correct 12 ms 50008 KB Output is correct
5 Correct 12 ms 50012 KB Output is correct
6 Correct 11 ms 50008 KB Output is correct
7 Correct 12 ms 50012 KB Output is correct
8 Correct 11 ms 50136 KB Output is correct
9 Correct 11 ms 50216 KB Output is correct
10 Correct 12 ms 50012 KB Output is correct
11 Correct 13 ms 50220 KB Output is correct
12 Correct 12 ms 50012 KB Output is correct
13 Correct 11 ms 50012 KB Output is correct
14 Correct 12 ms 50220 KB Output is correct
15 Correct 11 ms 50012 KB Output is correct
16 Correct 11 ms 50136 KB Output is correct
17 Correct 11 ms 50012 KB Output is correct
18 Correct 11 ms 50012 KB Output is correct
19 Correct 11 ms 50012 KB Output is correct
20 Correct 12 ms 50012 KB Output is correct
21 Correct 11 ms 50012 KB Output is correct
22 Correct 11 ms 50012 KB Output is correct
23 Correct 12 ms 50012 KB Output is correct
24 Correct 12 ms 50220 KB Output is correct
25 Correct 11 ms 50012 KB Output is correct
26 Correct 12 ms 50008 KB Output is correct
27 Correct 11 ms 50012 KB Output is correct
28 Correct 11 ms 50224 KB Output is correct
29 Correct 11 ms 50012 KB Output is correct
30 Correct 11 ms 50220 KB Output is correct
31 Correct 11 ms 50012 KB Output is correct
32 Correct 11 ms 50144 KB Output is correct
33 Correct 11 ms 50012 KB Output is correct
34 Correct 12 ms 50012 KB Output is correct
35 Correct 11 ms 50012 KB Output is correct
36 Correct 11 ms 50012 KB Output is correct
37 Correct 11 ms 50012 KB Output is correct
38 Correct 11 ms 50012 KB Output is correct
39 Correct 11 ms 50176 KB Output is correct
40 Correct 11 ms 50012 KB Output is correct
41 Correct 12 ms 50012 KB Output is correct
42 Correct 11 ms 50012 KB Output is correct
43 Correct 12 ms 50012 KB Output is correct
44 Correct 13 ms 50268 KB Output is correct
45 Correct 11 ms 50172 KB Output is correct
46 Correct 12 ms 50012 KB Output is correct
47 Correct 11 ms 50012 KB Output is correct
48 Correct 11 ms 50220 KB Output is correct
49 Correct 11 ms 50012 KB Output is correct
50 Correct 11 ms 50008 KB Output is correct
51 Correct 11 ms 50012 KB Output is correct
52 Correct 11 ms 50012 KB Output is correct
53 Correct 11 ms 50012 KB Output is correct
54 Correct 12 ms 50012 KB Output is correct
55 Correct 11 ms 50012 KB Output is correct
56 Correct 11 ms 50012 KB Output is correct
57 Correct 186 ms 183092 KB Output is correct
58 Correct 192 ms 183484 KB Output is correct
59 Correct 182 ms 183824 KB Output is correct
60 Correct 186 ms 182480 KB Output is correct
61 Correct 190 ms 182792 KB Output is correct
62 Correct 178 ms 183400 KB Output is correct
63 Correct 174 ms 183416 KB Output is correct
64 Correct 182 ms 182408 KB Output is correct
65 Correct 190 ms 183632 KB Output is correct
66 Correct 174 ms 182892 KB Output is correct
67 Correct 177 ms 182480 KB Output is correct
68 Correct 186 ms 182512 KB Output is correct
69 Correct 12 ms 50008 KB Output is correct
70 Correct 13 ms 50268 KB Output is correct
71 Correct 11 ms 50264 KB Output is correct
72 Correct 12 ms 50264 KB Output is correct
73 Correct 12 ms 50268 KB Output is correct
74 Correct 12 ms 50268 KB Output is correct
75 Correct 12 ms 50176 KB Output is correct
76 Correct 13 ms 50268 KB Output is correct
77 Correct 12 ms 50128 KB Output is correct
78 Correct 18 ms 50268 KB Output is correct
79 Correct 13 ms 50224 KB Output is correct
80 Correct 11 ms 50268 KB Output is correct
81 Correct 11 ms 50268 KB Output is correct
82 Correct 12 ms 50268 KB Output is correct
83 Correct 11 ms 50268 KB Output is correct
84 Correct 11 ms 50268 KB Output is correct
85 Correct 12 ms 50168 KB Output is correct
86 Correct 12 ms 50220 KB Output is correct
87 Correct 12 ms 50268 KB Output is correct
88 Correct 12 ms 50268 KB Output is correct
89 Correct 13 ms 50220 KB Output is correct
90 Correct 11 ms 50268 KB Output is correct
91 Correct 12 ms 50264 KB Output is correct
92 Correct 12 ms 50268 KB Output is correct
93 Correct 12 ms 50216 KB Output is correct
94 Correct 11 ms 50300 KB Output is correct
95 Correct 11 ms 50268 KB Output is correct
96 Correct 11 ms 50216 KB Output is correct
97 Correct 12 ms 50108 KB Output is correct
98 Correct 12 ms 50012 KB Output is correct
99 Correct 13 ms 50012 KB Output is correct
100 Correct 152 ms 115764 KB Output is correct
101 Correct 150 ms 115788 KB Output is correct
102 Correct 130 ms 115876 KB Output is correct
103 Correct 135 ms 115764 KB Output is correct
104 Correct 130 ms 115728 KB Output is correct
105 Correct 161 ms 138124 KB Output is correct
106 Correct 155 ms 137788 KB Output is correct
107 Correct 152 ms 136584 KB Output is correct
108 Correct 150 ms 137924 KB Output is correct
109 Correct 154 ms 136632 KB Output is correct
110 Correct 141 ms 116780 KB Output is correct
111 Correct 134 ms 115664 KB Output is correct
112 Correct 134 ms 116856 KB Output is correct
113 Correct 164 ms 115772 KB Output is correct
114 Correct 131 ms 116788 KB Output is correct
115 Correct 193 ms 182840 KB Output is correct
116 Correct 211 ms 183280 KB Output is correct
117 Correct 179 ms 182560 KB Output is correct
118 Correct 179 ms 183268 KB Output is correct
119 Correct 187 ms 183504 KB Output is correct
120 Correct 129 ms 116464 KB Output is correct
121 Correct 133 ms 116164 KB Output is correct
122 Correct 135 ms 116684 KB Output is correct
123 Correct 134 ms 116948 KB Output is correct
124 Correct 164 ms 147764 KB Output is correct
125 Correct 169 ms 147220 KB Output is correct
126 Correct 145 ms 147096 KB Output is correct
127 Correct 149 ms 147148 KB Output is correct
128 Correct 75 ms 86132 KB Output is correct
129 Correct 69 ms 86048 KB Output is correct
130 Correct 69 ms 86648 KB Output is correct
131 Correct 11 ms 50008 KB Output is correct