Submission #130269

#TimeUsernameProblemLanguageResultExecution timeMemory
130269tjd229Zagonetka (COI18_zagonetka)C++14
27 / 100
109 ms432 KiB
#include <stdio.h> #include <vector> #include <queue> using namespace std; int s[101], l[101]; int p[101]; int mat[101][101]; int pos[101]; int n; int tp_sort(queue<int> &q,int s,int *vt,int *ind,vector<int> edge[101]) { int vis = 0; while (q.size()) { int u= q.front(); q.pop(); //if (u < 0) u = -u; vt[u] = s++; ++vis; for (auto v : edge[u]) { if (--ind[v]==0) q.push(v); } } return vis; } int dfs(int x,int dst,vector<int> edge[101]) { if (dst == x) return 1; for (auto nxt : edge[x]) { if (dfs(nxt, dst, edge)) return 1; } return 0; } void dfs(int x, int d, int &num,int *vt, vector<int> edge[101]) { if (vt[x]) return; for (auto nxt : edge[x]) dfs(nxt, d, num, vt, edge); vt[x] = num; num += d; } void qry(int x,int y) {//chk pos[x]->pos[y] //inv edge ok -> no condition //inv edge no -> there is condition //cycle -> there is cond.(inclusive indirect) vector<int> edge[101]; vector<int> loc; int ind[101] = { 0 }; int myp[101] = {}; for (int i = 1; i <= n; ++i) myp[i] = p[i]; for (int i = x; i <= y; ++i) loc.push_back(pos[i]); for (int i = 0; i < loc.size(); ++i) { for (int j = i; j < loc.size(); ++j) { if (mat[loc[i]][loc[j]]) { edge[loc[i]].push_back(loc[j]); ++ind[loc[j]]; } } } //dfs chk if (dfs(pos[x], pos[y], edge)) return; edge[pos[y]].push_back(pos[x]);//inv edge ++ind[pos[x]]; queue<int> q; for (auto v : loc) { if (ind[v] == 0) q.push(v); } if (y - x + 1 == tp_sort(q,x, myp, ind, edge)) { int i; for (printf("query"), i = 1; i <= n; ++i) printf(" %d",myp[i]); printf("\n"); fflush(stdout); scanf("%d",&i); if (i) return; } //cycle chk mat[pos[x]][pos[y]] = 1; } int main() { int i; for (scanf("%d", &n), i = 1; i <= n; ++i) { scanf("%d", p + i); pos[p[i]] = i; } for (int range = 1; range < n; ++range) { for (i = 1; i + range <= n; ++i) qry(i,i+range); } vector<int> back[101],edge[101]; for (i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (mat[i][j]) { back[j].push_back(i); edge[i].push_back(j); } } } int src = 1; for (i = 1; i <= n; ++i) dfs(i, 1, src, s, back); for (i = 1,src=n; i <= n; ++i) dfs(i, -1, src, l, edge); for (printf("end\n"), i = 1; i <= n; ++i) printf("%d ",s[i]); for (printf("\n"), i = 1; i <= n; ++i) printf("%d ", l[i]); fflush(stdout); return 0; }

Compilation message (stderr)

zagonetka.cpp: In function 'void qry(int, int)':
zagonetka.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < loc.size(); ++i) {
                  ~~^~~~~~~~~~~~
zagonetka.cpp:50:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = i; j < loc.size(); ++j) {
                   ~~^~~~~~~~~~~~
zagonetka.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&i);
   ~~~~~^~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:81:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (scanf("%d", &n), i = 1; i <= n; ++i) {
       ~~~~~~~~~~~~~~~^~~~~~~
zagonetka.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", p + 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...