답안 #1034995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034995 2024-07-26T02:25:13 Z pcc Homework (CEOI22_homework) C++17
100 / 100
247 ms 151104 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")

const int mxn = 1e6+10;
vector<int> tree[mxn*2];
int val[mxn*2],dp[mxn*2];
int vcnt = 0;
int N;
string s;
int rt;

void dfs(int now){
	for(auto nxt:tree[now])dfs(nxt);
	dp[now] = 0;
	if(val[now] == -1)dp[now] = min(dp[tree[now][0]],dp[tree[now][1]]);
	else if(val[now] == -2)dp[now] = dp[tree[now][0]]+dp[tree[now][1]]+1;
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>s;
	for(int i = 0;i<s.size();i++)N += s[i] == '?';
	{
		int pt = 0;
		vector<int> v,stk;
		while(pt<s.size()){
			if(s[pt] == 'm'){
				if(s.substr(pt,3) == "min"){
					v.push_back(-1);
				}
				else{
					v.push_back(-2);
				}
				pt += 3;
			}
			else if(s[pt] == '?'){
				v.push_back(++vcnt);
				pt++;
			}
			else pt++;
		}
		vcnt = N;
		for(auto &i:v){
			stk.push_back(i);
			while(stk.size()>=2&&stk.end()[-1]>0&&stk.end()[-2]>0){
				int a = stk.end()[-1],b = stk.end()[-2];
				stk.pop_back();stk.pop_back();
				int c = ++vcnt;
				tree[c].push_back(a);
				tree[c].push_back(b);
				assert(stk.back()<0);
				val[c] = stk.back();
				stk.pop_back();
				rt = c;
				stk.push_back(c);
			}
		}
	}
	/*
	for(int i = 1;i<=vcnt;i++){
		if(val[i])cerr<<i<<' '<<val[i]<<":"<<tree[i][0]<<','<<tree[i][1]<<endl;
	}
	*/
	dfs(rt);
	int l = dp[rt];
	//for(int i = 1;i<=vcnt;i++)cerr<<dp[i]<<',';cerr<<endl;
	for(int i = 1;i<=vcnt;i++)if(val[i] < 0)val[i] = (val[i] == -2?-1:-2);
	/*
	for(int i = 1;i<=vcnt;i++){
		if(val[i])cerr<<i<<' '<<val[i]<<":"<<tree[i][0]<<','<<tree[i][1]<<endl;
	}
	*/
	dfs(rt);
	//for(int i = 1;i<=vcnt;i++)cerr<<dp[i]<<',';cerr<<endl;
	int r = N-dp[rt]-1;
	cout<<max(0,r-l+1)<<'\n';
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i = 0;i<s.size();i++)N += s[i] == '?';
      |                ~^~~~~~~~~
Main.cpp:29:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   while(pt<s.size()){
      |         ~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 23 ms 47228 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 23 ms 47192 KB Output is correct
5 Correct 22 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 21 ms 47192 KB Output is correct
8 Correct 22 ms 47208 KB Output is correct
9 Correct 20 ms 47196 KB Output is correct
10 Correct 21 ms 47344 KB Output is correct
11 Correct 21 ms 47196 KB Output is correct
12 Correct 21 ms 47196 KB Output is correct
13 Correct 22 ms 47196 KB Output is correct
14 Correct 21 ms 47196 KB Output is correct
15 Correct 22 ms 47424 KB Output is correct
16 Correct 26 ms 47196 KB Output is correct
17 Correct 23 ms 47196 KB Output is correct
18 Correct 22 ms 47240 KB Output is correct
19 Correct 21 ms 47196 KB Output is correct
20 Correct 22 ms 47196 KB Output is correct
21 Correct 24 ms 47400 KB Output is correct
22 Correct 22 ms 47428 KB Output is correct
23 Correct 21 ms 47196 KB Output is correct
24 Correct 21 ms 47196 KB Output is correct
25 Correct 22 ms 47196 KB Output is correct
26 Correct 22 ms 47192 KB Output is correct
27 Correct 21 ms 47196 KB Output is correct
28 Correct 24 ms 47440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 23 ms 47228 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 23 ms 47192 KB Output is correct
5 Correct 22 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 21 ms 47192 KB Output is correct
8 Correct 22 ms 47208 KB Output is correct
9 Correct 20 ms 47196 KB Output is correct
10 Correct 21 ms 47344 KB Output is correct
11 Correct 21 ms 47196 KB Output is correct
12 Correct 21 ms 47196 KB Output is correct
13 Correct 22 ms 47196 KB Output is correct
14 Correct 21 ms 47196 KB Output is correct
15 Correct 22 ms 47424 KB Output is correct
16 Correct 26 ms 47196 KB Output is correct
17 Correct 23 ms 47196 KB Output is correct
18 Correct 22 ms 47240 KB Output is correct
19 Correct 21 ms 47196 KB Output is correct
20 Correct 22 ms 47196 KB Output is correct
21 Correct 24 ms 47400 KB Output is correct
22 Correct 22 ms 47428 KB Output is correct
23 Correct 21 ms 47196 KB Output is correct
24 Correct 21 ms 47196 KB Output is correct
25 Correct 22 ms 47196 KB Output is correct
26 Correct 22 ms 47192 KB Output is correct
27 Correct 21 ms 47196 KB Output is correct
28 Correct 24 ms 47440 KB Output is correct
29 Correct 22 ms 47196 KB Output is correct
30 Correct 22 ms 47196 KB Output is correct
31 Correct 21 ms 47196 KB Output is correct
32 Correct 22 ms 47336 KB Output is correct
33 Correct 26 ms 47196 KB Output is correct
34 Correct 22 ms 47196 KB Output is correct
35 Correct 22 ms 47192 KB Output is correct
36 Correct 22 ms 47196 KB Output is correct
37 Correct 22 ms 47196 KB Output is correct
38 Correct 22 ms 47196 KB Output is correct
39 Correct 20 ms 47428 KB Output is correct
40 Correct 22 ms 47196 KB Output is correct
41 Correct 22 ms 47332 KB Output is correct
42 Correct 23 ms 47196 KB Output is correct
43 Correct 21 ms 47196 KB Output is correct
44 Correct 22 ms 47196 KB Output is correct
45 Correct 23 ms 47192 KB Output is correct
46 Correct 21 ms 47192 KB Output is correct
47 Correct 22 ms 47344 KB Output is correct
48 Correct 21 ms 47196 KB Output is correct
49 Correct 21 ms 47392 KB Output is correct
50 Correct 22 ms 47428 KB Output is correct
51 Correct 21 ms 47196 KB Output is correct
52 Correct 21 ms 47192 KB Output is correct
53 Correct 23 ms 47264 KB Output is correct
54 Correct 22 ms 47196 KB Output is correct
55 Correct 23 ms 47196 KB Output is correct
56 Correct 23 ms 47196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 149424 KB Output is correct
2 Correct 229 ms 150944 KB Output is correct
3 Correct 227 ms 150932 KB Output is correct
4 Correct 233 ms 150904 KB Output is correct
5 Correct 228 ms 150988 KB Output is correct
6 Correct 225 ms 150908 KB Output is correct
7 Correct 225 ms 150944 KB Output is correct
8 Correct 227 ms 150948 KB Output is correct
9 Correct 231 ms 150944 KB Output is correct
10 Correct 229 ms 151104 KB Output is correct
11 Correct 228 ms 150908 KB Output is correct
12 Correct 224 ms 150944 KB Output is correct
13 Correct 21 ms 47196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 23 ms 47228 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 23 ms 47192 KB Output is correct
5 Correct 22 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 21 ms 47192 KB Output is correct
8 Correct 22 ms 47208 KB Output is correct
9 Correct 20 ms 47196 KB Output is correct
10 Correct 21 ms 47344 KB Output is correct
11 Correct 21 ms 47196 KB Output is correct
12 Correct 21 ms 47196 KB Output is correct
13 Correct 22 ms 47196 KB Output is correct
14 Correct 21 ms 47196 KB Output is correct
15 Correct 22 ms 47424 KB Output is correct
16 Correct 26 ms 47196 KB Output is correct
17 Correct 23 ms 47196 KB Output is correct
18 Correct 22 ms 47240 KB Output is correct
19 Correct 21 ms 47196 KB Output is correct
20 Correct 22 ms 47196 KB Output is correct
21 Correct 24 ms 47400 KB Output is correct
22 Correct 22 ms 47428 KB Output is correct
23 Correct 21 ms 47196 KB Output is correct
24 Correct 21 ms 47196 KB Output is correct
25 Correct 22 ms 47196 KB Output is correct
26 Correct 22 ms 47192 KB Output is correct
27 Correct 21 ms 47196 KB Output is correct
28 Correct 24 ms 47440 KB Output is correct
29 Correct 22 ms 47196 KB Output is correct
30 Correct 22 ms 47196 KB Output is correct
31 Correct 21 ms 47196 KB Output is correct
32 Correct 22 ms 47336 KB Output is correct
33 Correct 26 ms 47196 KB Output is correct
34 Correct 22 ms 47196 KB Output is correct
35 Correct 22 ms 47192 KB Output is correct
36 Correct 22 ms 47196 KB Output is correct
37 Correct 22 ms 47196 KB Output is correct
38 Correct 22 ms 47196 KB Output is correct
39 Correct 20 ms 47428 KB Output is correct
40 Correct 22 ms 47196 KB Output is correct
41 Correct 22 ms 47332 KB Output is correct
42 Correct 23 ms 47196 KB Output is correct
43 Correct 21 ms 47196 KB Output is correct
44 Correct 22 ms 47196 KB Output is correct
45 Correct 23 ms 47192 KB Output is correct
46 Correct 21 ms 47192 KB Output is correct
47 Correct 22 ms 47344 KB Output is correct
48 Correct 21 ms 47196 KB Output is correct
49 Correct 21 ms 47392 KB Output is correct
50 Correct 22 ms 47428 KB Output is correct
51 Correct 21 ms 47196 KB Output is correct
52 Correct 21 ms 47192 KB Output is correct
53 Correct 23 ms 47264 KB Output is correct
54 Correct 22 ms 47196 KB Output is correct
55 Correct 23 ms 47196 KB Output is correct
56 Correct 23 ms 47196 KB Output is correct
57 Correct 21 ms 47452 KB Output is correct
58 Correct 21 ms 47452 KB Output is correct
59 Correct 21 ms 47488 KB Output is correct
60 Correct 21 ms 47420 KB Output is correct
61 Correct 22 ms 47444 KB Output is correct
62 Correct 24 ms 47452 KB Output is correct
63 Correct 21 ms 47448 KB Output is correct
64 Correct 22 ms 47452 KB Output is correct
65 Correct 21 ms 47452 KB Output is correct
66 Correct 21 ms 47452 KB Output is correct
67 Correct 24 ms 47452 KB Output is correct
68 Correct 22 ms 47448 KB Output is correct
69 Correct 20 ms 47464 KB Output is correct
70 Correct 23 ms 47452 KB Output is correct
71 Correct 22 ms 47264 KB Output is correct
72 Correct 22 ms 47452 KB Output is correct
73 Correct 27 ms 47452 KB Output is correct
74 Correct 22 ms 47452 KB Output is correct
75 Correct 22 ms 47452 KB Output is correct
76 Correct 21 ms 47440 KB Output is correct
77 Correct 21 ms 47448 KB Output is correct
78 Correct 21 ms 47440 KB Output is correct
79 Correct 21 ms 47444 KB Output is correct
80 Correct 23 ms 47452 KB Output is correct
81 Correct 21 ms 47336 KB Output is correct
82 Correct 22 ms 47448 KB Output is correct
83 Correct 23 ms 47376 KB Output is correct
84 Correct 22 ms 47448 KB Output is correct
85 Correct 21 ms 47452 KB Output is correct
86 Correct 22 ms 47196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 23 ms 47228 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 23 ms 47192 KB Output is correct
5 Correct 22 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 21 ms 47192 KB Output is correct
8 Correct 22 ms 47208 KB Output is correct
9 Correct 20 ms 47196 KB Output is correct
10 Correct 21 ms 47344 KB Output is correct
11 Correct 21 ms 47196 KB Output is correct
12 Correct 21 ms 47196 KB Output is correct
13 Correct 22 ms 47196 KB Output is correct
14 Correct 21 ms 47196 KB Output is correct
15 Correct 22 ms 47424 KB Output is correct
16 Correct 26 ms 47196 KB Output is correct
17 Correct 23 ms 47196 KB Output is correct
18 Correct 22 ms 47240 KB Output is correct
19 Correct 21 ms 47196 KB Output is correct
20 Correct 22 ms 47196 KB Output is correct
21 Correct 24 ms 47400 KB Output is correct
22 Correct 22 ms 47428 KB Output is correct
23 Correct 21 ms 47196 KB Output is correct
24 Correct 21 ms 47196 KB Output is correct
25 Correct 22 ms 47196 KB Output is correct
26 Correct 22 ms 47192 KB Output is correct
27 Correct 21 ms 47196 KB Output is correct
28 Correct 24 ms 47440 KB Output is correct
29 Correct 22 ms 47196 KB Output is correct
30 Correct 22 ms 47196 KB Output is correct
31 Correct 21 ms 47196 KB Output is correct
32 Correct 22 ms 47336 KB Output is correct
33 Correct 26 ms 47196 KB Output is correct
34 Correct 22 ms 47196 KB Output is correct
35 Correct 22 ms 47192 KB Output is correct
36 Correct 22 ms 47196 KB Output is correct
37 Correct 22 ms 47196 KB Output is correct
38 Correct 22 ms 47196 KB Output is correct
39 Correct 20 ms 47428 KB Output is correct
40 Correct 22 ms 47196 KB Output is correct
41 Correct 22 ms 47332 KB Output is correct
42 Correct 23 ms 47196 KB Output is correct
43 Correct 21 ms 47196 KB Output is correct
44 Correct 22 ms 47196 KB Output is correct
45 Correct 23 ms 47192 KB Output is correct
46 Correct 21 ms 47192 KB Output is correct
47 Correct 22 ms 47344 KB Output is correct
48 Correct 21 ms 47196 KB Output is correct
49 Correct 21 ms 47392 KB Output is correct
50 Correct 22 ms 47428 KB Output is correct
51 Correct 21 ms 47196 KB Output is correct
52 Correct 21 ms 47192 KB Output is correct
53 Correct 23 ms 47264 KB Output is correct
54 Correct 22 ms 47196 KB Output is correct
55 Correct 23 ms 47196 KB Output is correct
56 Correct 23 ms 47196 KB Output is correct
57 Correct 226 ms 149424 KB Output is correct
58 Correct 229 ms 150944 KB Output is correct
59 Correct 227 ms 150932 KB Output is correct
60 Correct 233 ms 150904 KB Output is correct
61 Correct 228 ms 150988 KB Output is correct
62 Correct 225 ms 150908 KB Output is correct
63 Correct 225 ms 150944 KB Output is correct
64 Correct 227 ms 150948 KB Output is correct
65 Correct 231 ms 150944 KB Output is correct
66 Correct 229 ms 151104 KB Output is correct
67 Correct 228 ms 150908 KB Output is correct
68 Correct 224 ms 150944 KB Output is correct
69 Correct 21 ms 47196 KB Output is correct
70 Correct 21 ms 47452 KB Output is correct
71 Correct 21 ms 47452 KB Output is correct
72 Correct 21 ms 47488 KB Output is correct
73 Correct 21 ms 47420 KB Output is correct
74 Correct 22 ms 47444 KB Output is correct
75 Correct 24 ms 47452 KB Output is correct
76 Correct 21 ms 47448 KB Output is correct
77 Correct 22 ms 47452 KB Output is correct
78 Correct 21 ms 47452 KB Output is correct
79 Correct 21 ms 47452 KB Output is correct
80 Correct 24 ms 47452 KB Output is correct
81 Correct 22 ms 47448 KB Output is correct
82 Correct 20 ms 47464 KB Output is correct
83 Correct 23 ms 47452 KB Output is correct
84 Correct 22 ms 47264 KB Output is correct
85 Correct 22 ms 47452 KB Output is correct
86 Correct 27 ms 47452 KB Output is correct
87 Correct 22 ms 47452 KB Output is correct
88 Correct 22 ms 47452 KB Output is correct
89 Correct 21 ms 47440 KB Output is correct
90 Correct 21 ms 47448 KB Output is correct
91 Correct 21 ms 47440 KB Output is correct
92 Correct 21 ms 47444 KB Output is correct
93 Correct 23 ms 47452 KB Output is correct
94 Correct 21 ms 47336 KB Output is correct
95 Correct 22 ms 47448 KB Output is correct
96 Correct 23 ms 47376 KB Output is correct
97 Correct 22 ms 47448 KB Output is correct
98 Correct 21 ms 47452 KB Output is correct
99 Correct 22 ms 47196 KB Output is correct
100 Correct 184 ms 104052 KB Output is correct
101 Correct 183 ms 104280 KB Output is correct
102 Correct 179 ms 104124 KB Output is correct
103 Correct 162 ms 104124 KB Output is correct
104 Correct 154 ms 104108 KB Output is correct
105 Correct 187 ms 121628 KB Output is correct
106 Correct 189 ms 121684 KB Output is correct
107 Correct 183 ms 121648 KB Output is correct
108 Correct 185 ms 121576 KB Output is correct
109 Correct 181 ms 121656 KB Output is correct
110 Correct 183 ms 104332 KB Output is correct
111 Correct 183 ms 104120 KB Output is correct
112 Correct 159 ms 104120 KB Output is correct
113 Correct 174 ms 104124 KB Output is correct
114 Correct 168 ms 104128 KB Output is correct
115 Correct 247 ms 150948 KB Output is correct
116 Correct 233 ms 151052 KB Output is correct
117 Correct 217 ms 150984 KB Output is correct
118 Correct 219 ms 150924 KB Output is correct
119 Correct 220 ms 150984 KB Output is correct
120 Correct 170 ms 104116 KB Output is correct
121 Correct 166 ms 104084 KB Output is correct
122 Correct 180 ms 104120 KB Output is correct
123 Correct 179 ms 104124 KB Output is correct
124 Correct 173 ms 131416 KB Output is correct
125 Correct 175 ms 131360 KB Output is correct
126 Correct 180 ms 131448 KB Output is correct
127 Correct 179 ms 131456 KB Output is correct
128 Correct 96 ms 76996 KB Output is correct
129 Correct 88 ms 77144 KB Output is correct
130 Correct 88 ms 77000 KB Output is correct
131 Correct 21 ms 47196 KB Output is correct