| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 942244 | Ghetto | Homework (CEOI22_homework) | C++17 | 154 ms | 82348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAX_N = 1e5 + 5;
string str;
int n;
set<int> commas_at_depth[4 * MAX_N]; // Starts at 1
int type[4 * MAX_N]; // 1 = min, 2 = max, 3 = leaf
void build(int u, int l, int r, int d) {
// cout << u << " " << l << " " << r << " " << d << endl;
if (l == r) {
type[u] = 3;
return;
}
type[u] = (str[l + 1] == 'i') ? 1 : 2;
int i = *commas_at_depth[d].lower_bound(l);
build(2 * u, l + 4, i - 1, d + 1);
build(2 * u + 1, i + 1, r - 1, d + 1);
}
void precomp() {
for (int i = 0; i < str.size(); i++) n += (bool) (str[i] == '?');
int depth = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '(') depth++;
else if (str[i] == ')') depth--;
else if (str[i] == ',') commas_at_depth[depth].insert(i);
}
build(1, 0, str.size() - 1, 1);
// for (int i = 1; i <= 4 * n; i++) {
// cout << i << ": " << type[i] << endl;
// }
}
pii find_bounds(int u) {
if (type[u] == 3) return {0, 0};
pii l_bounds = find_bounds(2 * u), r_bounds = find_bounds(2 * u + 1);
int min_bound = (type[u] == 1) ? min(l_bounds.first, r_bounds.first) : l_bounds.first + r_bounds.first + 1;
int max_bound = (type[u] == 1) ? l_bounds.second + r_bounds.second + 1 : min(l_bounds.second, r_bounds.second);
return {min_bound, max_bound};
}
int main() {
// freopen("homework.in", "r", stdin);
cin >> str;
precomp();
pii bounds = find_bounds(1);
int ans = n - bounds.first - bounds.second;
cout << ans << '\n';
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
