# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
865537 | 2023-10-24T09:36:14 Z | mychecksedad | Homework (CEOI22_homework) | C++17 | 173 ms | 205152 KB |
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 3e6+100, M = 1e5+10, K = 52, MX = 30; vector<int> g[N]; vector<int> tp; int sz[N]; pair<int, int> dfs(int v){ sz[v] = tp[v] == 2; if(tp[v] == 2) return {1, 1}; pair<int, int> x = dfs(g[v][0]); pair<int, int> y = dfs(g[v][1]); // cout << g[v][0] << ": " << x.first << ' ' << x.second << '|' << g[v][1] << ": " << y.first << ' ' << y.second << '\n'; sz[v] += sz[g[v][0]]; sz[v] += sz[g[v][1]]; if(tp[v] == 0) return {min(x.first, y.first), x.second + y.second - 1}; return {x.first + y.first, max(sz[g[v][0]] + y.second, x.second + sz[g[v][1]])}; } string s; void solve(){ cin >> s; int n = 0, mx = 0, mn = 0; int cur = 1; tp.resize(s.size()+2); vector<int> last; for(int i = 0 ; i < s.length(); ++i){ if(s[i] == '?'){ tp[cur] = 2; if(!last.empty()){ g[last.back()].pb(cur); } ++cur; }else if(s[i] == '('){ if(!last.empty()){ g[last.back()].pb(cur); } if(s[i - 1] == 'n') tp[cur] = 0; else if(s[i - 1] == 'x') tp[cur] = 1; last.pb(cur); ++cur; }else if(s[i] == ')'){ last.pop_back(); } } auto R = dfs(1); cout << R.second-R.first+1; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin >> tt; while(tt--){ solve(); // en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 72028 KB | Output is correct |
2 | Correct | 16 ms | 72028 KB | Output is correct |
3 | Correct | 16 ms | 72124 KB | Output is correct |
4 | Correct | 15 ms | 71996 KB | Output is correct |
5 | Correct | 15 ms | 72172 KB | Output is correct |
6 | Correct | 15 ms | 72028 KB | Output is correct |
7 | Correct | 16 ms | 72028 KB | Output is correct |
8 | Correct | 16 ms | 72116 KB | Output is correct |
9 | Correct | 15 ms | 72028 KB | Output is correct |
10 | Correct | 16 ms | 72024 KB | Output is correct |
11 | Correct | 16 ms | 72024 KB | Output is correct |
12 | Correct | 16 ms | 72028 KB | Output is correct |
13 | Correct | 16 ms | 72132 KB | Output is correct |
14 | Correct | 15 ms | 72028 KB | Output is correct |
15 | Correct | 16 ms | 72028 KB | Output is correct |
16 | Correct | 15 ms | 72028 KB | Output is correct |
17 | Correct | 15 ms | 72028 KB | Output is correct |
18 | Correct | 15 ms | 72400 KB | Output is correct |
19 | Correct | 16 ms | 72028 KB | Output is correct |
20 | Correct | 17 ms | 72028 KB | Output is correct |
21 | Correct | 16 ms | 72028 KB | Output is correct |
22 | Correct | 17 ms | 72028 KB | Output is correct |
23 | Correct | 16 ms | 71980 KB | Output is correct |
24 | Correct | 16 ms | 72028 KB | Output is correct |
25 | Correct | 16 ms | 72028 KB | Output is correct |
26 | Correct | 15 ms | 72028 KB | Output is correct |
27 | Correct | 16 ms | 72028 KB | Output is correct |
28 | Correct | 16 ms | 72116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 72028 KB | Output is correct |
2 | Correct | 16 ms | 72028 KB | Output is correct |
3 | Correct | 16 ms | 72124 KB | Output is correct |
4 | Correct | 15 ms | 71996 KB | Output is correct |
5 | Correct | 15 ms | 72172 KB | Output is correct |
6 | Correct | 15 ms | 72028 KB | Output is correct |
7 | Correct | 16 ms | 72028 KB | Output is correct |
8 | Correct | 16 ms | 72116 KB | Output is correct |
9 | Correct | 15 ms | 72028 KB | Output is correct |
10 | Correct | 16 ms | 72024 KB | Output is correct |
11 | Correct | 16 ms | 72024 KB | Output is correct |
12 | Correct | 16 ms | 72028 KB | Output is correct |
13 | Correct | 16 ms | 72132 KB | Output is correct |
14 | Correct | 15 ms | 72028 KB | Output is correct |
15 | Correct | 16 ms | 72028 KB | Output is correct |
16 | Correct | 15 ms | 72028 KB | Output is correct |
17 | Correct | 15 ms | 72028 KB | Output is correct |
18 | Correct | 15 ms | 72400 KB | Output is correct |
19 | Correct | 16 ms | 72028 KB | Output is correct |
20 | Correct | 17 ms | 72028 KB | Output is correct |
21 | Correct | 16 ms | 72028 KB | Output is correct |
22 | Correct | 17 ms | 72028 KB | Output is correct |
23 | Correct | 16 ms | 71980 KB | Output is correct |
24 | Correct | 16 ms | 72028 KB | Output is correct |
25 | Correct | 16 ms | 72028 KB | Output is correct |
26 | Correct | 15 ms | 72028 KB | Output is correct |
27 | Correct | 16 ms | 72028 KB | Output is correct |
28 | Correct | 16 ms | 72116 KB | Output is correct |
29 | Correct | 15 ms | 72028 KB | Output is correct |
30 | Correct | 15 ms | 72024 KB | Output is correct |
31 | Correct | 16 ms | 72028 KB | Output is correct |
32 | Correct | 16 ms | 72028 KB | Output is correct |
33 | Correct | 15 ms | 72128 KB | Output is correct |
34 | Correct | 16 ms | 72028 KB | Output is correct |
35 | Correct | 15 ms | 72028 KB | Output is correct |
36 | Correct | 16 ms | 72284 KB | Output is correct |
37 | Correct | 16 ms | 71984 KB | Output is correct |
38 | Correct | 15 ms | 72028 KB | Output is correct |
39 | Correct | 16 ms | 72024 KB | Output is correct |
40 | Correct | 16 ms | 72028 KB | Output is correct |
41 | Correct | 15 ms | 72024 KB | Output is correct |
42 | Correct | 16 ms | 72028 KB | Output is correct |
43 | Correct | 15 ms | 72028 KB | Output is correct |
44 | Correct | 15 ms | 72024 KB | Output is correct |
45 | Correct | 16 ms | 72028 KB | Output is correct |
46 | Correct | 15 ms | 72028 KB | Output is correct |
47 | Correct | 16 ms | 72028 KB | Output is correct |
48 | Correct | 16 ms | 72028 KB | Output is correct |
49 | Correct | 16 ms | 72220 KB | Output is correct |
50 | Correct | 16 ms | 72024 KB | Output is correct |
51 | Correct | 15 ms | 72188 KB | Output is correct |
52 | Correct | 16 ms | 72004 KB | Output is correct |
53 | Correct | 16 ms | 72024 KB | Output is correct |
54 | Correct | 16 ms | 72028 KB | Output is correct |
55 | Correct | 15 ms | 72024 KB | Output is correct |
56 | Correct | 15 ms | 72028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 166 ms | 196812 KB | Output is correct |
2 | Correct | 167 ms | 201160 KB | Output is correct |
3 | Correct | 173 ms | 200656 KB | Output is correct |
4 | Correct | 172 ms | 203852 KB | Output is correct |
5 | Correct | 171 ms | 203700 KB | Output is correct |
6 | Correct | 165 ms | 203984 KB | Output is correct |
7 | Correct | 165 ms | 204240 KB | Output is correct |
8 | Correct | 164 ms | 203660 KB | Output is correct |
9 | Correct | 163 ms | 203980 KB | Output is correct |
10 | Correct | 160 ms | 205008 KB | Output is correct |
11 | Correct | 164 ms | 204580 KB | Output is correct |
12 | Correct | 162 ms | 204228 KB | Output is correct |
13 | Correct | 15 ms | 72028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 72028 KB | Output is correct |
2 | Correct | 16 ms | 72028 KB | Output is correct |
3 | Correct | 16 ms | 72124 KB | Output is correct |
4 | Correct | 15 ms | 71996 KB | Output is correct |
5 | Correct | 15 ms | 72172 KB | Output is correct |
6 | Correct | 15 ms | 72028 KB | Output is correct |
7 | Correct | 16 ms | 72028 KB | Output is correct |
8 | Correct | 16 ms | 72116 KB | Output is correct |
9 | Correct | 15 ms | 72028 KB | Output is correct |
10 | Correct | 16 ms | 72024 KB | Output is correct |
11 | Correct | 16 ms | 72024 KB | Output is correct |
12 | Correct | 16 ms | 72028 KB | Output is correct |
13 | Correct | 16 ms | 72132 KB | Output is correct |
14 | Correct | 15 ms | 72028 KB | Output is correct |
15 | Correct | 16 ms | 72028 KB | Output is correct |
16 | Correct | 15 ms | 72028 KB | Output is correct |
17 | Correct | 15 ms | 72028 KB | Output is correct |
18 | Correct | 15 ms | 72400 KB | Output is correct |
19 | Correct | 16 ms | 72028 KB | Output is correct |
20 | Correct | 17 ms | 72028 KB | Output is correct |
21 | Correct | 16 ms | 72028 KB | Output is correct |
22 | Correct | 17 ms | 72028 KB | Output is correct |
23 | Correct | 16 ms | 71980 KB | Output is correct |
24 | Correct | 16 ms | 72028 KB | Output is correct |
25 | Correct | 16 ms | 72028 KB | Output is correct |
26 | Correct | 15 ms | 72028 KB | Output is correct |
27 | Correct | 16 ms | 72028 KB | Output is correct |
28 | Correct | 16 ms | 72116 KB | Output is correct |
29 | Correct | 15 ms | 72028 KB | Output is correct |
30 | Correct | 15 ms | 72024 KB | Output is correct |
31 | Correct | 16 ms | 72028 KB | Output is correct |
32 | Correct | 16 ms | 72028 KB | Output is correct |
33 | Correct | 15 ms | 72128 KB | Output is correct |
34 | Correct | 16 ms | 72028 KB | Output is correct |
35 | Correct | 15 ms | 72028 KB | Output is correct |
36 | Correct | 16 ms | 72284 KB | Output is correct |
37 | Correct | 16 ms | 71984 KB | Output is correct |
38 | Correct | 15 ms | 72028 KB | Output is correct |
39 | Correct | 16 ms | 72024 KB | Output is correct |
40 | Correct | 16 ms | 72028 KB | Output is correct |
41 | Correct | 15 ms | 72024 KB | Output is correct |
42 | Correct | 16 ms | 72028 KB | Output is correct |
43 | Correct | 15 ms | 72028 KB | Output is correct |
44 | Correct | 15 ms | 72024 KB | Output is correct |
45 | Correct | 16 ms | 72028 KB | Output is correct |
46 | Correct | 15 ms | 72028 KB | Output is correct |
47 | Correct | 16 ms | 72028 KB | Output is correct |
48 | Correct | 16 ms | 72028 KB | Output is correct |
49 | Correct | 16 ms | 72220 KB | Output is correct |
50 | Correct | 16 ms | 72024 KB | Output is correct |
51 | Correct | 15 ms | 72188 KB | Output is correct |
52 | Correct | 16 ms | 72004 KB | Output is correct |
53 | Correct | 16 ms | 72024 KB | Output is correct |
54 | Correct | 16 ms | 72028 KB | Output is correct |
55 | Correct | 15 ms | 72024 KB | Output is correct |
56 | Correct | 15 ms | 72028 KB | Output is correct |
57 | Correct | 15 ms | 72280 KB | Output is correct |
58 | Correct | 15 ms | 72284 KB | Output is correct |
59 | Correct | 16 ms | 72128 KB | Output is correct |
60 | Correct | 16 ms | 72284 KB | Output is correct |
61 | Correct | 15 ms | 72244 KB | Output is correct |
62 | Correct | 15 ms | 72284 KB | Output is correct |
63 | Correct | 16 ms | 72284 KB | Output is correct |
64 | Correct | 16 ms | 72284 KB | Output is correct |
65 | Correct | 16 ms | 72308 KB | Output is correct |
66 | Correct | 15 ms | 72280 KB | Output is correct |
67 | Correct | 15 ms | 72280 KB | Output is correct |
68 | Correct | 15 ms | 72284 KB | Output is correct |
69 | Correct | 15 ms | 72284 KB | Output is correct |
70 | Correct | 15 ms | 72184 KB | Output is correct |
71 | Correct | 15 ms | 72228 KB | Output is correct |
72 | Correct | 15 ms | 72284 KB | Output is correct |
73 | Correct | 15 ms | 72164 KB | Output is correct |
74 | Correct | 15 ms | 72284 KB | Output is correct |
75 | Correct | 16 ms | 72284 KB | Output is correct |
76 | Correct | 16 ms | 72248 KB | Output is correct |
77 | Correct | 15 ms | 72220 KB | Output is correct |
78 | Correct | 15 ms | 72244 KB | Output is correct |
79 | Correct | 15 ms | 72284 KB | Output is correct |
80 | Correct | 15 ms | 72284 KB | Output is correct |
81 | Correct | 15 ms | 72280 KB | Output is correct |
82 | Correct | 15 ms | 72284 KB | Output is correct |
83 | Correct | 15 ms | 72028 KB | Output is correct |
84 | Correct | 15 ms | 72028 KB | Output is correct |
85 | Correct | 15 ms | 72024 KB | Output is correct |
86 | Correct | 16 ms | 72148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 72028 KB | Output is correct |
2 | Correct | 16 ms | 72028 KB | Output is correct |
3 | Correct | 16 ms | 72124 KB | Output is correct |
4 | Correct | 15 ms | 71996 KB | Output is correct |
5 | Correct | 15 ms | 72172 KB | Output is correct |
6 | Correct | 15 ms | 72028 KB | Output is correct |
7 | Correct | 16 ms | 72028 KB | Output is correct |
8 | Correct | 16 ms | 72116 KB | Output is correct |
9 | Correct | 15 ms | 72028 KB | Output is correct |
10 | Correct | 16 ms | 72024 KB | Output is correct |
11 | Correct | 16 ms | 72024 KB | Output is correct |
12 | Correct | 16 ms | 72028 KB | Output is correct |
13 | Correct | 16 ms | 72132 KB | Output is correct |
14 | Correct | 15 ms | 72028 KB | Output is correct |
15 | Correct | 16 ms | 72028 KB | Output is correct |
16 | Correct | 15 ms | 72028 KB | Output is correct |
17 | Correct | 15 ms | 72028 KB | Output is correct |
18 | Correct | 15 ms | 72400 KB | Output is correct |
19 | Correct | 16 ms | 72028 KB | Output is correct |
20 | Correct | 17 ms | 72028 KB | Output is correct |
21 | Correct | 16 ms | 72028 KB | Output is correct |
22 | Correct | 17 ms | 72028 KB | Output is correct |
23 | Correct | 16 ms | 71980 KB | Output is correct |
24 | Correct | 16 ms | 72028 KB | Output is correct |
25 | Correct | 16 ms | 72028 KB | Output is correct |
26 | Correct | 15 ms | 72028 KB | Output is correct |
27 | Correct | 16 ms | 72028 KB | Output is correct |
28 | Correct | 16 ms | 72116 KB | Output is correct |
29 | Correct | 15 ms | 72028 KB | Output is correct |
30 | Correct | 15 ms | 72024 KB | Output is correct |
31 | Correct | 16 ms | 72028 KB | Output is correct |
32 | Correct | 16 ms | 72028 KB | Output is correct |
33 | Correct | 15 ms | 72128 KB | Output is correct |
34 | Correct | 16 ms | 72028 KB | Output is correct |
35 | Correct | 15 ms | 72028 KB | Output is correct |
36 | Correct | 16 ms | 72284 KB | Output is correct |
37 | Correct | 16 ms | 71984 KB | Output is correct |
38 | Correct | 15 ms | 72028 KB | Output is correct |
39 | Correct | 16 ms | 72024 KB | Output is correct |
40 | Correct | 16 ms | 72028 KB | Output is correct |
41 | Correct | 15 ms | 72024 KB | Output is correct |
42 | Correct | 16 ms | 72028 KB | Output is correct |
43 | Correct | 15 ms | 72028 KB | Output is correct |
44 | Correct | 15 ms | 72024 KB | Output is correct |
45 | Correct | 16 ms | 72028 KB | Output is correct |
46 | Correct | 15 ms | 72028 KB | Output is correct |
47 | Correct | 16 ms | 72028 KB | Output is correct |
48 | Correct | 16 ms | 72028 KB | Output is correct |
49 | Correct | 16 ms | 72220 KB | Output is correct |
50 | Correct | 16 ms | 72024 KB | Output is correct |
51 | Correct | 15 ms | 72188 KB | Output is correct |
52 | Correct | 16 ms | 72004 KB | Output is correct |
53 | Correct | 16 ms | 72024 KB | Output is correct |
54 | Correct | 16 ms | 72028 KB | Output is correct |
55 | Correct | 15 ms | 72024 KB | Output is correct |
56 | Correct | 15 ms | 72028 KB | Output is correct |
57 | Correct | 166 ms | 196812 KB | Output is correct |
58 | Correct | 167 ms | 201160 KB | Output is correct |
59 | Correct | 173 ms | 200656 KB | Output is correct |
60 | Correct | 172 ms | 203852 KB | Output is correct |
61 | Correct | 171 ms | 203700 KB | Output is correct |
62 | Correct | 165 ms | 203984 KB | Output is correct |
63 | Correct | 165 ms | 204240 KB | Output is correct |
64 | Correct | 164 ms | 203660 KB | Output is correct |
65 | Correct | 163 ms | 203980 KB | Output is correct |
66 | Correct | 160 ms | 205008 KB | Output is correct |
67 | Correct | 164 ms | 204580 KB | Output is correct |
68 | Correct | 162 ms | 204228 KB | Output is correct |
69 | Correct | 15 ms | 72028 KB | Output is correct |
70 | Correct | 15 ms | 72280 KB | Output is correct |
71 | Correct | 15 ms | 72284 KB | Output is correct |
72 | Correct | 16 ms | 72128 KB | Output is correct |
73 | Correct | 16 ms | 72284 KB | Output is correct |
74 | Correct | 15 ms | 72244 KB | Output is correct |
75 | Correct | 15 ms | 72284 KB | Output is correct |
76 | Correct | 16 ms | 72284 KB | Output is correct |
77 | Correct | 16 ms | 72284 KB | Output is correct |
78 | Correct | 16 ms | 72308 KB | Output is correct |
79 | Correct | 15 ms | 72280 KB | Output is correct |
80 | Correct | 15 ms | 72280 KB | Output is correct |
81 | Correct | 15 ms | 72284 KB | Output is correct |
82 | Correct | 15 ms | 72284 KB | Output is correct |
83 | Correct | 15 ms | 72184 KB | Output is correct |
84 | Correct | 15 ms | 72228 KB | Output is correct |
85 | Correct | 15 ms | 72284 KB | Output is correct |
86 | Correct | 15 ms | 72164 KB | Output is correct |
87 | Correct | 15 ms | 72284 KB | Output is correct |
88 | Correct | 16 ms | 72284 KB | Output is correct |
89 | Correct | 16 ms | 72248 KB | Output is correct |
90 | Correct | 15 ms | 72220 KB | Output is correct |
91 | Correct | 15 ms | 72244 KB | Output is correct |
92 | Correct | 15 ms | 72284 KB | Output is correct |
93 | Correct | 15 ms | 72284 KB | Output is correct |
94 | Correct | 15 ms | 72280 KB | Output is correct |
95 | Correct | 15 ms | 72284 KB | Output is correct |
96 | Correct | 15 ms | 72028 KB | Output is correct |
97 | Correct | 15 ms | 72028 KB | Output is correct |
98 | Correct | 15 ms | 72024 KB | Output is correct |
99 | Correct | 16 ms | 72148 KB | Output is correct |
100 | Correct | 137 ms | 153612 KB | Output is correct |
101 | Correct | 137 ms | 153756 KB | Output is correct |
102 | Correct | 131 ms | 152784 KB | Output is correct |
103 | Correct | 137 ms | 153348 KB | Output is correct |
104 | Correct | 128 ms | 152800 KB | Output is correct |
105 | Correct | 153 ms | 169848 KB | Output is correct |
106 | Correct | 157 ms | 170452 KB | Output is correct |
107 | Correct | 147 ms | 170760 KB | Output is correct |
108 | Correct | 145 ms | 170884 KB | Output is correct |
109 | Correct | 146 ms | 169936 KB | Output is correct |
110 | Correct | 143 ms | 154280 KB | Output is correct |
111 | Correct | 141 ms | 152956 KB | Output is correct |
112 | Correct | 135 ms | 152948 KB | Output is correct |
113 | Correct | 139 ms | 153160 KB | Output is correct |
114 | Correct | 135 ms | 152764 KB | Output is correct |
115 | Correct | 171 ms | 205008 KB | Output is correct |
116 | Correct | 170 ms | 204284 KB | Output is correct |
117 | Correct | 164 ms | 204236 KB | Output is correct |
118 | Correct | 162 ms | 203652 KB | Output is correct |
119 | Correct | 161 ms | 205152 KB | Output is correct |
120 | Correct | 131 ms | 152784 KB | Output is correct |
121 | Correct | 132 ms | 152784 KB | Output is correct |
122 | Correct | 141 ms | 153292 KB | Output is correct |
123 | Correct | 141 ms | 153292 KB | Output is correct |
124 | Correct | 136 ms | 179664 KB | Output is correct |
125 | Correct | 140 ms | 178752 KB | Output is correct |
126 | Correct | 136 ms | 179152 KB | Output is correct |
127 | Correct | 140 ms | 178356 KB | Output is correct |
128 | Correct | 72 ms | 114384 KB | Output is correct |
129 | Correct | 77 ms | 114384 KB | Output is correct |
130 | Correct | 67 ms | 114384 KB | Output is correct |
131 | Correct | 15 ms | 72028 KB | Output is correct |