Submission #1054009

# Submission time Handle Problem Language Result Execution time Memory
1054009 2024-08-12T04:02:34 Z huutuan Secret Permutation (RMI19_permutation) C++14
53.3333 / 100
17 ms 344 KB
#include "permutation.h"

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(69420);

int rand(int l, int r){
   return uniform_int_distribution<int>(l, r)(rng);
}

void solve(int n) {
   if (n==3){
      if (query({1, 2, 3})==2) answer({1, 2, 3});
      if (query({2, 1, 3})==2) answer({2, 1, 3});
      answer({3, 1, 2});
   }
   vector<int> ans(n+1, -1);
   int x=rand(1, n);
   int y=x;
   while (y==x) y=rand(1, n);
   if (x>y) swap(x, y);
   map<int, int> cnt;
   vector<int> dx(n+1), dy(n+1), sum(n+1);
   int diff=0;
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      vector<int> v;
      v.push_back(i);
      v.push_back(y);
      v.push_back(x);
      for (int j=1; j<=n; ++j) if (j!=i && j!=x && j!=y) v.push_back(j);
      int d=-query(v);
      sum[i]=-d;
      swap(v[0], v[1]);
      d+=query(v);
      dx[i]=d;
      diff=min(diff, d);
   }
   diff=max(1, -diff+1);
   int mx=0;
   vector<int> cand;
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      dx[i]+=diff;
      mx=max(mx, dx[i]);
   }
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      if (dx[i]==mx) cand.push_back(i);
   }
   if (diff==n-1){
      ans[x]=1; ans[y]=n;
   }else{
      int x1=mx+1, x2=n-mx;
      int y1=x1+diff, y2=x2+diff;
      vector<int> vis(n+1);
      if (cand.size()==2){
         ans[x]=x1; ans[y]=y1;
         vis[x1]=vis[y1]=1;
      }else{
         int id=cand[0];
         vector<int> v;
         v.push_back(id);
         v.push_back(x);
         v.push_back(y);
         for (int j=1; j<=n; ++j) if (j!=id && j!=x && j!=y) v.push_back(j);
         int d=-query(v);
         swap(v[0], v[1]);
         d+=query(v)+diff;
         if (x1>=1 && x1<=n && y1>=1 && y1<=n && y1==d+1){
            ans[x]=x1; ans[y]=y1; ans[id]=1;
         }else{
            ans[x]=x2; ans[y]=y2; ans[id]=n;
         }
         dy[id]=abs(ans[id]-ans[y]);
         vis[ans[x]]=vis[ans[y]]=vis[ans[id]]=1;
      }
   }
   for (int i=1; i<=n; ++i) if (ans[i]==-1){
      int t1=ans[x]+dx[i], t2=ans[x]-dx[i];
      if (t1<1 || t1>n) ans[i]=t2;
      else if (t2<1 || t2>n) ans[i]=t1;
      else{
         vector<int> v;
         v.push_back(i);
         v.push_back(x);
         v.push_back(y);
         for (int j=1; j<=n; ++j) if (j!=i && j!=x && j!=y) v.push_back(j);
         int d=-query(v);
         swap(v[0], v[1]);
         d+=query(v)+diff;
         if (dx[i]+d==diff) ans[i]=ans[x]+dx[i];
         else if (dx[i]<d) ans[i]=ans[x]-dx[i];
         else ans[i]=ans[x]+dx[i];
      }
   }
   ans.erase(ans.begin());
   answer(ans);
}

Compilation message

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB Partially correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Partially correct 0 ms 344 KB Partially correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB Partially correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Partially correct 0 ms 344 KB Partially correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
7 Partially correct 2 ms 344 KB Partially correct
8 Partially correct 2 ms 344 KB Partially correct
9 Partially correct 1 ms 344 KB Partially correct
10 Partially correct 1 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 1 ms 344 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 1 ms 344 KB Partially correct
16 Partially correct 1 ms 344 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB Partially correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Partially correct 0 ms 344 KB Partially correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
7 Partially correct 2 ms 344 KB Partially correct
8 Partially correct 2 ms 344 KB Partially correct
9 Partially correct 1 ms 344 KB Partially correct
10 Partially correct 1 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 1 ms 344 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 1 ms 344 KB Partially correct
16 Partially correct 1 ms 344 KB Partially correct
17 Partially correct 16 ms 344 KB Partially correct
18 Partially correct 10 ms 344 KB Partially correct
19 Partially correct 10 ms 344 KB Partially correct
20 Partially correct 17 ms 344 KB Partially correct
21 Partially correct 13 ms 344 KB Partially correct
22 Partially correct 11 ms 344 KB Partially correct
23 Partially correct 11 ms 344 KB Partially correct
24 Partially correct 12 ms 344 KB Partially correct
25 Partially correct 15 ms 344 KB Partially correct
26 Partially correct 9 ms 344 KB Partially correct