답안 #1073051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073051 2024-08-24T09:05:07 Z Gromp15 Homework (CEOI22_homework) C++17
100 / 100
405 ms 254784 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
	string s; cin >> s;
	vector<int> type; // 0 = max, 1 = min, 2 = ?
	vector<int> lst;
	vector<ar<int, 2>> adj;
	int on = 0;
	for (int i = 0; i < sz(s); i++) {
		if (s[i] == '?') {
			adj.push_back({-1, -1});
			lst.emplace_back(on++);
			type.emplace_back(2);
		}
		else if (s[i] == ')') {
			assert(lst.size() > 2);
			int x = lst.back(); lst.pop_back();
			int y = lst.back(); lst.pop_back();
			int v = lst.back();
			adj[v] = {x, y};
		}
		else if (i+2 < sz(s)) {
			if (s.substr(i, 3) == "min") {
				lst.emplace_back(on++);
				type.push_back(1);
				adj.push_back({-1, -1});
				i += 2;
			}
			else if (s.substr(i, 3) == "max") {
				lst.emplace_back(on++);
				type.push_back(0);
				adj.push_back({-1, -1});
				i += 2;
			}
		}
	}
	vector<ar<ar<int, 2>, 3>> dp(on), dp2(on);
	auto dfs = [&](auto&& s, int v) -> void {
		for (int i = 0; i < 3; i++) for (int j = 0; j < 2; j++) dp[v][i][j] = -1e9, dp2[v][i][j] = 1e9;
		if (~adj[v][0]) {
			auto [l, r] = adj[v];
			s(s, l);
			s(s, r);
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					for (int k1 = 0; k1 < 2; k1++) for (int k2 = 0; k2 < 2; k2++) if (!k1 || !k2) {
						if (type[v] == 0) {
							ckmax(dp[v][max(i, j)][k1||k2], dp[l][i][k1] + dp[r][j][k2]);
							ckmin(dp2[v][max(i, j)][k1||k2], dp2[l][i][k1] + dp2[r][j][k2]);
						}
						else {
							assert(type[v] == 1);
							ckmax(dp[v][min(i, j)][k1||k2], dp[l][i][k1] + dp[r][j][k2]);
							ckmin(dp2[v][min(i, j)][k1||k2], dp2[l][i][k1] + dp2[r][j][k2]);
						}
					}
				}
			}
		}
		else {
			for (int i = 0; i < 3; i++) {
				dp[v][i][i==1] = !i, dp2[v][i][i==1] = !i;
			}
		}
	};
	dfs(dfs, 0);
	cout << dp[0][1][1] - dp2[0][1][1] + 1 << '\n';



}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 456 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 388 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 464 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 370 ms 252968 KB Output is correct
2 Correct 363 ms 246944 KB Output is correct
3 Correct 371 ms 253712 KB Output is correct
4 Correct 405 ms 247044 KB Output is correct
5 Correct 364 ms 246996 KB Output is correct
6 Correct 349 ms 246932 KB Output is correct
7 Correct 364 ms 247160 KB Output is correct
8 Correct 376 ms 253956 KB Output is correct
9 Correct 353 ms 252964 KB Output is correct
10 Correct 366 ms 254784 KB Output is correct
11 Correct 369 ms 251036 KB Output is correct
12 Correct 361 ms 253572 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 456 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 388 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 464 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 784 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 2 ms 604 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 1 ms 600 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 676 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 856 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 1 ms 600 KB Output is correct
81 Correct 1 ms 600 KB Output is correct
82 Correct 1 ms 604 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 0 ms 604 KB Output is correct
86 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 456 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 388 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 464 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 370 ms 252968 KB Output is correct
58 Correct 363 ms 246944 KB Output is correct
59 Correct 371 ms 253712 KB Output is correct
60 Correct 405 ms 247044 KB Output is correct
61 Correct 364 ms 246996 KB Output is correct
62 Correct 349 ms 246932 KB Output is correct
63 Correct 364 ms 247160 KB Output is correct
64 Correct 376 ms 253956 KB Output is correct
65 Correct 353 ms 252964 KB Output is correct
66 Correct 366 ms 254784 KB Output is correct
67 Correct 369 ms 251036 KB Output is correct
68 Correct 361 ms 253572 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 600 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 784 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 1 ms 604 KB Output is correct
82 Correct 2 ms 604 KB Output is correct
83 Correct 1 ms 604 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 676 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 856 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 1 ms 600 KB Output is correct
94 Correct 1 ms 600 KB Output is correct
95 Correct 1 ms 604 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 604 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 360 ms 131644 KB Output is correct
101 Correct 361 ms 136204 KB Output is correct
102 Correct 325 ms 137644 KB Output is correct
103 Correct 383 ms 135492 KB Output is correct
104 Correct 315 ms 131576 KB Output is correct
105 Correct 321 ms 172712 KB Output is correct
106 Correct 312 ms 178200 KB Output is correct
107 Correct 295 ms 175872 KB Output is correct
108 Correct 309 ms 174100 KB Output is correct
109 Correct 376 ms 172320 KB Output is correct
110 Correct 309 ms 135596 KB Output is correct
111 Correct 327 ms 135592 KB Output is correct
112 Correct 297 ms 136864 KB Output is correct
113 Correct 318 ms 131660 KB Output is correct
114 Correct 298 ms 138020 KB Output is correct
115 Correct 350 ms 247072 KB Output is correct
116 Correct 390 ms 246988 KB Output is correct
117 Correct 350 ms 252304 KB Output is correct
118 Correct 358 ms 247180 KB Output is correct
119 Correct 371 ms 247176 KB Output is correct
120 Correct 341 ms 137604 KB Output is correct
121 Correct 312 ms 138212 KB Output is correct
122 Correct 317 ms 137740 KB Output is correct
123 Correct 336 ms 136604 KB Output is correct
124 Correct 326 ms 198264 KB Output is correct
125 Correct 325 ms 198656 KB Output is correct
126 Correct 325 ms 190200 KB Output is correct
127 Correct 308 ms 190348 KB Output is correct
128 Correct 165 ms 72228 KB Output is correct
129 Correct 164 ms 72288 KB Output is correct
130 Correct 157 ms 72212 KB Output is correct
131 Correct 0 ms 344 KB Output is correct