Submission #570620

#TimeUsernameProblemLanguageResultExecution timeMemory
570620patrikpavic2Zagonetka (COI18_zagonetka)C++17
100 / 100
108 ms416 KiB
#include <cstdio> #include <vector> #include <algorithm> #define PB push_back #define X first #define Y second using namespace std; typedef pair < int, int > pii; const int N = 5050; int p[N], q[N], l[N], r[N], uz[N], n; bool pitaj(){ printf("query "); for(int i = 0;i < n;i++) printf("%d ", q[i]); printf("\n"); fflush(stdout); int x; scanf("%d", &x); return x; } int main(){ scanf("%d", &n); for(int i = 0;i < n;i++){ scanf("%d", p + i); q[i] = p[i]; } for(int i = 0;i < n;i++){ for(int j = q[i] - 1;j >= 1;j--){ if(uz[j]) continue; vector < pii > vr; for(int k = i;k < n;k++){ if(q[k] <= q[i] && q[k] >= j) vr.PB({q[k], k}); } sort(vr.begin(), vr.end()); for(int i = 0;i + 1 < (int)vr.size();i++){ q[vr[i + 1].Y] = vr[i].X; } q[vr[0].Y] = vr.back().X; if(!pitaj()){ for(pii &tmp : vr) q[tmp.Y] = tmp.X; } } uz[q[i]] = 1; } for(int i = 0;i < n;i++){ l[i] = q[i]; q[i] = p[i]; uz[i + 1] = 0; } for(int i = 0;i < n;i++){ for(int j = q[i] + 1;j <= n;j++){ if(uz[j]) continue; vector < pii > vr; for(int k = i;k < n;k++){ if(q[k] >= q[i] && q[k] <= j) vr.PB({q[k], k}); } sort(vr.begin(), vr.end()); for(int i = 0;i + 1 < (int)vr.size();i++){ q[vr[i].Y] = vr[i + 1].X; } q[vr.back().Y] = vr[0].X; if(!pitaj()){ for(pii &tmp : vr) q[tmp.Y] = tmp.X; } } uz[q[i]] = 1; } printf("end\n"); for(int i = 0;i < n;i++) printf("%d ", l[i]); printf("\n"); for(int i = 0;i < n;i++) printf("%d ", q[i]); printf("\n"); fflush(stdout); return 0; }

Compilation message (stderr)

zagonetka.cpp: In function 'bool pitaj()':
zagonetka.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  int x; scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
zagonetka.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   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...