답안 #53123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53123 2018-06-28T12:49:13 Z zetapi 곤돌라 (IOI14_gondola) C++14
컴파일 오류
0 ms 0 KB
#include "gondola.h"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
const int MAX=1e6;
const ll mod=1e9+9;
 
int arr[MAX];

map<ll,ll> fre;
 
ll power(ll base,ll exp)
{
	ll res=1;
	while(exp)
	{
		if(exp%2)
			res*=base;
		base*=base;
		res%=mod;
		base%=mod;
		exp/=2;
	}
	return res;
}
 
int valid(int n, int inputSeq[])
{
  	int N=n,ok=1;
	for(int A=0;A<N;A++)
	{
		fre[inputSeq[A]]++;
		if(fre[inputSeq[A]]>1)
		 	return 0;
	}
  	for(int A=0;A<N;A++)
  	{
  	  	if(inputSeq[A]<=N)
  	  	{	
		 	ok=0;
		 	inputSeq[A]--;
		 	for(int B=A;B>=0;B--)
		 	{
			 	arr[B]=inputSeq[A];
			 	inputSeq[A]--;
			 	if(inputSeq[A]<0)
			 		inputSeq[A]+=N;
		 	}
		 	inputSeq[A]=arr[A];
		 	for(int B=A+1;B<N;B++)
		 	{
		 		inputSeq[A]++;
		 		if(inputSeq[A]>=N)
		 			inputSeq[A]=0;
		 		arr[B]=inputSeq[A];
		 	}
		 	inputSeq[A]=arr[A]+1;
		 	break;
	  	}
  	}
  	if(ok)
  	 	return 1;
  	for(int A=0;A<N;A++)
  	 	arr[A]++;
  	for(int A=0;A<N;A++)
  	{
  	  	if(inputSeq[A]<=N and arr[A]!=inputSeq[A])
  	  		return 0;	
  	}
  	return 1;
}
 
//----------------------
 
/*int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  	return -2;
}*/
 
 
int replacement(int n,int gondolaSeq[],int replacementSeq[])
{
	vector<int> vec;
	priority_queue<int> absent;
	priority_queue<pii> present;
	pii cur;
	int N=n,mx=0,change=0,sec;
	for(int A=0;A<N;A++)
		arr[A]=A;
	for(int A=0;A<N;A++)
  	{
	  	if(gondolaSeq[A]<=N)
	  	{
			 gondolaSeq[A]--;
			 for(int B=A;B>=0;B--)
			 {
			 	arr[B]=gondolaSeq[A];
			 	gondolaSeq[A]--;
			 	if(gondolaSeq[A]<0)
			 		gondolaSeq[A]+=N;
			 }
			 gondolaSeq[A]=arr[A];
			 for(int B=A+1;B<N;B++)
			 {
			 	gondolaSeq[A]++;
			 	if(gondolaSeq[A]>=N)
			 		gondolaSeq[A]=0;
			 	arr[B]=gondolaSeq[A];
			 }
			 gondolaSeq[A]=arr[A]+1;
		 	 break;
		}
  	}
  	for(int A=0;A<N;A++)
  		arr[A]++;
  	for(int A=0;A<N;A++)
  	{
  		fre[gondolaSeq[A]]++;
  		mx=max(mx,gondolaSeq[A]);
  		present.push(mp(gondolaSeq[A],A));
  		if(arr[A]!=gondolaSeq[A])
  			change++;
  	}
  	for(int A=1;A<=mx;A++)
  	{
  		if(!fre[A])
  			absent.push(A);
  	}
  	while(!present.empty())
  	{
  		cur=present.top();
  		if(cur.first<=N+change)
  			break;
  		present.pop();
  		sec=absent.top();
  		present.push(mp(sec,cur.second));
  		absent.pop();
  		//cout<<cur.second<<" "<<cur.first<<" "<<sec<<"\n";
  		vec.pb(sec);
  	}
  	while(!present.empty())
  	{
  		cur=present.top();
  		present.pop();	
  		fin[cur.second]=cur.first;
  	}
  	for(int A=0;A<N;A++)
  	{
  		if(fin[A]!=arr[A])
  			present.push(mp(fin[A],arr[A]));
  	}
  	while(!present.empty())
  	{
  		cur=present.top();
  		present.pop();
  		vec.pb(cur.second);
  	}
  	reverse(vec.begin(),vec.end());
  //	for(auto A:vec)
  	//	cout<<A<<" ";
  	for(int A=0;A<vec.size();A++)
  		replacementSeq[A]=vec[A];
  	return vec.size();
}
//----------------------
 
//long long
int countReplacement(int n, int inputSeq[])
{
	if(!valid(n,inputSeq))
		return 0;
	sort(inputSeq,inputSeq+n);
	vector<ll> vec;
	for(int A=0;A<n;A++)
		if(inputSeq[A]>n)
			vec.push_back(inputSeq[A]);
	if(vec.empty())
		return 1;
	sort(vec.begin(),vec.end());
	ll res=1,ptr=0,cnt=vec.size();
	while(ptr<n and inputSeq[ptr]<=n)
		++ptr;
	for(int A=0;A<vec.size()-1;A++)
	{
		while(ptr<n and inputSeq[ptr]<=vec[A])
			++ptr,--cnt;
		//cout<<ptr<<"\n";
		//cout<<vec[A]<<" "<<cnt<<"\n";
		if(vec[A+1]-vec[A]>1)
		{
			res*=power(cnt,vec[A+1]-vec[A]-1);
			res%=mod;
		}
	}
	if(vec[0]!=n+1)
	{
		res*=power((ll)vec.size(),(vec[0]-n-1));
		res%=mod;
	}
	if(inputSeq[0]>n)
	{
		res*=(ll)n;
		res%=mod;
	}
	return res;
}
 
/*signed main()
{
	ios_base::sync_with_stdio(false);
	
	int arr[]={3,4};
	cout<<countReplacement(2,arr);
	return 0;
}*/

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:88:17: error: 'pii' was not declared in this scope
  priority_queue<pii> present;
                 ^~~
gondola.cpp:88:20: error: template argument 1 is invalid
  priority_queue<pii> present;
                    ^
gondola.cpp:88:20: error: template argument 2 is invalid
gondola.cpp:88:20: error: template argument 3 is invalid
gondola.cpp:89:6: error: expected ';' before 'cur'
  pii cur;
      ^~~
gondola.cpp:123:13: error: request for member 'push' in 'present', which is of non-class type 'int'
     present.push(mp(gondolaSeq[A],A));
             ^~~~
gondola.cpp:123:18: error: 'mp' was not declared in this scope
     present.push(mp(gondolaSeq[A],A));
                  ^~
gondola.cpp:123:18: note: suggested alternative: 'mx'
     present.push(mp(gondolaSeq[A],A));
                  ^~
                  mx
gondola.cpp:132:19: error: request for member 'empty' in 'present', which is of non-class type 'int'
    while(!present.empty())
                   ^~~~~
gondola.cpp:134:5: error: 'cur' was not declared in this scope
     cur=present.top();
     ^~~
gondola.cpp:134:17: error: request for member 'top' in 'present', which is of non-class type 'int'
     cur=present.top();
                 ^~~
gondola.cpp:137:13: error: request for member 'pop' in 'present', which is of non-class type 'int'
     present.pop();
             ^~~
gondola.cpp:139:13: error: request for member 'push' in 'present', which is of non-class type 'int'
     present.push(mp(sec,cur.second));
             ^~~~
gondola.cpp:139:18: error: 'mp' was not declared in this scope
     present.push(mp(sec,cur.second));
                  ^~
gondola.cpp:139:18: note: suggested alternative: 'mx'
     present.push(mp(sec,cur.second));
                  ^~
                  mx
gondola.cpp:142:9: error: 'class std::vector<int>' has no member named 'pb'
     vec.pb(sec);
         ^~
gondola.cpp:144:19: error: request for member 'empty' in 'present', which is of non-class type 'int'
    while(!present.empty())
                   ^~~~~
gondola.cpp:146:5: error: 'cur' was not declared in this scope
     cur=present.top();
     ^~~
gondola.cpp:146:17: error: request for member 'top' in 'present', which is of non-class type 'int'
     cur=present.top();
                 ^~~
gondola.cpp:147:13: error: request for member 'pop' in 'present', which is of non-class type 'int'
     present.pop(); 
             ^~~
gondola.cpp:148:5: error: 'fin' was not declared in this scope
     fin[cur.second]=cur.first;
     ^~~
gondola.cpp:148:5: note: suggested alternative: 'sin'
     fin[cur.second]=cur.first;
     ^~~
     sin
gondola.cpp:152:8: error: 'fin' was not declared in this scope
     if(fin[A]!=arr[A])
        ^~~
gondola.cpp:152:8: note: suggested alternative: 'sin'
     if(fin[A]!=arr[A])
        ^~~
        sin
gondola.cpp:153:14: error: request for member 'push' in 'present', which is of non-class type 'int'
      present.push(mp(fin[A],arr[A]));
              ^~~~
gondola.cpp:153:19: error: 'mp' was not declared in this scope
      present.push(mp(fin[A],arr[A]));
                   ^~
gondola.cpp:153:19: note: suggested alternative: 'mx'
      present.push(mp(fin[A],arr[A]));
                   ^~
                   mx
gondola.cpp:155:19: error: request for member 'empty' in 'present', which is of non-class type 'int'
    while(!present.empty())
                   ^~~~~
gondola.cpp:157:5: error: 'cur' was not declared in this scope
     cur=present.top();
     ^~~
gondola.cpp:157:17: error: request for member 'top' in 'present', which is of non-class type 'int'
     cur=present.top();
                 ^~~
gondola.cpp:158:13: error: request for member 'pop' in 'present', which is of non-class type 'int'
     present.pop();
             ^~~
gondola.cpp:159:9: error: 'class std::vector<int>' has no member named 'pb'
     vec.pb(cur.second);
         ^~
gondola.cpp:164:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int A=0;A<vec.size();A++)
                ~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:186:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=0;A<vec.size()-1;A++)
              ~^~~~~~~~~~~~~