답안 #1054122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054122 2024-08-12T06:37:32 Z huutuan Secret Permutation (RMI19_permutation) C++14
0 / 100
1 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) {
   vector<int> ans(n+1);
   vector<int> v(n);
   iota(v.begin(), v.end(), 1);
   vector<int> d1(n+1);
   for (int i=0; i<n; ++i){
      d1[v[0]]=query(v);
      rotate(v.begin(), v.begin()+1, v.end());
   }
   int sum=accumulate(d1.begin(), d1.end(), 0)/(n-1);
   for (int &i:d1) i=sum-i;
   auto find=[&](int x, int y){
      if (x>y) swap(x, y);
      if (y-x==1) return d1[y];
      if (y-x==n-1) return d1[1];
      vector<int> vv(n);
      iota(vv.begin(), vv.end(), 1);
      rotate(vv.begin(), vv.begin()+x-1, vv.end());
      reverse(vv.begin(), vv.begin()+y-x);
      int s=query(vv);
      for (int i=1; i<n; ++i){
         if (abs(vv[i]-vv[i-1])==1){
            s-=d1[max(vv[i], vv[i-1])];
         }else if (abs(vv[i]-vv[i-1])==n-1){
            s-=d1[1];
         }
      }
      return s;
   };
   ans[2]=ans[1]+d1[2];
   for (int i=3; i+1<=n; i+=2){
      int t=find(i-2, i+1);
      if (abs(ans[i-1]-ans[i-2]+d1[i]+d1[i+1])==t){
         ans[i]=ans[i-1]+d1[i];
         ans[i+1]=ans[i]+d1[i+1];
      }else if (abs(ans[i-1]-ans[i-2]+d1[i]-d1[i+1])==t){
         ans[i]=ans[i-1]+d1[i];
         ans[i+1]=ans[i]-d1[i+1];
      }else if (abs(ans[i-1]-ans[i-2]-d1[i]+d1[i+1])==t){
         ans[i]=ans[i-1]-d1[i];
         ans[i+1]=ans[i]+d1[i+1];
      }else{
         ans[i]=ans[i-1]-d1[i];
         ans[i+1]=ans[i]-d1[i+1];
      }
   }
   if (n&1){
      int t=find(n-2, n);
      if (abs(ans[n-1]-ans[n-2]+d1[n])==t){
         ans[n]=ans[n-1]+d1[n];
      }else{
         ans[n]=ans[n-1]-d1[n];
      }
   }
   ans.erase(ans.begin());
   int mn=*min_element(ans.begin(), ans.end());
   for (int &i:ans) i-=mn-1;
   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 1 ms 344 KB Partially correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -