답안 #278189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278189 2020-08-21T11:12:45 Z amiratou 곤돌라 (IOI14_gondola) C++14
100 / 100
80 ms 6724 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x.size())
const int MOD =(int)(1e9+9);
typedef long long ll;
int val[100005],p[250005];
set<int> here;

int valid(int n, int inputSeq[])
{
	int idx=-1;
	for (int i = 0; i < n; ++i){
		if(here.find(inputSeq[i])!=here.end())return 0;
		here.insert(inputSeq[i]);
		if(inputSeq[i]<=n)idx=i;
	}
	if(idx==-1)return 1;
	int h=inputSeq[idx];
	for (int i = 0; i < n; ++i)
		val[(idx+i)%n]=((h-1+i)%n)+1;
	for (int i = 0; i < n; ++i)
		if(inputSeq[i]<=n && inputSeq[i]!=val[i])return 0;
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int flag=-1;
	for (int i = 0; i < n; ++i)
		if(gondolaSeq[i]<=n)flag=i;
	priority_queue<int,vector<int>,greater<int> > pq;
	if(flag!=-1){
		int g=gondolaSeq[flag];
		for (int i = 0; i < n; ++i){
			int r=((g-1+i)%n)+1;
			if(gondolaSeq[(flag+i)%n]!=r)pq.push(gondolaSeq[(flag+i)%n]),p[gondolaSeq[(flag+i)%n]]=r;
		}
	}
	else{
		for (int i = 0; i < n; ++i)
			p[gondolaSeq[i]]=i+1,pq.push(gondolaSeq[i]);
	}
	int h=n+1,idx=0;
	while(!pq.empty()){
		int f=pq.top();
		pq.pop();
		replacementSeq[idx++]=p[f];
		while(h<f)replacementSeq[idx++]=h++;
		h++;
	}
	return idx;
}

//----------------------
int binpow(int a,int b){
	if(!b)return 1;
	ll h=binpow(a,b>>1);
	h*=h;
	if(h>=MOD)h%=MOD;
	if(b&1)h*=a;
	if(h>=MOD)h%=MOD;
	return (int)(h);
}

int countReplacement(int n, int inputSeq[])
{
	if(!valid(n,inputSeq))return 0;
	vector<int> vec={n};
	bool flag=0;
	for (int i = 0; i < n; ++i){
		if(inputSeq[i]>n)
			vec.push_back(inputSeq[i]);
		else flag=1;
	}
	ll ans=1;
	sort(vec.begin(),vec.end());
	for (int i = 1; i < sz(vec); ++i)
		ans=(ans*(ll)binpow(sz(vec)-i,vec[i]-vec[i-1]-1))%MOD;
	return (ans*((!flag)?n:1))%MOD;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 18 ms 2328 KB Output is correct
7 Correct 14 ms 640 KB Output is correct
8 Correct 31 ms 4292 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 45 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 35 ms 2424 KB Output is correct
7 Correct 17 ms 768 KB Output is correct
8 Correct 32 ms 4216 KB Output is correct
9 Correct 11 ms 1536 KB Output is correct
10 Correct 35 ms 4944 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 20 ms 2304 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 66 ms 5048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 17 ms 640 KB Output is correct
12 Correct 14 ms 640 KB Output is correct
13 Correct 20 ms 1544 KB Output is correct
14 Correct 12 ms 640 KB Output is correct
15 Correct 39 ms 2740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 55 ms 4872 KB Output is correct
10 Correct 41 ms 4216 KB Output is correct
11 Correct 14 ms 1792 KB Output is correct
12 Correct 27 ms 2168 KB Output is correct
13 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 50 ms 4856 KB Output is correct
10 Correct 42 ms 4224 KB Output is correct
11 Correct 17 ms 1792 KB Output is correct
12 Correct 24 ms 2168 KB Output is correct
13 Correct 4 ms 768 KB Output is correct
14 Correct 68 ms 6008 KB Output is correct
15 Correct 80 ms 6724 KB Output is correct
16 Correct 17 ms 1536 KB Output is correct
17 Correct 45 ms 4608 KB Output is correct
18 Correct 39 ms 2808 KB Output is correct