답안 #119641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119641 2019-06-21T14:18:27 Z CaroLinda 곤돌라 (IOI14_gondola) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "gondola.h"

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back

const int MOD=1e9;
const int maxn=1e5+10;

using namespace std ;

bool ok = false ;

int valid(int n, int inputSeq[])
{
  set<int> s ;
  int k=-1 ;
  lp(i,0,n)
  {
    if( s.find(inputSeq[i]) != s.end() )
      return 0 ;
    s.insert(inputSeq[i]) ;
    if(inputSeq[i]<=n) k = i ;
  }
  if(k==-1) {ok=true;return 1 ;}
  int count=(inputSeq[k]-k-1+n)%n+1 ;
  lp(i,0,n)
  {
    if(inputSeq[i]<=n && inputSeq[i]!=count)
      return 0 ;
    if (++count>n) count=1 ;
  }
  ok=true ;
  return 1 ;
}

int replacement(int n, int gondolaSeq[] , int replacementSeq[])
{
  int k=-1;
  lp(i,0,n)
  if(gondolaSeq[i]<=n)k=i ;

  int count ;

  if(k==-1)
    count=1 ;
  
  else count = (gondolaSeq[k]-k-1+n)%n+1 ;

  vector<pii> p ;

  lp(i,0,n)
  {
    if(gondolaSeq[i]>n)
    p.pb( pii( gondolaSeq[i] , count ) ) ;
    if(++count>n) count=1 ;
  }

  sort(p.begin(),p.end()) ;

  int ind=0 ;

  lp(i,0,p.size()){
    while(ind+n+1<=p[i].ff){
    replacementSeq[ind]=p[i].ss ;
    p[i].ss = ind+n+1 ;
    ind++ ;
    }
  }

  return ind ;

}

ll expo(ll x, int n)
{
    if(n==0) return 1 ;
    if(n==1) return x ;
    if(n%2==0)
    {
        ll aux=expo(x,n/2) ;
        return (aux*aux)%MOD ;
    }
    return (x*expo(x,n-1))%MOD ;
}

ll countReplacement(int n, int inputSeq[])
{
    if(!ok) return 0 ;
    int g ;
    for(g=0;g<n;g++)
    if(inputSeq[g]>n) break ;
    if(g==n+1) return 1 ;
    int k=-1 ;
    lp(i,0,n)
    if(inputSeq[i]<=n) k=i ;

    ll ans=1 ;
    int count=1;
    
    if(k == -1) {k=0 ; ans=n ; }
    else count=(inputSeq[k]-k-1)%n+1 ;
    
    vector<int> p ;
    
    p.pb(n+1) ;
    
    lp(i,0,n)
    if(inputSeq[i]>n)
    p.pb(inputSeq[i]) ;
    
    sort(p.begin(),p.end()) ;

    lp(i,1,p.size())
    {
        ans = (ans * expo(p.size() - i , p[i]-p[i-1] ) ) % MOD ;
        p[i] ++ ;
    }
    
    return ans ;
    
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:4:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define lp(i,a,b) for(int i=a;i<b;i++)
gondola.cpp:67:6:
   lp(i,0,p.size()){
      ~~~~~~~~~~~~               
gondola.cpp:67:3: note: in expansion of macro 'lp'
   lp(i,0,p.size()){
   ^~
gondola.cpp: In function 'long long int countReplacement(int, int*)':
gondola.cpp:91:4: error: ambiguating new declaration of 'long long int countReplacement(int, int*)'
 ll countReplacement(int n, int inputSeq[])
    ^~~~~~~~~~~~~~~~
In file included from gondola.cpp:2:0:
gondola.h:12:5: note: old declaration 'int countReplacement(int, int*)'
 int countReplacement(int n, int inputSeq[]);
     ^~~~~~~~~~~~~~~~
gondola.cpp:4:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define lp(i,a,b) for(int i=a;i<b;i++)
gondola.cpp:118:8:
     lp(i,1,p.size())
        ~~~~~~~~~~~~             
gondola.cpp:118:5: note: in expansion of macro 'lp'
     lp(i,1,p.size())
     ^~