답안 #1053996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053996 2024-08-12T03:23:47 Z huutuan Secret Permutation (RMI19_permutation) C++14
53.1429 / 100
26 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);
   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);
      swap(v[0], v[1]);
      d+=query(v);
      dx[i]=d;
      diff=min(diff, d);
   }
   diff=max(1, -diff+1);
   int mx=0;
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      dx[i]+=diff;
      mx=max(mx, dx[i]);
   }
   int x1=mx+1, x2=n-mx;
   int y1=x1+diff, y2=x2+diff;
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      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);
      dy[i]=d;
   }
   int my=0;
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      dy[i]+=diff;
      my=max(my, dy[i]);
   }
   if ((x1>=1 && x1<=n && y1>=1 && y1<=n && (y1==my+1 || y1==n-my))){
      ans[x]=x1;
      ans[y]=y1;
   }else{
      ans[x]=x2;
      ans[y]=y2;
   }
   for (int i=1; i<=n; ++i) if (i!=x && i!=y){
      if (dx[i]+dy[i]==diff) ans[i]=ans[x]+dx[i];
      else if (dx[i]<dy[i]) 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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 344 KB Partially correct
# 결과 실행 시간 메모리 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 1 ms 344 KB Partially correct
7 Partially correct 1 ms 344 KB Partially correct
8 Partially correct 2 ms 344 KB Partially correct
9 Partially correct 2 ms 344 KB Partially correct
10 Partially correct 2 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 2 ms 344 KB Partially correct
13 Partially correct 2 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 2 ms 344 KB Partially correct
16 Partially correct 1 ms 344 KB Partially correct
# 결과 실행 시간 메모리 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 1 ms 344 KB Partially correct
7 Partially correct 1 ms 344 KB Partially correct
8 Partially correct 2 ms 344 KB Partially correct
9 Partially correct 2 ms 344 KB Partially correct
10 Partially correct 2 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 2 ms 344 KB Partially correct
13 Partially correct 2 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 2 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 14 ms 344 KB Partially correct
19 Partially correct 14 ms 344 KB Partially correct
20 Partially correct 15 ms 344 KB Partially correct
21 Partially correct 17 ms 344 KB Partially correct
22 Partially correct 17 ms 344 KB Partially correct
23 Partially correct 17 ms 344 KB Partially correct
24 Partially correct 15 ms 344 KB Partially correct
25 Partially correct 26 ms 344 KB Partially correct
26 Partially correct 15 ms 344 KB Partially correct