# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1099655 | 2024-10-12T00:46:37 Z | Zero_OP | Homework (CEOI22_homework) | C++14 | 220 ms | 214472 KB |
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i) #define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i) #define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i) #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } using ll = long long; using ld = long double; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); } template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); } const int MAX = 4e6 + 5; int len, n; string s; int sz[MAX], l[MAX], r[MAX]; bitset<MAX> is_leaf, is_min; vector<int> adj[MAX]; void dfs(int u){ if(is_leaf[u]){ l[u] = r[u] = 1; sz[u] = 1; return; } int v1 = adj[u][0]; int v2 = adj[u][1]; dfs(v1); dfs(v2); sz[u] = sz[v1] + sz[v2]; if(is_min[u]){ l[u] = min(l[v1], l[v2]); r[u] = r[v1] + r[v2] - 1; } else{ l[u] = l[v1] + l[v2]; r[u] = max(sz[v1] + r[v2], sz[v2] + r[v1]); } } void testcase(){ cin >> s; len = sz(s); stack<int> st; rep(i, 0, len){ if(s[i] == '('){ ++n; if(!st.empty()){ adj[st.top()].push_back(n); } st.push(n); is_min[n] = (s[i - 1] == 'n'); } else if(s[i] == ')'){ st.pop(); } else if(s[i] == '?'){ ++n; is_leaf[n] = true; adj[st.top()].push_back(n); } } dfs(1); cout << r[1] - l[1] + 1 << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define filename "task" if(fopen(filename".inp", "r")){ freopen(filename".inp", "r", stdin); freopen(filename".out", "w", stdout); } int T = 1; //cin >> T; while(T--) testcase(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 94288 KB | Output is correct |
2 | Correct | 43 ms | 94292 KB | Output is correct |
3 | Correct | 42 ms | 94292 KB | Output is correct |
4 | Correct | 43 ms | 94292 KB | Output is correct |
5 | Correct | 41 ms | 94292 KB | Output is correct |
6 | Correct | 42 ms | 94292 KB | Output is correct |
7 | Correct | 41 ms | 94400 KB | Output is correct |
8 | Correct | 44 ms | 94288 KB | Output is correct |
9 | Correct | 39 ms | 94300 KB | Output is correct |
10 | Correct | 48 ms | 94292 KB | Output is correct |
11 | Correct | 42 ms | 94296 KB | Output is correct |
12 | Correct | 42 ms | 94288 KB | Output is correct |
13 | Correct | 42 ms | 94292 KB | Output is correct |
14 | Correct | 42 ms | 94380 KB | Output is correct |
15 | Correct | 43 ms | 94288 KB | Output is correct |
16 | Correct | 42 ms | 94288 KB | Output is correct |
17 | Correct | 48 ms | 94288 KB | Output is correct |
18 | Correct | 43 ms | 94288 KB | Output is correct |
19 | Correct | 40 ms | 94288 KB | Output is correct |
20 | Correct | 37 ms | 94160 KB | Output is correct |
21 | Correct | 37 ms | 94300 KB | Output is correct |
22 | Correct | 37 ms | 94348 KB | Output is correct |
23 | Correct | 37 ms | 94300 KB | Output is correct |
24 | Correct | 37 ms | 94216 KB | Output is correct |
25 | Correct | 37 ms | 94296 KB | Output is correct |
26 | Correct | 38 ms | 94292 KB | Output is correct |
27 | Correct | 37 ms | 94288 KB | Output is correct |
28 | Correct | 37 ms | 94288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 94288 KB | Output is correct |
2 | Correct | 43 ms | 94292 KB | Output is correct |
3 | Correct | 42 ms | 94292 KB | Output is correct |
4 | Correct | 43 ms | 94292 KB | Output is correct |
5 | Correct | 41 ms | 94292 KB | Output is correct |
6 | Correct | 42 ms | 94292 KB | Output is correct |
7 | Correct | 41 ms | 94400 KB | Output is correct |
8 | Correct | 44 ms | 94288 KB | Output is correct |
9 | Correct | 39 ms | 94300 KB | Output is correct |
10 | Correct | 48 ms | 94292 KB | Output is correct |
11 | Correct | 42 ms | 94296 KB | Output is correct |
12 | Correct | 42 ms | 94288 KB | Output is correct |
13 | Correct | 42 ms | 94292 KB | Output is correct |
14 | Correct | 42 ms | 94380 KB | Output is correct |
15 | Correct | 43 ms | 94288 KB | Output is correct |
16 | Correct | 42 ms | 94288 KB | Output is correct |
17 | Correct | 48 ms | 94288 KB | Output is correct |
18 | Correct | 43 ms | 94288 KB | Output is correct |
19 | Correct | 40 ms | 94288 KB | Output is correct |
20 | Correct | 37 ms | 94160 KB | Output is correct |
21 | Correct | 37 ms | 94300 KB | Output is correct |
22 | Correct | 37 ms | 94348 KB | Output is correct |
23 | Correct | 37 ms | 94300 KB | Output is correct |
24 | Correct | 37 ms | 94216 KB | Output is correct |
25 | Correct | 37 ms | 94296 KB | Output is correct |
26 | Correct | 38 ms | 94292 KB | Output is correct |
27 | Correct | 37 ms | 94288 KB | Output is correct |
28 | Correct | 37 ms | 94288 KB | Output is correct |
29 | Correct | 37 ms | 94292 KB | Output is correct |
30 | Correct | 36 ms | 94292 KB | Output is correct |
31 | Correct | 42 ms | 94372 KB | Output is correct |
32 | Correct | 38 ms | 94288 KB | Output is correct |
33 | Correct | 37 ms | 94228 KB | Output is correct |
34 | Correct | 37 ms | 94344 KB | Output is correct |
35 | Correct | 38 ms | 94300 KB | Output is correct |
36 | Correct | 42 ms | 94288 KB | Output is correct |
37 | Correct | 43 ms | 94288 KB | Output is correct |
38 | Correct | 43 ms | 94348 KB | Output is correct |
39 | Correct | 41 ms | 94292 KB | Output is correct |
40 | Correct | 41 ms | 94292 KB | Output is correct |
41 | Correct | 43 ms | 94288 KB | Output is correct |
42 | Correct | 42 ms | 94292 KB | Output is correct |
43 | Correct | 42 ms | 94292 KB | Output is correct |
44 | Correct | 43 ms | 94288 KB | Output is correct |
45 | Correct | 42 ms | 94288 KB | Output is correct |
46 | Correct | 44 ms | 94300 KB | Output is correct |
47 | Correct | 43 ms | 94292 KB | Output is correct |
48 | Correct | 44 ms | 94300 KB | Output is correct |
49 | Correct | 42 ms | 94268 KB | Output is correct |
50 | Correct | 43 ms | 94288 KB | Output is correct |
51 | Correct | 43 ms | 94288 KB | Output is correct |
52 | Correct | 44 ms | 94292 KB | Output is correct |
53 | Correct | 40 ms | 94196 KB | Output is correct |
54 | Correct | 43 ms | 94292 KB | Output is correct |
55 | Correct | 44 ms | 94288 KB | Output is correct |
56 | Correct | 43 ms | 94208 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 205 ms | 214216 KB | Output is correct |
2 | Correct | 201 ms | 214220 KB | Output is correct |
3 | Correct | 210 ms | 214220 KB | Output is correct |
4 | Correct | 211 ms | 214292 KB | Output is correct |
5 | Correct | 207 ms | 214312 KB | Output is correct |
6 | Correct | 206 ms | 214216 KB | Output is correct |
7 | Correct | 197 ms | 214188 KB | Output is correct |
8 | Correct | 197 ms | 214216 KB | Output is correct |
9 | Correct | 205 ms | 214220 KB | Output is correct |
10 | Correct | 200 ms | 214472 KB | Output is correct |
11 | Correct | 202 ms | 214220 KB | Output is correct |
12 | Correct | 206 ms | 214216 KB | Output is correct |
13 | Correct | 43 ms | 94300 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 94288 KB | Output is correct |
2 | Correct | 43 ms | 94292 KB | Output is correct |
3 | Correct | 42 ms | 94292 KB | Output is correct |
4 | Correct | 43 ms | 94292 KB | Output is correct |
5 | Correct | 41 ms | 94292 KB | Output is correct |
6 | Correct | 42 ms | 94292 KB | Output is correct |
7 | Correct | 41 ms | 94400 KB | Output is correct |
8 | Correct | 44 ms | 94288 KB | Output is correct |
9 | Correct | 39 ms | 94300 KB | Output is correct |
10 | Correct | 48 ms | 94292 KB | Output is correct |
11 | Correct | 42 ms | 94296 KB | Output is correct |
12 | Correct | 42 ms | 94288 KB | Output is correct |
13 | Correct | 42 ms | 94292 KB | Output is correct |
14 | Correct | 42 ms | 94380 KB | Output is correct |
15 | Correct | 43 ms | 94288 KB | Output is correct |
16 | Correct | 42 ms | 94288 KB | Output is correct |
17 | Correct | 48 ms | 94288 KB | Output is correct |
18 | Correct | 43 ms | 94288 KB | Output is correct |
19 | Correct | 40 ms | 94288 KB | Output is correct |
20 | Correct | 37 ms | 94160 KB | Output is correct |
21 | Correct | 37 ms | 94300 KB | Output is correct |
22 | Correct | 37 ms | 94348 KB | Output is correct |
23 | Correct | 37 ms | 94300 KB | Output is correct |
24 | Correct | 37 ms | 94216 KB | Output is correct |
25 | Correct | 37 ms | 94296 KB | Output is correct |
26 | Correct | 38 ms | 94292 KB | Output is correct |
27 | Correct | 37 ms | 94288 KB | Output is correct |
28 | Correct | 37 ms | 94288 KB | Output is correct |
29 | Correct | 37 ms | 94292 KB | Output is correct |
30 | Correct | 36 ms | 94292 KB | Output is correct |
31 | Correct | 42 ms | 94372 KB | Output is correct |
32 | Correct | 38 ms | 94288 KB | Output is correct |
33 | Correct | 37 ms | 94228 KB | Output is correct |
34 | Correct | 37 ms | 94344 KB | Output is correct |
35 | Correct | 38 ms | 94300 KB | Output is correct |
36 | Correct | 42 ms | 94288 KB | Output is correct |
37 | Correct | 43 ms | 94288 KB | Output is correct |
38 | Correct | 43 ms | 94348 KB | Output is correct |
39 | Correct | 41 ms | 94292 KB | Output is correct |
40 | Correct | 41 ms | 94292 KB | Output is correct |
41 | Correct | 43 ms | 94288 KB | Output is correct |
42 | Correct | 42 ms | 94292 KB | Output is correct |
43 | Correct | 42 ms | 94292 KB | Output is correct |
44 | Correct | 43 ms | 94288 KB | Output is correct |
45 | Correct | 42 ms | 94288 KB | Output is correct |
46 | Correct | 44 ms | 94300 KB | Output is correct |
47 | Correct | 43 ms | 94292 KB | Output is correct |
48 | Correct | 44 ms | 94300 KB | Output is correct |
49 | Correct | 42 ms | 94268 KB | Output is correct |
50 | Correct | 43 ms | 94288 KB | Output is correct |
51 | Correct | 43 ms | 94288 KB | Output is correct |
52 | Correct | 44 ms | 94292 KB | Output is correct |
53 | Correct | 40 ms | 94196 KB | Output is correct |
54 | Correct | 43 ms | 94292 KB | Output is correct |
55 | Correct | 44 ms | 94288 KB | Output is correct |
56 | Correct | 43 ms | 94208 KB | Output is correct |
57 | Correct | 43 ms | 94292 KB | Output is correct |
58 | Correct | 43 ms | 94292 KB | Output is correct |
59 | Correct | 38 ms | 94288 KB | Output is correct |
60 | Correct | 37 ms | 94292 KB | Output is correct |
61 | Correct | 37 ms | 94288 KB | Output is correct |
62 | Correct | 37 ms | 94444 KB | Output is correct |
63 | Correct | 37 ms | 94300 KB | Output is correct |
64 | Correct | 39 ms | 94260 KB | Output is correct |
65 | Correct | 37 ms | 94288 KB | Output is correct |
66 | Correct | 37 ms | 94300 KB | Output is correct |
67 | Correct | 38 ms | 94288 KB | Output is correct |
68 | Correct | 37 ms | 94288 KB | Output is correct |
69 | Correct | 37 ms | 94316 KB | Output is correct |
70 | Correct | 37 ms | 94300 KB | Output is correct |
71 | Correct | 37 ms | 94332 KB | Output is correct |
72 | Correct | 38 ms | 94292 KB | Output is correct |
73 | Correct | 37 ms | 94300 KB | Output is correct |
74 | Correct | 38 ms | 94288 KB | Output is correct |
75 | Correct | 37 ms | 94288 KB | Output is correct |
76 | Correct | 36 ms | 94404 KB | Output is correct |
77 | Correct | 40 ms | 94272 KB | Output is correct |
78 | Correct | 38 ms | 94296 KB | Output is correct |
79 | Correct | 36 ms | 94292 KB | Output is correct |
80 | Correct | 38 ms | 94420 KB | Output is correct |
81 | Correct | 41 ms | 94492 KB | Output is correct |
82 | Correct | 39 ms | 94300 KB | Output is correct |
83 | Correct | 42 ms | 94292 KB | Output is correct |
84 | Correct | 43 ms | 94384 KB | Output is correct |
85 | Correct | 43 ms | 94308 KB | Output is correct |
86 | Correct | 42 ms | 94288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 94288 KB | Output is correct |
2 | Correct | 43 ms | 94292 KB | Output is correct |
3 | Correct | 42 ms | 94292 KB | Output is correct |
4 | Correct | 43 ms | 94292 KB | Output is correct |
5 | Correct | 41 ms | 94292 KB | Output is correct |
6 | Correct | 42 ms | 94292 KB | Output is correct |
7 | Correct | 41 ms | 94400 KB | Output is correct |
8 | Correct | 44 ms | 94288 KB | Output is correct |
9 | Correct | 39 ms | 94300 KB | Output is correct |
10 | Correct | 48 ms | 94292 KB | Output is correct |
11 | Correct | 42 ms | 94296 KB | Output is correct |
12 | Correct | 42 ms | 94288 KB | Output is correct |
13 | Correct | 42 ms | 94292 KB | Output is correct |
14 | Correct | 42 ms | 94380 KB | Output is correct |
15 | Correct | 43 ms | 94288 KB | Output is correct |
16 | Correct | 42 ms | 94288 KB | Output is correct |
17 | Correct | 48 ms | 94288 KB | Output is correct |
18 | Correct | 43 ms | 94288 KB | Output is correct |
19 | Correct | 40 ms | 94288 KB | Output is correct |
20 | Correct | 37 ms | 94160 KB | Output is correct |
21 | Correct | 37 ms | 94300 KB | Output is correct |
22 | Correct | 37 ms | 94348 KB | Output is correct |
23 | Correct | 37 ms | 94300 KB | Output is correct |
24 | Correct | 37 ms | 94216 KB | Output is correct |
25 | Correct | 37 ms | 94296 KB | Output is correct |
26 | Correct | 38 ms | 94292 KB | Output is correct |
27 | Correct | 37 ms | 94288 KB | Output is correct |
28 | Correct | 37 ms | 94288 KB | Output is correct |
29 | Correct | 37 ms | 94292 KB | Output is correct |
30 | Correct | 36 ms | 94292 KB | Output is correct |
31 | Correct | 42 ms | 94372 KB | Output is correct |
32 | Correct | 38 ms | 94288 KB | Output is correct |
33 | Correct | 37 ms | 94228 KB | Output is correct |
34 | Correct | 37 ms | 94344 KB | Output is correct |
35 | Correct | 38 ms | 94300 KB | Output is correct |
36 | Correct | 42 ms | 94288 KB | Output is correct |
37 | Correct | 43 ms | 94288 KB | Output is correct |
38 | Correct | 43 ms | 94348 KB | Output is correct |
39 | Correct | 41 ms | 94292 KB | Output is correct |
40 | Correct | 41 ms | 94292 KB | Output is correct |
41 | Correct | 43 ms | 94288 KB | Output is correct |
42 | Correct | 42 ms | 94292 KB | Output is correct |
43 | Correct | 42 ms | 94292 KB | Output is correct |
44 | Correct | 43 ms | 94288 KB | Output is correct |
45 | Correct | 42 ms | 94288 KB | Output is correct |
46 | Correct | 44 ms | 94300 KB | Output is correct |
47 | Correct | 43 ms | 94292 KB | Output is correct |
48 | Correct | 44 ms | 94300 KB | Output is correct |
49 | Correct | 42 ms | 94268 KB | Output is correct |
50 | Correct | 43 ms | 94288 KB | Output is correct |
51 | Correct | 43 ms | 94288 KB | Output is correct |
52 | Correct | 44 ms | 94292 KB | Output is correct |
53 | Correct | 40 ms | 94196 KB | Output is correct |
54 | Correct | 43 ms | 94292 KB | Output is correct |
55 | Correct | 44 ms | 94288 KB | Output is correct |
56 | Correct | 43 ms | 94208 KB | Output is correct |
57 | Correct | 205 ms | 214216 KB | Output is correct |
58 | Correct | 201 ms | 214220 KB | Output is correct |
59 | Correct | 210 ms | 214220 KB | Output is correct |
60 | Correct | 211 ms | 214292 KB | Output is correct |
61 | Correct | 207 ms | 214312 KB | Output is correct |
62 | Correct | 206 ms | 214216 KB | Output is correct |
63 | Correct | 197 ms | 214188 KB | Output is correct |
64 | Correct | 197 ms | 214216 KB | Output is correct |
65 | Correct | 205 ms | 214220 KB | Output is correct |
66 | Correct | 200 ms | 214472 KB | Output is correct |
67 | Correct | 202 ms | 214220 KB | Output is correct |
68 | Correct | 206 ms | 214216 KB | Output is correct |
69 | Correct | 43 ms | 94300 KB | Output is correct |
70 | Correct | 43 ms | 94292 KB | Output is correct |
71 | Correct | 43 ms | 94292 KB | Output is correct |
72 | Correct | 38 ms | 94288 KB | Output is correct |
73 | Correct | 37 ms | 94292 KB | Output is correct |
74 | Correct | 37 ms | 94288 KB | Output is correct |
75 | Correct | 37 ms | 94444 KB | Output is correct |
76 | Correct | 37 ms | 94300 KB | Output is correct |
77 | Correct | 39 ms | 94260 KB | Output is correct |
78 | Correct | 37 ms | 94288 KB | Output is correct |
79 | Correct | 37 ms | 94300 KB | Output is correct |
80 | Correct | 38 ms | 94288 KB | Output is correct |
81 | Correct | 37 ms | 94288 KB | Output is correct |
82 | Correct | 37 ms | 94316 KB | Output is correct |
83 | Correct | 37 ms | 94300 KB | Output is correct |
84 | Correct | 37 ms | 94332 KB | Output is correct |
85 | Correct | 38 ms | 94292 KB | Output is correct |
86 | Correct | 37 ms | 94300 KB | Output is correct |
87 | Correct | 38 ms | 94288 KB | Output is correct |
88 | Correct | 37 ms | 94288 KB | Output is correct |
89 | Correct | 36 ms | 94404 KB | Output is correct |
90 | Correct | 40 ms | 94272 KB | Output is correct |
91 | Correct | 38 ms | 94296 KB | Output is correct |
92 | Correct | 36 ms | 94292 KB | Output is correct |
93 | Correct | 38 ms | 94420 KB | Output is correct |
94 | Correct | 41 ms | 94492 KB | Output is correct |
95 | Correct | 39 ms | 94300 KB | Output is correct |
96 | Correct | 42 ms | 94292 KB | Output is correct |
97 | Correct | 43 ms | 94384 KB | Output is correct |
98 | Correct | 43 ms | 94308 KB | Output is correct |
99 | Correct | 42 ms | 94288 KB | Output is correct |
100 | Correct | 174 ms | 163392 KB | Output is correct |
101 | Correct | 173 ms | 163352 KB | Output is correct |
102 | Correct | 164 ms | 163224 KB | Output is correct |
103 | Correct | 157 ms | 163312 KB | Output is correct |
104 | Correct | 158 ms | 163276 KB | Output is correct |
105 | Correct | 186 ms | 179108 KB | Output is correct |
106 | Correct | 186 ms | 178976 KB | Output is correct |
107 | Correct | 191 ms | 179152 KB | Output is correct |
108 | Correct | 176 ms | 179048 KB | Output is correct |
109 | Correct | 178 ms | 178956 KB | Output is correct |
110 | Correct | 187 ms | 163176 KB | Output is correct |
111 | Correct | 173 ms | 163376 KB | Output is correct |
112 | Correct | 165 ms | 163340 KB | Output is correct |
113 | Correct | 169 ms | 163212 KB | Output is correct |
114 | Correct | 163 ms | 163272 KB | Output is correct |
115 | Correct | 206 ms | 214340 KB | Output is correct |
116 | Correct | 205 ms | 214348 KB | Output is correct |
117 | Correct | 199 ms | 214320 KB | Output is correct |
118 | Correct | 220 ms | 214216 KB | Output is correct |
119 | Correct | 192 ms | 214288 KB | Output is correct |
120 | Correct | 159 ms | 163388 KB | Output is correct |
121 | Correct | 162 ms | 163352 KB | Output is correct |
122 | Correct | 176 ms | 163616 KB | Output is correct |
123 | Correct | 189 ms | 163344 KB | Output is correct |
124 | Correct | 153 ms | 188688 KB | Output is correct |
125 | Correct | 160 ms | 188876 KB | Output is correct |
126 | Correct | 154 ms | 188724 KB | Output is correct |
127 | Correct | 150 ms | 188700 KB | Output is correct |
128 | Correct | 93 ms | 130360 KB | Output is correct |
129 | Correct | 87 ms | 130580 KB | Output is correct |
130 | Correct | 87 ms | 130364 KB | Output is correct |
131 | Correct | 39 ms | 94260 KB | Output is correct |