Submission #44578

#TimeUsernameProblemLanguageResultExecution timeMemory
44578ssnsarang2023Zagonetka (COI18_zagonetka)C++17
100 / 100
180 ms716 KiB
#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 (stderr)

zagonetka.cpp: In function 'bool ask(std::vector<int>&, int)':
zagonetka.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &re);
     ~~~~~^~~~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
zagonetka.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...