Submission #249886

#TimeUsernameProblemLanguageResultExecution timeMemory
249886kingfran1907Zagonetka (COI18_zagonetka)C++14
18 / 100
403 ms504 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n; int niz[maxn]; int graph[maxn][maxn]; bool bio[maxn]; vector< int > v; int qs[maxn]; int cnt[maxn], in[maxn]; queue< int > q; int sol[maxn]; int query() { printf("query "); for (int i = 0; i < n; i++) printf("%d ", qs[i]); printf("\n"); fflush(stdout); int x; scanf("%d", &x); return x; } void dfs(int x) { bio[x] = true; for (int i = 0; i < n; i++) { if (graph[x][i] != -1 && !bio[i]) dfs(i); } v.push_back(x); } void gen(vector< int > &v, int a, int b) { if (v.size() == 0) return; int x = v[0]; vector< int > p, q; for (int i = 1; i < v.size(); i++) { if (v[i] == x) continue; if (graph[v[i]][x] > -1) p.push_back(v[i]); else q.push_back(v[i]); } int k = a + p.size(); sol[x] = k; //printf("gen %d %d: %d %d\n", a, b, x, k); gen(p, a, k - 1); gen(q, k + 1, b); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", niz+i); memset(graph, -1, sizeof graph); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (niz[i] < niz[j]) { graph[i][j] = 0; } } } while (true) { while (!q.empty()) q.pop(); memset(cnt, 0, sizeof cnt); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (graph[i][j] != -1) cnt[j]++; } } for (int i = 0; i < n; i++) if (cnt[i] == 0) q.push(i); int a = -1, b = -1; int t = 0; while (!q.empty()) { int x = q.front(); q.pop(); //printf("debug: %d\n", x); in[x] = t++; int bs = -1; for (int i = 0; i < n; i++) { if (graph[i][x] == 0) { if (bs == -1 || in[bs] < in[i]) bs = i; } } if (bs != -1) { a = bs, b = x; break; } for (int i = 0; i < n; i++) { if (graph[x][i] != -1) { cnt[i]--; if (cnt[i] == 0) q.push(i); } } } if (a == -1) break; graph[a][b] = -1; graph[b][a] = 0; memset(bio, false, sizeof bio); v.clear(); for (int i = 0; i < n; i++) if (!bio[i]) dfs(i); reverse(v.begin(), v.end()); for (int i = 0; i < n; i++) qs[v[i]] = i + 1; //printf("trying: %d %d\n", a + 1, b + 1); int tren = query(); if (tren == 0) { graph[a][b] = 1; } else graph[a][b] = -1; graph[b][a] = -1; } printf("end\n"); /** for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (graph[i][j] != -1) { printf("edge: %d %d\n", i + 1, j + 1); } } } **/ v.clear(); for (int i = 0; i < n; i++) v.push_back(i); gen(v, 0, n - 1); for (int i = 0; i < n; i++) printf("%d ", sol[i] + 1); printf("\n"); for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) swap(graph[i][j], graph[j][i]); gen(v, 0, n - 1); for (int i = 0; i < n; i++) printf("%d ", n - sol[i]); printf("\n"); return 0; }

Compilation message (stderr)

zagonetka.cpp: In function 'void gen(std::vector<int>&, int, int)':
zagonetka.cpp:41:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < v.size(); i++) {
                     ~~^~~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:143:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0; i < n; i++) printf("%d ", sol[i] + 1); printf("\n");
     ^~~
zagonetka.cpp:143:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i = 0; i < n; i++) printf("%d ", sol[i] + 1); printf("\n");
                                                            ^~~~~~
zagonetka.cpp:150:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0; i < n; i++) printf("%d ", n - sol[i]); printf("\n");
     ^~~
zagonetka.cpp:150:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i = 0; i < n; i++) printf("%d ", n - sol[i]); printf("\n");
                                                            ^~~~~~
zagonetka.cpp: In function 'int query()':
zagonetka.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &x);
     ~~~~~^~~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
zagonetka.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", niz+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...