Submission #637790

#TimeUsernameProblemLanguageResultExecution timeMemory
637790ogibogi2004Secret Permutation (RMI19_permutation)C++14
Compilation error
0 ms0 KiB
#include "permutationc.h" #include<bits/stdc++.h> using namespace std; mt19937 mt(69); /*vector<int>p; int query(vector<int>v) { int ans=0; for(int i=1;i<v.size();i++) { ans+=abs(p[v[i]]-p[v[i-1]]); } return ans; } void answer(vector<int>v) { for(auto xd:v)cout<<xd<<" "; cout<<endl; }*/ int[] conv(vector<int>v) { int ret[v.size()]; for(int i=0;i<v.size();i++)ret[i]=v[i]; return ret; } int val[256]; int dif1[256]; int dif2[256]; int c[256]; int n; void solve(int N) { n=N; vector<int>v1; for(int i=0;i<n;i++)v1.push_back(i); vector<int>answers; answers.push_back(query(v1)); for(int i=1;i<n;i++) { v1.clear(); for(int j=i;j<n;j++)v1.push_back(j); for(int j=0;j<i;j++)v1.push_back(j); answers.push_back(query(conv(v1))); } int sum=0; for(auto xd:answers)sum+=xd; sum/=(n-1); //cout<<sum<<endl; for(int i=0;i<n;i++) { dif1[i]=sum-answers[i]; } v1.clear(); answers.clear(); vector<int>v2; for(int i=0;i<n;i+=2)v2.push_back(i); for(int i=1;i<n;i+=2)v2.push_back(i); for(int i=0;i<v2.size();i++) { v1.clear(); for(int j=i;j<v2.size();j++)v1.push_back(v2[j]); for(int j=0;j<i;j++)v1.push_back(v2[j]); answers.push_back(query(conv(v1))); } sum=0; for(auto xd:answers)sum+=xd; sum/=(n-1); for(int i=0;i<v2.size();i++) { dif2[v2[i]]=sum-answers[i]; } vector<int>ans(n,0); ans[1]=ans[0]+dif1[1]; c[1]=1; for(int i=2;i<ans.size();i++) { if(dif2[i]==dif1[i-1]+dif1[i]) { c[i]=c[i-1]; } else c[i]=-c[i-1]; ans[i]=ans[i-1]+c[i]*dif1[i]; } int minans=0; for(int i=0;i<ans.size();i++)minans=min(minans,ans[i]); for(int i=0;i<ans.size();i++) { ans[i]-=minans; ans[i]+=1; } /*cout<<"difs:\n"; for(int i=0;i<n;i++) { cout<<dif1[i]<<" "; } cout<<endl; for(int i=0;i<n;i++) { cout<<dif2[i]<<" "; } cout<<endl; cout<<endl;*/ answer(ans); } /*int main() { int N; cin>>N; for(int i=0;i<N;i++) { int x; cin>>x; p.push_back(x); } solve(N); }*/

Compilation message (stderr)

permutation.cpp:22:4: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 | int[] conv(vector<int>v)
      |    ^
permutation.cpp:22:4: error: structured binding declaration cannot have type 'int'
   22 | int[] conv(vector<int>v)
      |    ^~
permutation.cpp:22:4: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
permutation.cpp:22:4: error: empty structured binding declaration
permutation.cpp:22:7: error: expected initializer before 'conv'
   22 | int[] conv(vector<int>v)
      |       ^~~~
permutation.cpp: In function 'void solve(int)':
permutation.cpp:40:29: error: cannot convert 'std::vector<int>' to 'int*'
   40 |     answers.push_back(query(v1));
      |                             ^~
      |                             |
      |                             std::vector<int>
In file included from permutation.cpp:1:
permutationc.h:2:15: note:   initializing argument 1 of 'int query(int*)'
    2 | int query(int v[]);
      |           ~~~~^~~
permutation.cpp:46:33: error: 'conv' was not declared in this scope; did you mean 'lconv'?
   46 |         answers.push_back(query(conv(v1)));
      |                                 ^~~~
      |                                 lconv
permutation.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0;i<v2.size();i++)
      |                 ~^~~~~~~~~~
permutation.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int j=i;j<v2.size();j++)v1.push_back(v2[j]);
      |                     ~^~~~~~~~~~
permutation.cpp:66:33: error: 'conv' was not declared in this scope; did you mean 'lconv'?
   66 |         answers.push_back(query(conv(v1)));
      |                                 ^~~~
      |                                 lconv
permutation.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i=0;i<v2.size();i++)
      |                 ~^~~~~~~~~~
permutation.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=2;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
permutation.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i=0;i<ans.size();i++)minans=min(minans,ans[i]);
      |                 ~^~~~~~~~~~~
permutation.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
permutation.cpp:106:12: error: cannot convert 'std::vector<int>' to 'int*'
  106 |     answer(ans);
      |            ^~~
      |            |
      |            std::vector<int>
In file included from permutation.cpp:1:
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~