답안 #1054406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054406 2024-08-12T09:40:03 Z huutuan Secret Permutation (RMI19_permutation) C++14
0 / 100
0 ms 344 KB
#include "permutation.h"

#include <bits/stdc++.h>

using namespace std;

void solve(int n) {
   vector<int> v(n);
   iota(v.begin(), v.end(), 1);
   shuffle(v.begin(), v.end(), mt19937(69420));
   vector<int> d1(n);
   for (int i=0; i<n; ++i){
      d1[i]=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;
   vector<int> ans(n);
   vector<int> vis(n+1);
   auto backtrack=[&](auto &&self, int i){
      if (i>=n){
         if (abs(ans[n-1]-ans[0])!=d1[0]) return;
         vector<int> res(n);
         for (int i=0; i<n; ++i) res[v[i]-1]=ans[i];
         answer(res);
      }
      int x=ans[i-1]+d1[i];
      if (1<=x && x<=n && !vis[x]){
         vis[x]=1;
         ans[i]=x;
         self(self, i+1);
         vis[x]=0;
      }
      x=ans[i-1]-d1[i];
      if (1<=x && x<=n && !vis[x]){
         vis[x]=1;
         ans[i]=x;
         self(self, i+1);
         vis[x]=0;
      }
   };
   for (int i=1; i<=n; ++i){
      vis[i]=1;
      ans[0]=i;
      backtrack(backtrack, 1);
      vis[i]=0;
   }
}

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 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -