답안 #14761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14761 2015-06-21T14:05:39 Z progressive 곤돌라 (IOI14_gondola) C++
100 / 100
30 ms 3604 KB
#include "gondola.h"
#include <vector>
#include <algorithm>
using namespace std;

int valid(int n, int inputSeq[])
{
	//duplication check
	vector<int> dupe;
	for(int i=0;i<n;i++)
		dupe.push_back(inputSeq[i]);
	sort(dupe.begin(),dupe.end());
	for(int i=0;i<n-1;i++)
		if(dupe[i]==dupe[i+1]) return 0;


	//rotatable check
	int key=-1;
	for(int i=0;i<n;i++)
		if(inputSeq[i]<=n)
			key=i;
	
	if(key==-1) return 1;

	for(int i=0;i<n;i++)
	{
		if(inputSeq[i]>n) continue;
		if((inputSeq[i]-inputSeq[key]+n)%n!=(i-key+n)%n) return 0;
		//do not have same diff
	}
	
	return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	if(!valid(n,gondolaSeq)) return 0;
	
	int key=0;
	for(int i=0;i<n;i++)
		if(gondolaSeq[i]<=n)
			key=i;
	
	vector<int> newSeq;
	for(int i=0;i<n;i++)
		newSeq.push_back((i+(gondolaSeq[key]-1)-key+n)%n+1);
	
	vector<pair<int,int> > targetSeq;
	for(int i=0;i<n;i++)
		if(gondolaSeq[i]>n) targetSeq.push_back(make_pair(gondolaSeq[i],i));		
	sort(targetSeq.begin(),targetSeq.end());
	
	int tp=0; //top, return value
	for(int i=0;i<targetSeq.size();i++)
	{
		int ind=targetSeq[i].second;
		int val=targetSeq[i].first;
		while(tp+n<val)
		{
			replacementSeq[tp++]=newSeq[ind];
			newSeq[ind]=tp+n;
		}
	}
	return tp;
}

//----------------------

static const int mod=1000000009;
static int getpow(int a,int b)
{
	if(b==0) return 1;
	long long res=getpow(a,b/2);
	res=(1LL*res*res)%mod;
	if(b%2==1) res=(1LL*res*a)%mod;
	return res;
}
int countReplacement(int n, int inputSeq[])
{
	if(!valid(n,inputSeq)) return 0;
	vector<int> p;	
	for(int i=0;i<n;i++)
		if(inputSeq[i]>n)
			p.push_back(inputSeq[i]);
	
	sort(p.begin(),p.end());
	
	int ginputed=n; //max gondola input
	long long ans=1LL;
	if(p.size()==n) ans=n;
	for(int i=0;i<p.size();i++)
	{
		ans=(1LL*ans*getpow(p.size()-i,p[i]-ginputed-1))%mod;
		ginputed=p[i];
	}
	return ans;
}











# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 9 ms 2972 KB Output is correct
7 Correct 23 ms 3356 KB Output is correct
8 Correct 18 ms 3356 KB Output is correct
9 Correct 7 ms 2712 KB Output is correct
10 Correct 17 ms 3356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 9 ms 2972 KB Output is correct
7 Correct 19 ms 3356 KB Output is correct
8 Correct 15 ms 3356 KB Output is correct
9 Correct 0 ms 2712 KB Output is correct
10 Correct 18 ms 3356 KB Output is correct
11 Correct 0 ms 2584 KB Output is correct
12 Correct 0 ms 2584 KB Output is correct
13 Correct 9 ms 2972 KB Output is correct
14 Correct 0 ms 2584 KB Output is correct
15 Correct 24 ms 3356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 0 ms 2584 KB Output is correct
10 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 0 ms 2584 KB Output is correct
10 Correct 0 ms 2584 KB Output is correct
11 Correct 18 ms 3604 KB Output is correct
12 Correct 18 ms 3604 KB Output is correct
13 Correct 17 ms 3348 KB Output is correct
14 Correct 18 ms 3604 KB Output is correct
15 Correct 24 ms 3096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 25 ms 3356 KB Output is correct
10 Correct 19 ms 3092 KB Output is correct
11 Correct 8 ms 2836 KB Output is correct
12 Correct 4 ms 2836 KB Output is correct
13 Correct 2 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 26 ms 3356 KB Output is correct
10 Correct 19 ms 3092 KB Output is correct
11 Correct 4 ms 2836 KB Output is correct
12 Correct 9 ms 2836 KB Output is correct
13 Correct 0 ms 2584 KB Output is correct
14 Correct 29 ms 3604 KB Output is correct
15 Correct 30 ms 3604 KB Output is correct
16 Correct 8 ms 2836 KB Output is correct
17 Correct 20 ms 3092 KB Output is correct
18 Correct 14 ms 3092 KB Output is correct