# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44578 | 2018-04-03T12:18:55 Z | ssnsarang2023 | Zagonetka (COI18_zagonetka) | C++17 | 180 ms | 716 KB |
#define debug #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> ii; #define SZ(x) ((int)x.size()) int n, a[105], b[105], pos[105], deg[105]; bool adj[105][105]; bool ask(vector<int> &lst, int id) { queue<int> q; for (int i = 1; i <= n; ++i) { b[i] = a[i], deg[i] = 0; } for (auto &u : lst) { for (auto &v : lst) { deg[v] += adj[u][v]; } } for (auto &v : lst) { if (!deg[v]) { q.push(v); } } while (SZ(q)) { int u = q.front(); q.pop(); b[u] = id--; for (auto &v : lst) { if (!adj[u][v]) continue; --deg[v]; if (!deg[v]) { q.push(v); } } } for (auto &v : lst) { if (deg[v]) { return 1; } } printf("query "); for (int i = 1; i <= n; ++i) { printf("%d ", b[i]); } printf("\n"); fflush(stdout); int re = 0; scanf("%d", &re); return re; } bool vis[105]; int cnt; void get_ans(int u) { vis[u] = 1; while (1) { bool ok = 0; for (int v = 1; v <= n; ++v) { if (!vis[v] && adj[u][v]) { ok = 1; get_ans(v); } } if (!ok) break; } a[u] = ++cnt; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); pos[a[i]] = i; } for (int i = 1; i < n; ++i) { for (int j = 1; j <= n - i; ++j) { int x = pos[j], y = pos[j + i]; vector<int> lst; for (int k = 1; k <= n; ++k) { if (j <= a[k] && a[k] <= j + i) { lst.push_back(k); } } adj[x][y] = 1; adj[y][x] = !ask(lst, j + i); adj[x][y] = 0; } } for (int k = 1; k <= n; ++k) { for (int u = 1; u <= n; ++u) { for (int v = 1; v <= n; ++v) { adj[u][v] |= (adj[u][k] && adj[k][v]); } } } for (int i = 1; i <= n; ++i) { adj[0][i] = 1; } get_ans(0); printf("end\n"); for (int i = 1; i <= n; ++i) { printf("%d ", a[i]); } printf("\n"); for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { swap(adj[i][j], adj[j][i]); } } cnt = 0; memset(vis, false, sizeof(vis)); get_ans(0); for (int i = 1; i <= n; ++i) { printf("%d ", n - a[i] + 1); } fflush(stdout); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 308 KB | Output is correct |
3 | Correct | 2 ms | 360 KB | Output is correct |
4 | Correct | 2 ms | 536 KB | Output is correct |
5 | Correct | 2 ms | 536 KB | Output is correct |
6 | Correct | 2 ms | 536 KB | Output is correct |
7 | Correct | 2 ms | 536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 536 KB | Output is correct |
2 | Correct | 32 ms | 536 KB | Output is correct |
3 | Correct | 37 ms | 536 KB | Output is correct |
4 | Correct | 41 ms | 536 KB | Output is correct |
5 | Correct | 10 ms | 536 KB | Output is correct |
6 | Correct | 40 ms | 656 KB | Output is correct |
7 | Correct | 7 ms | 656 KB | Output is correct |
8 | Correct | 8 ms | 656 KB | Output is correct |
9 | Correct | 44 ms | 656 KB | Output is correct |
10 | Correct | 17 ms | 656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 656 KB | Output is correct |
2 | Correct | 3 ms | 656 KB | Output is correct |
3 | Correct | 6 ms | 656 KB | Output is correct |
4 | Correct | 8 ms | 656 KB | Output is correct |
5 | Correct | 4 ms | 656 KB | Output is correct |
6 | Correct | 5 ms | 656 KB | Output is correct |
7 | Correct | 5 ms | 656 KB | Output is correct |
8 | Correct | 7 ms | 656 KB | Output is correct |
9 | Correct | 8 ms | 656 KB | Output is correct |
10 | Correct | 3 ms | 656 KB | Output is correct |
11 | Correct | 5 ms | 656 KB | Output is correct |
12 | Correct | 7 ms | 656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 112 ms | 656 KB | Output is correct |
2 | Correct | 118 ms | 656 KB | Output is correct |
3 | Correct | 83 ms | 656 KB | Output is correct |
4 | Correct | 19 ms | 656 KB | Output is correct |
5 | Correct | 25 ms | 656 KB | Output is correct |
6 | Correct | 24 ms | 656 KB | Output is correct |
7 | Correct | 33 ms | 656 KB | Output is correct |
8 | Correct | 49 ms | 656 KB | Output is correct |
9 | Correct | 48 ms | 656 KB | Output is correct |
10 | Correct | 180 ms | 656 KB | Output is correct |
11 | Correct | 98 ms | 656 KB | Output is correct |
12 | Correct | 109 ms | 656 KB | Output is correct |
13 | Correct | 119 ms | 656 KB | Output is correct |
14 | Correct | 96 ms | 712 KB | Output is correct |
15 | Correct | 138 ms | 712 KB | Output is correct |
16 | Correct | 124 ms | 716 KB | Output is correct |