답안 #1102901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102901 2024-10-19T08:26:04 Z alexander707070 곤돌라 (IOI14_gondola) C++14
75 / 100
15 ms 8276 KB
#include<bits/stdc++.h>
#include "gondola.h"

#define MAXN 500007
using namespace std;

const long long mod=1e9+9;

int n,pos;
int s[MAXN],last,maxs,where[MAXN],val[MAXN];
bool li[MAXN],dali;
long long ways;

int valid(int N, int inputSeq[]){
	n=N;

	int mins=1;
	for(int i=1;i<=n;i++){
		s[i]=inputSeq[i-1];
		s[i+n]=s[i];

		if(s[i]<s[mins]){
			mins=i;
		}
	}

	for(int i=mins;i<mins+n;i++){
		if(s[i]<=n and s[i]!=s[mins]+i-mins)return 0;

		if(s[i]>n){
			if(li[s[i]])return 0;
			li[s[i]]=true;
		}
	}

	return 1;
}

int replacement(int N, int gondolaSeq[], int replacementSeq[]){
	n=N;

	maxs=1;
	for(int i=1;i<=n;i++){
		s[i]=gondolaSeq[i-1];
		
		if(s[i]>s[maxs])maxs=i;
		if(s[i]<=n)pos=i;

		where[s[i]]=i;
	}

	if(pos==0){
		for(int i=1;i<=n;i++)val[i]=i;
	}else{
		for(int i=pos;i<=n;i++)val[i]=s[pos]+i-pos;
		for(int i=1;i<pos;i++)val[i]=val[n]+i;

		for(int i=1;i<=n;i++){
			if(val[i]>n)val[i]-=n;
		}
	}

	for(int i=n+1;i<=s[maxs];i++){
		if(where[i]==0){
			replacementSeq[i-n-1]=val[maxs];
			val[maxs]=i;
		}else{
			replacementSeq[i-n-1]=val[where[i]];
			val[where[i]]=i;
		}
	}

	return s[maxs]-n;
}

long long power(long long a,int b){
	if(b==0)return 1;
	if(b==1)return a;
	if(b==2)return (a*a)%mod;
	if(b%2==0)return power(power(a,b/2),2);
	return (power(power(a,b/2),2)*a)%mod;
}

int countReplacement(int N, int inputSeq[]){
	n=N;

	for(int i=1;i<=n;i++){
		s[i]=inputSeq[i-1];
	}

	sort(s+1,s+n+1);

	ways=1; last=n;
	for(int i=1;i<=n;i++){
		if(s[i]<=n)continue;

		ways*=power(n-i+1,s[i]-last-1);
		ways%=mod;

		last=s[i];
	}

	return ways;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2556 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 4 ms 2640 KB Output is correct
7 Correct 7 ms 2800 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 6 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 3 ms 2640 KB Output is correct
7 Correct 7 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 7 ms 2616 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 4 ms 2640 KB Output is correct
14 Correct 1 ms 2400 KB Output is correct
15 Correct 7 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6656 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6648 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6596 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6648 KB Output is correct
8 Correct 2 ms 6484 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6536 KB Output is correct
11 Correct 7 ms 6736 KB Output is correct
12 Correct 9 ms 7248 KB Output is correct
13 Correct 8 ms 7248 KB Output is correct
14 Correct 8 ms 6688 KB Output is correct
15 Correct 15 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2556 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2400 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 12 ms 3156 KB Output is correct
10 Correct 10 ms 2996 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 5 ms 2644 KB Output is correct
13 Incorrect 2 ms 2508 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2560 KB Output is correct
5 Correct 1 ms 2556 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 13 ms 3156 KB Output is correct
10 Correct 10 ms 3064 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 8 ms 2620 KB Output is correct
13 Incorrect 2 ms 2388 KB Output isn't correct
14 Halted 0 ms 0 KB -