답안 #839177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839177 2023-08-29T01:36:34 Z dolphingarlic Homework (CEOI22_homework) C++17
100 / 100
290 ms 177580 KB
#include <bits/stdc++.h>
using namespace std;const int N=3e6;vector<int>g[N];int p[N],n=0,t[N],sz[N],mn[N],mx[N];void dfs(int z=1){if(!g[z].size())return;int u=g[z][0],v=g[z][1];dfs(u);dfs(v);sz[z]+=sz[u]+sz[v];if(t[z]==1){mn[z]=min(mn[u],mn[v]);mx[z]=mx[u]+mx[v]-1;}if(t[z]==2){mn[z]=mn[u]+mn[v];mx[z]=max(sz[u]+mx[v],sz[v]+mx[u]);}}main(){string s;cin>>s;int c=0;for(int i=0;i<s.size();i++){if(s[i]=='m'){p[++n]=c;g[c].push_back(n);c=n;if(s[i+2]=='n')t[c]=1;else t[c]=2;i+=3;}else if(s[i]=='?'){p[++n]=c;g[c].push_back(n);c=n;mn[c]=mx[c]=sz[c]=1;}else c=p[c];}dfs();cout<<mx[1]-mn[1]+1;}

Compilation message

Main.cpp:2:310: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    2 | using namespace std;const int N=3e6;vector<int>g[N];int p[N],n=0,t[N],sz[N],mn[N],mx[N];void dfs(int z=1){if(!g[z].size())return;int u=g[z][0],v=g[z][1];dfs(u);dfs(v);sz[z]+=sz[u]+sz[v];if(t[z]==1){mn[z]=min(mn[u],mn[v]);mx[z]=mx[u]+mx[v]-1;}if(t[z]==2){mn[z]=mn[u]+mn[v];mx[z]=max(sz[u]+mx[v],sz[v]+mx[u]);}}main(){string s;cin>>s;int c=0;for(int i=0;i<s.size();i++){if(s[i]=='m'){p[++n]=c;g[c].push_back(n);c=n;if(s[i+2]=='n')t[c]=1;else t[c]=2;i+=3;}else if(s[i]=='?'){p[++n]=c;g[c].push_back(n);c=n;mn[c]=mx[c]=sz[c]=1;}else c=p[c];}dfs();cout<<mx[1]-mn[1]+1;}
      |                                                                                                                                                                                                                                                                                                                      ^~~~
Main.cpp: In function 'int main()':
Main.cpp:2:354: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | using namespace std;const int N=3e6;vector<int>g[N];int p[N],n=0,t[N],sz[N],mn[N],mx[N];void dfs(int z=1){if(!g[z].size())return;int u=g[z][0],v=g[z][1];dfs(u);dfs(v);sz[z]+=sz[u]+sz[v];if(t[z]==1){mn[z]=min(mn[u],mn[v]);mx[z]=mx[u]+mx[v]-1;}if(t[z]==2){mn[z]=mn[u]+mn[v];mx[z]=max(sz[u]+mx[v],sz[v]+mx[u]);}}main(){string s;cin>>s;int c=0;for(int i=0;i<s.size();i++){if(s[i]=='m'){p[++n]=c;g[c].push_back(n);c=n;if(s[i+2]=='n')t[c]=1;else t[c]=2;i+=3;}else if(s[i]=='?'){p[++n]=c;g[c].push_back(n);c=n;mn[c]=mx[c]=sz[c]=1;}else c=p[c];}dfs();cout<<mx[1]-mn[1]+1;}
      |                                                                                                                                                                                                                                                                                                                                                                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB Output is correct
2 Correct 31 ms 70740 KB Output is correct
3 Correct 33 ms 70732 KB Output is correct
4 Correct 32 ms 70740 KB Output is correct
5 Correct 31 ms 70732 KB Output is correct
6 Correct 32 ms 70740 KB Output is correct
7 Correct 33 ms 70732 KB Output is correct
8 Correct 32 ms 70732 KB Output is correct
9 Correct 32 ms 70732 KB Output is correct
10 Correct 32 ms 70740 KB Output is correct
11 Correct 33 ms 70740 KB Output is correct
12 Correct 33 ms 70740 KB Output is correct
13 Correct 38 ms 70740 KB Output is correct
14 Correct 32 ms 70740 KB Output is correct
15 Correct 34 ms 70700 KB Output is correct
16 Correct 36 ms 70992 KB Output is correct
17 Correct 32 ms 70752 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 39 ms 70732 KB Output is correct
20 Correct 32 ms 70752 KB Output is correct
21 Correct 33 ms 70740 KB Output is correct
22 Correct 33 ms 70740 KB Output is correct
23 Correct 32 ms 70788 KB Output is correct
24 Correct 32 ms 70852 KB Output is correct
25 Correct 32 ms 70740 KB Output is correct
26 Correct 33 ms 70740 KB Output is correct
27 Correct 32 ms 70704 KB Output is correct
28 Correct 33 ms 70740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB Output is correct
2 Correct 31 ms 70740 KB Output is correct
3 Correct 33 ms 70732 KB Output is correct
4 Correct 32 ms 70740 KB Output is correct
5 Correct 31 ms 70732 KB Output is correct
6 Correct 32 ms 70740 KB Output is correct
7 Correct 33 ms 70732 KB Output is correct
8 Correct 32 ms 70732 KB Output is correct
9 Correct 32 ms 70732 KB Output is correct
10 Correct 32 ms 70740 KB Output is correct
11 Correct 33 ms 70740 KB Output is correct
12 Correct 33 ms 70740 KB Output is correct
13 Correct 38 ms 70740 KB Output is correct
14 Correct 32 ms 70740 KB Output is correct
15 Correct 34 ms 70700 KB Output is correct
16 Correct 36 ms 70992 KB Output is correct
17 Correct 32 ms 70752 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 39 ms 70732 KB Output is correct
20 Correct 32 ms 70752 KB Output is correct
21 Correct 33 ms 70740 KB Output is correct
22 Correct 33 ms 70740 KB Output is correct
23 Correct 32 ms 70788 KB Output is correct
24 Correct 32 ms 70852 KB Output is correct
25 Correct 32 ms 70740 KB Output is correct
26 Correct 33 ms 70740 KB Output is correct
27 Correct 32 ms 70704 KB Output is correct
28 Correct 33 ms 70740 KB Output is correct
29 Correct 33 ms 70740 KB Output is correct
30 Correct 33 ms 70780 KB Output is correct
31 Correct 33 ms 70740 KB Output is correct
32 Correct 33 ms 70756 KB Output is correct
33 Correct 33 ms 70740 KB Output is correct
34 Correct 32 ms 70856 KB Output is correct
35 Correct 36 ms 70736 KB Output is correct
36 Correct 38 ms 70740 KB Output is correct
37 Correct 31 ms 70740 KB Output is correct
38 Correct 32 ms 70740 KB Output is correct
39 Correct 32 ms 70732 KB Output is correct
40 Correct 33 ms 70740 KB Output is correct
41 Correct 32 ms 70772 KB Output is correct
42 Correct 33 ms 70756 KB Output is correct
43 Correct 32 ms 70740 KB Output is correct
44 Correct 32 ms 70740 KB Output is correct
45 Correct 34 ms 70740 KB Output is correct
46 Correct 32 ms 70772 KB Output is correct
47 Correct 38 ms 70740 KB Output is correct
48 Correct 33 ms 70712 KB Output is correct
49 Correct 32 ms 70740 KB Output is correct
50 Correct 33 ms 70764 KB Output is correct
51 Correct 32 ms 70740 KB Output is correct
52 Correct 33 ms 70740 KB Output is correct
53 Correct 34 ms 70672 KB Output is correct
54 Correct 33 ms 70756 KB Output is correct
55 Correct 32 ms 70740 KB Output is correct
56 Correct 32 ms 70740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 177348 KB Output is correct
2 Correct 260 ms 177392 KB Output is correct
3 Correct 254 ms 177448 KB Output is correct
4 Correct 247 ms 177320 KB Output is correct
5 Correct 246 ms 177320 KB Output is correct
6 Correct 249 ms 177320 KB Output is correct
7 Correct 254 ms 177580 KB Output is correct
8 Correct 248 ms 177384 KB Output is correct
9 Correct 248 ms 177532 KB Output is correct
10 Correct 247 ms 177364 KB Output is correct
11 Correct 252 ms 177372 KB Output is correct
12 Correct 244 ms 177368 KB Output is correct
13 Correct 32 ms 70740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB Output is correct
2 Correct 31 ms 70740 KB Output is correct
3 Correct 33 ms 70732 KB Output is correct
4 Correct 32 ms 70740 KB Output is correct
5 Correct 31 ms 70732 KB Output is correct
6 Correct 32 ms 70740 KB Output is correct
7 Correct 33 ms 70732 KB Output is correct
8 Correct 32 ms 70732 KB Output is correct
9 Correct 32 ms 70732 KB Output is correct
10 Correct 32 ms 70740 KB Output is correct
11 Correct 33 ms 70740 KB Output is correct
12 Correct 33 ms 70740 KB Output is correct
13 Correct 38 ms 70740 KB Output is correct
14 Correct 32 ms 70740 KB Output is correct
15 Correct 34 ms 70700 KB Output is correct
16 Correct 36 ms 70992 KB Output is correct
17 Correct 32 ms 70752 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 39 ms 70732 KB Output is correct
20 Correct 32 ms 70752 KB Output is correct
21 Correct 33 ms 70740 KB Output is correct
22 Correct 33 ms 70740 KB Output is correct
23 Correct 32 ms 70788 KB Output is correct
24 Correct 32 ms 70852 KB Output is correct
25 Correct 32 ms 70740 KB Output is correct
26 Correct 33 ms 70740 KB Output is correct
27 Correct 32 ms 70704 KB Output is correct
28 Correct 33 ms 70740 KB Output is correct
29 Correct 33 ms 70740 KB Output is correct
30 Correct 33 ms 70780 KB Output is correct
31 Correct 33 ms 70740 KB Output is correct
32 Correct 33 ms 70756 KB Output is correct
33 Correct 33 ms 70740 KB Output is correct
34 Correct 32 ms 70856 KB Output is correct
35 Correct 36 ms 70736 KB Output is correct
36 Correct 38 ms 70740 KB Output is correct
37 Correct 31 ms 70740 KB Output is correct
38 Correct 32 ms 70740 KB Output is correct
39 Correct 32 ms 70732 KB Output is correct
40 Correct 33 ms 70740 KB Output is correct
41 Correct 32 ms 70772 KB Output is correct
42 Correct 33 ms 70756 KB Output is correct
43 Correct 32 ms 70740 KB Output is correct
44 Correct 32 ms 70740 KB Output is correct
45 Correct 34 ms 70740 KB Output is correct
46 Correct 32 ms 70772 KB Output is correct
47 Correct 38 ms 70740 KB Output is correct
48 Correct 33 ms 70712 KB Output is correct
49 Correct 32 ms 70740 KB Output is correct
50 Correct 33 ms 70764 KB Output is correct
51 Correct 32 ms 70740 KB Output is correct
52 Correct 33 ms 70740 KB Output is correct
53 Correct 34 ms 70672 KB Output is correct
54 Correct 33 ms 70756 KB Output is correct
55 Correct 32 ms 70740 KB Output is correct
56 Correct 32 ms 70740 KB Output is correct
57 Correct 32 ms 70740 KB Output is correct
58 Correct 32 ms 70740 KB Output is correct
59 Correct 33 ms 70732 KB Output is correct
60 Correct 33 ms 70868 KB Output is correct
61 Correct 32 ms 70732 KB Output is correct
62 Correct 32 ms 70868 KB Output is correct
63 Correct 36 ms 70872 KB Output is correct
64 Correct 33 ms 70868 KB Output is correct
65 Correct 33 ms 70832 KB Output is correct
66 Correct 33 ms 70868 KB Output is correct
67 Correct 34 ms 70828 KB Output is correct
68 Correct 37 ms 70868 KB Output is correct
69 Correct 33 ms 70848 KB Output is correct
70 Correct 35 ms 70732 KB Output is correct
71 Correct 33 ms 70740 KB Output is correct
72 Correct 33 ms 70868 KB Output is correct
73 Correct 35 ms 70808 KB Output is correct
74 Correct 33 ms 70868 KB Output is correct
75 Correct 32 ms 70868 KB Output is correct
76 Correct 33 ms 70876 KB Output is correct
77 Correct 33 ms 70864 KB Output is correct
78 Correct 32 ms 70868 KB Output is correct
79 Correct 33 ms 70732 KB Output is correct
80 Correct 34 ms 70804 KB Output is correct
81 Correct 33 ms 70868 KB Output is correct
82 Correct 33 ms 70868 KB Output is correct
83 Correct 38 ms 70728 KB Output is correct
84 Correct 33 ms 70740 KB Output is correct
85 Correct 33 ms 70740 KB Output is correct
86 Correct 32 ms 70704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB Output is correct
2 Correct 31 ms 70740 KB Output is correct
3 Correct 33 ms 70732 KB Output is correct
4 Correct 32 ms 70740 KB Output is correct
5 Correct 31 ms 70732 KB Output is correct
6 Correct 32 ms 70740 KB Output is correct
7 Correct 33 ms 70732 KB Output is correct
8 Correct 32 ms 70732 KB Output is correct
9 Correct 32 ms 70732 KB Output is correct
10 Correct 32 ms 70740 KB Output is correct
11 Correct 33 ms 70740 KB Output is correct
12 Correct 33 ms 70740 KB Output is correct
13 Correct 38 ms 70740 KB Output is correct
14 Correct 32 ms 70740 KB Output is correct
15 Correct 34 ms 70700 KB Output is correct
16 Correct 36 ms 70992 KB Output is correct
17 Correct 32 ms 70752 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 39 ms 70732 KB Output is correct
20 Correct 32 ms 70752 KB Output is correct
21 Correct 33 ms 70740 KB Output is correct
22 Correct 33 ms 70740 KB Output is correct
23 Correct 32 ms 70788 KB Output is correct
24 Correct 32 ms 70852 KB Output is correct
25 Correct 32 ms 70740 KB Output is correct
26 Correct 33 ms 70740 KB Output is correct
27 Correct 32 ms 70704 KB Output is correct
28 Correct 33 ms 70740 KB Output is correct
29 Correct 33 ms 70740 KB Output is correct
30 Correct 33 ms 70780 KB Output is correct
31 Correct 33 ms 70740 KB Output is correct
32 Correct 33 ms 70756 KB Output is correct
33 Correct 33 ms 70740 KB Output is correct
34 Correct 32 ms 70856 KB Output is correct
35 Correct 36 ms 70736 KB Output is correct
36 Correct 38 ms 70740 KB Output is correct
37 Correct 31 ms 70740 KB Output is correct
38 Correct 32 ms 70740 KB Output is correct
39 Correct 32 ms 70732 KB Output is correct
40 Correct 33 ms 70740 KB Output is correct
41 Correct 32 ms 70772 KB Output is correct
42 Correct 33 ms 70756 KB Output is correct
43 Correct 32 ms 70740 KB Output is correct
44 Correct 32 ms 70740 KB Output is correct
45 Correct 34 ms 70740 KB Output is correct
46 Correct 32 ms 70772 KB Output is correct
47 Correct 38 ms 70740 KB Output is correct
48 Correct 33 ms 70712 KB Output is correct
49 Correct 32 ms 70740 KB Output is correct
50 Correct 33 ms 70764 KB Output is correct
51 Correct 32 ms 70740 KB Output is correct
52 Correct 33 ms 70740 KB Output is correct
53 Correct 34 ms 70672 KB Output is correct
54 Correct 33 ms 70756 KB Output is correct
55 Correct 32 ms 70740 KB Output is correct
56 Correct 32 ms 70740 KB Output is correct
57 Correct 265 ms 177348 KB Output is correct
58 Correct 260 ms 177392 KB Output is correct
59 Correct 254 ms 177448 KB Output is correct
60 Correct 247 ms 177320 KB Output is correct
61 Correct 246 ms 177320 KB Output is correct
62 Correct 249 ms 177320 KB Output is correct
63 Correct 254 ms 177580 KB Output is correct
64 Correct 248 ms 177384 KB Output is correct
65 Correct 248 ms 177532 KB Output is correct
66 Correct 247 ms 177364 KB Output is correct
67 Correct 252 ms 177372 KB Output is correct
68 Correct 244 ms 177368 KB Output is correct
69 Correct 32 ms 70740 KB Output is correct
70 Correct 32 ms 70740 KB Output is correct
71 Correct 32 ms 70740 KB Output is correct
72 Correct 33 ms 70732 KB Output is correct
73 Correct 33 ms 70868 KB Output is correct
74 Correct 32 ms 70732 KB Output is correct
75 Correct 32 ms 70868 KB Output is correct
76 Correct 36 ms 70872 KB Output is correct
77 Correct 33 ms 70868 KB Output is correct
78 Correct 33 ms 70832 KB Output is correct
79 Correct 33 ms 70868 KB Output is correct
80 Correct 34 ms 70828 KB Output is correct
81 Correct 37 ms 70868 KB Output is correct
82 Correct 33 ms 70848 KB Output is correct
83 Correct 35 ms 70732 KB Output is correct
84 Correct 33 ms 70740 KB Output is correct
85 Correct 33 ms 70868 KB Output is correct
86 Correct 35 ms 70808 KB Output is correct
87 Correct 33 ms 70868 KB Output is correct
88 Correct 32 ms 70868 KB Output is correct
89 Correct 33 ms 70876 KB Output is correct
90 Correct 33 ms 70864 KB Output is correct
91 Correct 32 ms 70868 KB Output is correct
92 Correct 33 ms 70732 KB Output is correct
93 Correct 34 ms 70804 KB Output is correct
94 Correct 33 ms 70868 KB Output is correct
95 Correct 33 ms 70868 KB Output is correct
96 Correct 38 ms 70728 KB Output is correct
97 Correct 33 ms 70740 KB Output is correct
98 Correct 33 ms 70740 KB Output is correct
99 Correct 32 ms 70704 KB Output is correct
100 Correct 227 ms 148000 KB Output is correct
101 Correct 242 ms 148012 KB Output is correct
102 Correct 230 ms 148084 KB Output is correct
103 Correct 224 ms 147992 KB Output is correct
104 Correct 223 ms 148000 KB Output is correct
105 Correct 244 ms 158436 KB Output is correct
106 Correct 260 ms 158480 KB Output is correct
107 Correct 242 ms 158448 KB Output is correct
108 Correct 239 ms 158376 KB Output is correct
109 Correct 255 ms 158492 KB Output is correct
110 Correct 237 ms 147980 KB Output is correct
111 Correct 239 ms 148088 KB Output is correct
112 Correct 235 ms 148056 KB Output is correct
113 Correct 230 ms 148032 KB Output is correct
114 Correct 251 ms 148104 KB Output is correct
115 Correct 286 ms 177316 KB Output is correct
116 Correct 254 ms 177320 KB Output is correct
117 Correct 244 ms 177336 KB Output is correct
118 Correct 290 ms 177364 KB Output is correct
119 Correct 274 ms 177320 KB Output is correct
120 Correct 231 ms 148032 KB Output is correct
121 Correct 232 ms 148052 KB Output is correct
122 Correct 234 ms 147996 KB Output is correct
123 Correct 238 ms 148096 KB Output is correct
124 Correct 238 ms 163696 KB Output is correct
125 Correct 228 ms 163636 KB Output is correct
126 Correct 236 ms 163692 KB Output is correct
127 Correct 230 ms 163700 KB Output is correct
128 Correct 134 ms 111288 KB Output is correct
129 Correct 128 ms 111228 KB Output is correct
130 Correct 143 ms 111280 KB Output is correct
131 Correct 35 ms 70904 KB Output is correct