답안 #637792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637792 2022-09-03T09:35:03 Z ogibogi2004 Secret Permutation (RMI19_permutation) C++14
컴파일 오류
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* conv(vector<int>v)
{
    static 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(conv(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

permutation.cpp: In function 'int* conv(std::vector<int>)':
permutation.cpp:24:16: error: storage size of 'ret' isn't constant
   24 |     static int ret[v.size()];
      |                ^~~
permutation.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<v.size();i++)ret[i]=v[i];
      |                 ~^~~~~~~~~
permutation.cpp: In function 'void solve(int)':
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: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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~