제출 #638389

#제출 시각아이디문제언어결과실행 시간메모리
638389ggoh곤돌라 (IOI14_gondola)C++14
컴파일 에러
0 ms0 KiB
#include<gondola.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
lint X=1e9+9;
lint po(lint p,int q)
{
  if(q==0)return 1ll;
  if(q==1)return p;
  lint o=po(p,q/2);
  o=o*o%X;
  if(q%2)return o*p%X;
  else return o;
}
int valid(int n, int inputSeq[])
{
  vector<int>check(n+1),copy(n);
  for(int i=0;i<n;i++)
  {
    copy[i]=inputSeq[i];
    if(inputSeq[i]<=n)check[inputSeq[i]]=i+1;
  }
  sort(copy.begin(),copy.end());
  for(int i=0;i<n;i++)if(copy[i]==copy[i+1])return 0;
  int c=0,ans=1,pos,t;
  for(int i=1;i<=n;i++)
  {
    if(check[i])
    {
      if(!c)c=i,pos=check[i];
      else
      {
        t=check[i]-pos;
        if(t<=0)t+=n;
        if(t!=i-c)ans=0;
      }
    }
  }
  return ans;
}
 
 
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  vector<int>top(n),ans;
  int c=0,pos;
  for(int i=0;i<n;i++)
  {
    if(gondolaSeq[i]<=n)
    {
      c=gondolaSeq[i];
      pos=i;
    }
  }
  int left=0;
  if(c)
  {
    left=pos-(c-1);
  }
  vector<pair<int,int>>newG;
  for(int i=0;i<n;i++)
  {
    top[i]=i+1;
    newG.push_back({gondolaSeq[i],(i+n-left)%n});
  }
  sort(newG.begin(),newG.end());
  int t=n+1;
  for(auto &k:newG)
  {
    if(top[k.second]==k.first)continue;
    ans.push_back(top[k.second]);
    top[k.second]=t;
    t++;
    while(top[k.second]!=k.first)
    {
      ans.push_back(top[k.second]);
      top[k.second]++;
      t++;
    }
  }
  int sz=(int)ans.size();
  for(int i=0;i<sz;i++)replacementSeq[i]=ans[i];
  return sz;
}
 
 
int countReplacement(int n, int inputSeq[])
{
  if(!valid(n,inputSeq))return 0;
  lint ans=1ll,mul;
  vector<int>top(n),ans;
  int c=0,pos;
  for(int i=0;i<n;i++)
  {
    if(gondolaSeq[i]<=n)
    {
      c=gondolaSeq[i];
      pos=i;
    }
  }
  int left=0;
  if(c)
  {
    left=pos-(c-1);
  }
  vector<pair<int,int>>newG;
  for(int i=0;i<n;i++)
  {
    top[i]=i+1;
    newG.push_back({gondolaSeq[i],(i+n-left)%n});
  }
  mul=n;
  sort(newG.begin(),newG.end());
  int t=n+1;
  for(auto &k:newG)
  {
    if(k.first==k.second+1)mul--;
    else
    {
      ans*=po(mul,k.first-t);
      ans%=X;
      t=k.first+1;
      mul--;
    }
  }
  return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:91:21: error: conflicting declaration 'std::vector<int> ans'
   91 |   vector<int>top(n),ans;
      |                     ^~~
gondola.cpp:90:8: note: previous declaration as 'lint ans'
   90 |   lint ans=1ll,mul;
      |        ^~~
gondola.cpp:95:8: error: 'gondolaSeq' was not declared in this scope
   95 |     if(gondolaSeq[i]<=n)
      |        ^~~~~~~~~~
gondola.cpp:110:21: error: 'gondolaSeq' was not declared in this scope
  110 |     newG.push_back({gondolaSeq[i],(i+n-left)%n});
      |                     ^~~~~~~~~~
gondola.cpp:110:48: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
  110 |     newG.push_back({gondolaSeq[i],(i+n-left)%n});
      |                                                ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from gondola.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~