# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
971588 | 2024-04-29T03:29:12 Z | vjudge1 | Homework (CEOI22_homework) | C++17 | 1000 ms | 20964 KB |
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int N = 1e5 + 10; pair<int, int> st[N]; int t[N]; int operation[N]; int child[2][N], a[N], order[N]; bool dd[N]; int32_t main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } if (fopen(task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } string str; cin >> str; int p = 0; int id = 0, _id = 0; for(char c : str) if (c == '?') _id++; int n = _id; for(int i = 0; i < str.size(); i++) { if (str[i] == 'm') { i += 3; st[++p] = make_pair(0, 0); t[p] = str[i - 1] == 'x'; // cout << str[i - 1] << " " << t[p] << endl; } else if (str[i] == '?') { ++id; if (st[p].first == 0) st[p].first = id; else st[p].second = id; } else if (str[i] == ')') { ++_id; assert(st[p].first && st[p].second); child[0][_id] = st[p].first; child[1][_id] = st[p].second; operation[_id] = t[p]; // cout << _id << " " << st[p].first << " " << st[p].second << " " << operation[_id] << endl; --p; if (st[p].first == 0) st[p].first = _id; else st[p].second = _id; } } auto dfs = [&] (auto self, int u) { if (u <= n) { a[u] = order[u]; return; } self(self, child[0][u]); self(self, child[1][u]); if (operation[u]) a[u] = max(a[child[0][u]], a[child[1][u]]); else a[u] = min(a[child[0][u]], a[child[1][u]]); }; for(int i = 1; i <= n; i++) order[i] = i; do { // for(int i = 1; i <= n; i++) cerr << order[i] << " "; cerr << endl; dfs(dfs, _id); dd[a[_id]] = 1; } while (next_permutation(order + 1, order + n + 1)); int ans = 0; for(int i = 1; i <= n; i++) ans += dd[i]; int last = 1; for(int i = 1; i <= n; i++) if (dd[i] == dd[1]) last = i; // for(int i = 1; i <= last; i++) assert(dd[i] == dd[1]); // for(int i = last + 1; i <= n; i++) assert(dd[i] == dd[n]); // for(int i = 1; i <= n; i++) cout << dd[i] << " "; cout << endl; cout << ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 2392 KB | Output is correct |
2 | Correct | 11 ms | 2396 KB | Output is correct |
3 | Correct | 11 ms | 2396 KB | Output is correct |
4 | Correct | 10 ms | 2396 KB | Output is correct |
5 | Correct | 11 ms | 2520 KB | Output is correct |
6 | Correct | 11 ms | 2396 KB | Output is correct |
7 | Correct | 10 ms | 2392 KB | Output is correct |
8 | Correct | 12 ms | 2652 KB | Output is correct |
9 | Correct | 10 ms | 2648 KB | Output is correct |
10 | Correct | 12 ms | 2392 KB | Output is correct |
11 | Correct | 12 ms | 2396 KB | Output is correct |
12 | Correct | 11 ms | 2396 KB | Output is correct |
13 | Correct | 11 ms | 2508 KB | Output is correct |
14 | Correct | 12 ms | 2392 KB | Output is correct |
15 | Correct | 13 ms | 2396 KB | Output is correct |
16 | Correct | 14 ms | 2396 KB | Output is correct |
17 | Correct | 14 ms | 2508 KB | Output is correct |
18 | Correct | 15 ms | 2392 KB | Output is correct |
19 | Correct | 15 ms | 2396 KB | Output is correct |
20 | Correct | 14 ms | 2396 KB | Output is correct |
21 | Correct | 12 ms | 2520 KB | Output is correct |
22 | Correct | 10 ms | 2396 KB | Output is correct |
23 | Correct | 13 ms | 2396 KB | Output is correct |
24 | Correct | 13 ms | 2396 KB | Output is correct |
25 | Correct | 2 ms | 2392 KB | Output is correct |
26 | Correct | 2 ms | 2396 KB | Output is correct |
27 | Correct | 1 ms | 2396 KB | Output is correct |
28 | Correct | 0 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 2392 KB | Output is correct |
2 | Correct | 11 ms | 2396 KB | Output is correct |
3 | Correct | 11 ms | 2396 KB | Output is correct |
4 | Correct | 10 ms | 2396 KB | Output is correct |
5 | Correct | 11 ms | 2520 KB | Output is correct |
6 | Correct | 11 ms | 2396 KB | Output is correct |
7 | Correct | 10 ms | 2392 KB | Output is correct |
8 | Correct | 12 ms | 2652 KB | Output is correct |
9 | Correct | 10 ms | 2648 KB | Output is correct |
10 | Correct | 12 ms | 2392 KB | Output is correct |
11 | Correct | 12 ms | 2396 KB | Output is correct |
12 | Correct | 11 ms | 2396 KB | Output is correct |
13 | Correct | 11 ms | 2508 KB | Output is correct |
14 | Correct | 12 ms | 2392 KB | Output is correct |
15 | Correct | 13 ms | 2396 KB | Output is correct |
16 | Correct | 14 ms | 2396 KB | Output is correct |
17 | Correct | 14 ms | 2508 KB | Output is correct |
18 | Correct | 15 ms | 2392 KB | Output is correct |
19 | Correct | 15 ms | 2396 KB | Output is correct |
20 | Correct | 14 ms | 2396 KB | Output is correct |
21 | Correct | 12 ms | 2520 KB | Output is correct |
22 | Correct | 10 ms | 2396 KB | Output is correct |
23 | Correct | 13 ms | 2396 KB | Output is correct |
24 | Correct | 13 ms | 2396 KB | Output is correct |
25 | Correct | 2 ms | 2392 KB | Output is correct |
26 | Correct | 2 ms | 2396 KB | Output is correct |
27 | Correct | 1 ms | 2396 KB | Output is correct |
28 | Correct | 0 ms | 2396 KB | Output is correct |
29 | Execution timed out | 1061 ms | 2396 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 25 ms | 20964 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 2392 KB | Output is correct |
2 | Correct | 11 ms | 2396 KB | Output is correct |
3 | Correct | 11 ms | 2396 KB | Output is correct |
4 | Correct | 10 ms | 2396 KB | Output is correct |
5 | Correct | 11 ms | 2520 KB | Output is correct |
6 | Correct | 11 ms | 2396 KB | Output is correct |
7 | Correct | 10 ms | 2392 KB | Output is correct |
8 | Correct | 12 ms | 2652 KB | Output is correct |
9 | Correct | 10 ms | 2648 KB | Output is correct |
10 | Correct | 12 ms | 2392 KB | Output is correct |
11 | Correct | 12 ms | 2396 KB | Output is correct |
12 | Correct | 11 ms | 2396 KB | Output is correct |
13 | Correct | 11 ms | 2508 KB | Output is correct |
14 | Correct | 12 ms | 2392 KB | Output is correct |
15 | Correct | 13 ms | 2396 KB | Output is correct |
16 | Correct | 14 ms | 2396 KB | Output is correct |
17 | Correct | 14 ms | 2508 KB | Output is correct |
18 | Correct | 15 ms | 2392 KB | Output is correct |
19 | Correct | 15 ms | 2396 KB | Output is correct |
20 | Correct | 14 ms | 2396 KB | Output is correct |
21 | Correct | 12 ms | 2520 KB | Output is correct |
22 | Correct | 10 ms | 2396 KB | Output is correct |
23 | Correct | 13 ms | 2396 KB | Output is correct |
24 | Correct | 13 ms | 2396 KB | Output is correct |
25 | Correct | 2 ms | 2392 KB | Output is correct |
26 | Correct | 2 ms | 2396 KB | Output is correct |
27 | Correct | 1 ms | 2396 KB | Output is correct |
28 | Correct | 0 ms | 2396 KB | Output is correct |
29 | Execution timed out | 1061 ms | 2396 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 2392 KB | Output is correct |
2 | Correct | 11 ms | 2396 KB | Output is correct |
3 | Correct | 11 ms | 2396 KB | Output is correct |
4 | Correct | 10 ms | 2396 KB | Output is correct |
5 | Correct | 11 ms | 2520 KB | Output is correct |
6 | Correct | 11 ms | 2396 KB | Output is correct |
7 | Correct | 10 ms | 2392 KB | Output is correct |
8 | Correct | 12 ms | 2652 KB | Output is correct |
9 | Correct | 10 ms | 2648 KB | Output is correct |
10 | Correct | 12 ms | 2392 KB | Output is correct |
11 | Correct | 12 ms | 2396 KB | Output is correct |
12 | Correct | 11 ms | 2396 KB | Output is correct |
13 | Correct | 11 ms | 2508 KB | Output is correct |
14 | Correct | 12 ms | 2392 KB | Output is correct |
15 | Correct | 13 ms | 2396 KB | Output is correct |
16 | Correct | 14 ms | 2396 KB | Output is correct |
17 | Correct | 14 ms | 2508 KB | Output is correct |
18 | Correct | 15 ms | 2392 KB | Output is correct |
19 | Correct | 15 ms | 2396 KB | Output is correct |
20 | Correct | 14 ms | 2396 KB | Output is correct |
21 | Correct | 12 ms | 2520 KB | Output is correct |
22 | Correct | 10 ms | 2396 KB | Output is correct |
23 | Correct | 13 ms | 2396 KB | Output is correct |
24 | Correct | 13 ms | 2396 KB | Output is correct |
25 | Correct | 2 ms | 2392 KB | Output is correct |
26 | Correct | 2 ms | 2396 KB | Output is correct |
27 | Correct | 1 ms | 2396 KB | Output is correct |
28 | Correct | 0 ms | 2396 KB | Output is correct |
29 | Execution timed out | 1061 ms | 2396 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |