답안 #1054519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054519 2024-08-12T10:26:09 Z bachhoangxuan Secret Permutation (RMI19_permutation) C++17
컴파일 오류
0 ms 0 KB
#include "permutation.h"
#include<bits/stdc++.h>
using namespace std;

void solve(int n){

    vector<int> D(n),P(n);
    iota(P.begin(),P.end(),1);
    shuffle(P.begin(),P.end(),mt19937(1));
    int S=0;
    for(int i=0;i<n;i++) S+=(D[i]=query(P)),rotate(P.begin(),P.begin()+1,P.end());
    S/=(N-1);
    for(int &x:D) x=S-x;
    vector<int> a(n),vis(n+1);

    function<void(int)> dfs = [&](int i){
        if(i>=n){
            if(abs(a[0]-a[n-1])!=d[0]) return;
            vector<int> res(n);
            for(int i=0;i<n;i++) res[P[i]-1]=a[i];
            answer(res);
            return;
        }
        for(int t:{-1,-1}){
            int x=a[i-1]+t*d[i];
            if(1<=x && x<=n && !vis[x]){
                a[i]=x,vis[x]=1;
                dfs(i+1);
                vis[x]=0;
            }
        }
    };
    for(int i=1;i<=n;i++){
        a[0]=i,vis[i]=1;
        dfs(1);
        vis[i]=0;
    }
}

Compilation message

permutation.cpp: In function 'void solve(int)':
permutation.cpp:12:9: error: 'N' was not declared in this scope
   12 |     S/=(N-1);
      |         ^
permutation.cpp: In lambda function:
permutation.cpp:18:34: error: 'd' was not declared in this scope
   18 |             if(abs(a[0]-a[n-1])!=d[0]) return;
      |                                  ^
permutation.cpp:25:28: error: 'd' was not declared in this scope
   25 |             int x=a[i-1]+t*d[i];
      |                            ^
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~