Submission #637789

# Submission time Handle Problem Language Result Execution time Memory
637789 2022-09-03T09:30:43 Z ogibogi2004 Secret Permutation (RMI19_permutation) C++14
Compilation error
0 ms 0 KB
#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 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(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(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

permutation.cpp: In function 'void solve(int)':
permutation.cpp:34:29: error: cannot convert 'std::vector<int>' to 'int*'
   34 |     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:40:33: 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:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=0;i<v2.size();i++)
      |                 ~^~~~~~~~~~
permutation.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int j=i;j<v2.size();j++)v1.push_back(v2[j]);
      |                     ~^~~~~~~~~~
permutation.cpp:60:33: error: cannot convert 'std::vector<int>' to 'int*'
   60 |         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:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=0;i<v2.size();i++)
      |                 ~^~~~~~~~~~
permutation.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=2;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
permutation.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i=0;i<ans.size();i++)minans=min(minans,ans[i]);
      |                 ~^~~~~~~~~~~
permutation.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
permutation.cpp:100:12: error: cannot convert 'std::vector<int>' to 'int*'
  100 |     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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~