답안 #803041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
803041 2023-08-02T20:04:33 Z ezdp Homework (CEOI22_homework) C++14
100 / 100
225 ms 174840 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define lsb(idx) idx&(-idx)
#define bin(x) bitset<32>(x).to_string()
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;

using namespace std;
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using matrix = vector<vector<T>>;
// find_by_order(x) -> x-th element in the set
// order_of_key(x)  -> how many elements are less than x
// insert(x)		 -> inserts x into the set

const int MAXN = 2e7;

int T = 1, type[MAXN + 5];
tuple<int, int, int> interval[MAXN + 5];
matrix<int> G;

void dfs(int u = 1){
	if(type[u] == 'l'){
		interval[u] = {1, 1, 1};
		return;
	}
	for(auto v : G[u])
		dfs(v);
	auto [l1, r1, s1] = interval[G[u][0]];
	auto [l2, r2, s2] = interval[G[u][1]];
	if(type[u] == 'n'){
		interval[u] = {min(l1, l2), r1 + r2 - 1, s1 + s2};
		return;
	}
	if(type[u] == 'x'){
		interval[u] = {l1 + l2, max(r1 + s2, s1 + r2), s1 + s2};
		return;
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	// freopen("filename.in" , "r", stdin); 
	// freopen("filename.out", "w", stdout);
	string t; cin >> t;
	stack<int> st;
	G.resize(1);
	for(int i = 0; i < t.size(); i ++){
		if(t[i] == '(' || t[i] == '?'){
			G.pb(vector<int>());
			type[T] = (t[i] == '(' ? t[i - 1] : 'l');
			if(!st.empty()){
				G[st.top()].pb(T);
			}
			if(t[i] == '(')
				st.push(T);
			++ T;
		}
		if(t[i] == ')'){
			st.pop();
		}
	}
	dfs();
	cout << get<1>(interval[1]) - get<0>(interval[1]) + 1 << endl;
}
/**

*/

Compilation message

Main.cpp: In function 'void dfs(int)':
Main.cpp:37:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |  auto [l1, r1, s1] = interval[G[u][0]];
      |       ^
Main.cpp:38:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |  auto [l2, r2, s2] = interval[G[u][1]];
      |       ^
Main.cpp: In function 'int main()':
Main.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(int i = 0; i < t.size(); i ++){
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 224 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 167812 KB Output is correct
2 Correct 197 ms 174656 KB Output is correct
3 Correct 205 ms 174564 KB Output is correct
4 Correct 206 ms 174576 KB Output is correct
5 Correct 196 ms 174556 KB Output is correct
6 Correct 202 ms 174656 KB Output is correct
7 Correct 205 ms 174640 KB Output is correct
8 Correct 195 ms 174564 KB Output is correct
9 Correct 200 ms 174840 KB Output is correct
10 Correct 197 ms 174676 KB Output is correct
11 Correct 225 ms 174644 KB Output is correct
12 Correct 202 ms 174744 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 224 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 448 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 0 ms 468 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 0 ms 468 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 0 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 468 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 1 ms 372 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 224 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 197 ms 167812 KB Output is correct
58 Correct 197 ms 174656 KB Output is correct
59 Correct 205 ms 174564 KB Output is correct
60 Correct 206 ms 174576 KB Output is correct
61 Correct 196 ms 174556 KB Output is correct
62 Correct 202 ms 174656 KB Output is correct
63 Correct 205 ms 174640 KB Output is correct
64 Correct 195 ms 174564 KB Output is correct
65 Correct 200 ms 174840 KB Output is correct
66 Correct 197 ms 174676 KB Output is correct
67 Correct 225 ms 174644 KB Output is correct
68 Correct 202 ms 174744 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 468 KB Output is correct
78 Correct 1 ms 448 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 0 ms 468 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 0 ms 468 KB Output is correct
84 Correct 1 ms 468 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 0 ms 468 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 468 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 0 ms 468 KB Output is correct
93 Correct 1 ms 468 KB Output is correct
94 Correct 1 ms 468 KB Output is correct
95 Correct 1 ms 372 KB Output is correct
96 Correct 0 ms 340 KB Output is correct
97 Correct 0 ms 340 KB Output is correct
98 Correct 0 ms 340 KB Output is correct
99 Correct 0 ms 212 KB Output is correct
100 Correct 171 ms 123576 KB Output is correct
101 Correct 167 ms 123564 KB Output is correct
102 Correct 160 ms 123520 KB Output is correct
103 Correct 168 ms 123544 KB Output is correct
104 Correct 162 ms 123620 KB Output is correct
105 Correct 185 ms 139264 KB Output is correct
106 Correct 182 ms 139272 KB Output is correct
107 Correct 186 ms 139336 KB Output is correct
108 Correct 208 ms 139320 KB Output is correct
109 Correct 185 ms 139236 KB Output is correct
110 Correct 170 ms 123692 KB Output is correct
111 Correct 169 ms 123520 KB Output is correct
112 Correct 169 ms 123532 KB Output is correct
113 Correct 176 ms 123700 KB Output is correct
114 Correct 173 ms 123492 KB Output is correct
115 Correct 201 ms 174640 KB Output is correct
116 Correct 222 ms 174636 KB Output is correct
117 Correct 202 ms 174648 KB Output is correct
118 Correct 210 ms 174652 KB Output is correct
119 Correct 208 ms 174680 KB Output is correct
120 Correct 168 ms 123500 KB Output is correct
121 Correct 188 ms 123560 KB Output is correct
122 Correct 174 ms 123572 KB Output is correct
123 Correct 169 ms 123580 KB Output is correct
124 Correct 170 ms 149068 KB Output is correct
125 Correct 173 ms 149248 KB Output is correct
126 Correct 184 ms 149124 KB Output is correct
127 Correct 169 ms 149052 KB Output is correct
128 Correct 80 ms 64900 KB Output is correct
129 Correct 77 ms 64908 KB Output is correct
130 Correct 79 ms 64888 KB Output is correct
131 Correct 1 ms 212 KB Output is correct