Submission #644245

# Submission time Handle Problem Language Result Execution time Memory
644245 2022-09-24T08:05:29 Z Karuk Secret Permutation (RMI19_permutation) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "permutationc.h"
using namespace std;
void solve(int n) {
    vector<int>a(n);
    for(int i=1;i<=n;i++) {
        a[i-1]=i;
    }
    int maxres=0,maxind=-1;
    for(int i=1;i<n;i++) {
        reverse(a.begin(),a.begin()+i-1);
        int c=query(a);
        reverse(a.begin(),a.begin()+i-1);
        if(c>maxres){maxres=c;maxind=a[i];}
    }
    swap(a[0],a[maxind]);
    maxres=0;
    maxind=-1;
    vector<pair<int,int> >v;
    for(int i=1;i<n;i++) {
        reverse(a.begin(),a.begin()+i-1);
        int c=query(a);
        reverse(a.begin(),a.begin()+i-1);
        v.push_back({c,a[i]});
    }
    vector<int>ans(n,-1);
    sort(v.begin(),v.end());
    ans[a[0]]=1;
    for(int i=2;i<=n;i++) {
        ans[v[i-2].second]=i;
    }
    answer(ans);
}

Compilation message

permutation.cpp: In function 'void solve(int)':
permutation.cpp:12:21: error: cannot convert 'std::vector<int>' to 'int*'
   12 |         int c=query(a);
      |                     ^
      |                     |
      |                     std::vector<int>
In file included from permutation.cpp:2:
permutationc.h:2:15: note:   initializing argument 1 of 'int query(int*)'
    2 | int query(int v[]);
      |           ~~~~^~~
permutation.cpp:22:21: error: cannot convert 'std::vector<int>' to 'int*'
   22 |         int c=query(a);
      |                     ^
      |                     |
      |                     std::vector<int>
In file included from permutation.cpp:2:
permutationc.h:2:15: note:   initializing argument 1 of 'int query(int*)'
    2 | int query(int v[]);
      |           ~~~~^~~
permutation.cpp:32:12: error: cannot convert 'std::vector<int>' to 'int*'
   32 |     answer(ans);
      |            ^~~
      |            |
      |            std::vector<int>
In file included from permutation.cpp:2:
permutationc.h:3:17: note:   initializing argument 1 of 'void answer(int*)'
    3 | void answer(int v[]);
      |             ~~~~^~~
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~