답안 #14758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14758 2015-06-21T13:48:47 Z progressive 곤돌라 (IOI14_gondola) C++
75 / 100
26 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=1e9+9;
static int pow(int a,int b)
{
	if(b==0) return 1;
	int res=pow(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 usin=p.size(); //using is keyword :(
	int ginputed=n; //max gondola input
	int ans=1;
	for(int i=0;i<p.size();i++)
	{
		ans=(ans*pow(usin--,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 5 ms 2972 KB Output is correct
7 Correct 23 ms 3356 KB Output is correct
8 Correct 17 ms 3356 KB Output is correct
9 Correct 6 ms 2712 KB Output is correct
10 Correct 22 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 10 ms 2972 KB Output is correct
7 Correct 24 ms 3356 KB Output is correct
8 Correct 15 ms 3356 KB Output is correct
9 Correct 7 ms 2712 KB Output is correct
10 Correct 17 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 10 ms 2972 KB Output is correct
14 Correct 0 ms 2584 KB Output is correct
15 Correct 23 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 17 ms 3604 KB Output is correct
12 Correct 16 ms 3604 KB Output is correct
13 Correct 24 ms 3348 KB Output is correct
14 Correct 12 ms 3604 KB Output is correct
15 Correct 26 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 Incorrect 21 ms 3356 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 21 ms 3356 KB Output isn't correct
10 Halted 0 ms 0 KB -