답안 #1032095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032095 2024-07-23T11:11:38 Z tolbi 곤돌라 (IOI14_gondola) C++17
100 / 100
47 ms 6812 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[])
{
	map<int,int> mp;
	int p = -1;
	for (int i = 0; i < n; ++i)
	{
		if (mp[inputSeq[i]]) return 0;
		mp[inputSeq[i]]++;
	}
	for (int i = 0; i < n; i++){
		if (inputSeq[i]<=n){
			p=i;
			break;
		}
	}
	if (p==-1) return 1;
	for (int i = 0; i < n; i++){
		if (inputSeq[i]>n) continue;
		int step = i-p;
		if (i<p) step = n-p+i;
		int a = inputSeq[p]-1;
		a+=step;
		a%=n;
		a++;
		if (inputSeq[i]!=a) return 0;
	}
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	pair<int,int> v[n];
	for (int i = 0; i < n; ++i)
	{
		v[i]={gondolaSeq[i],i};
	}
	sort(v,v+n);
	int cnt = 0;
	int p = 0;
	for (int i = 0; i < n; i++){
		if (gondolaSeq[i]<=n){
			p=i-gondolaSeq[i]+1;
			if (p<0) p+=n;
			break;
		}
	}
	for (int i = 0; i < n; i++){
		if (v[i].first<=n) continue;
		int lel = v[i].second-p+1;
		if (v[i].second<p) lel = n-p+v[i].second+1;
		while (cnt<v[i].first-n) {
			replacementSeq[cnt]=lel;
			lel=cnt+n+1;
			cnt++;
		}
	}
	return cnt;
}

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

constexpr int MOD = 1e9+9;
int fpow(int base, int pow){
	int rval = 1;
	while (pow){
		if (pow&1){
			rval=(1LL*rval*base)%MOD;
		}
		base=(1LL*base*base)%MOD;
		pow>>=1;
	}
	return rval;
}
int countReplacement(int n, int inputSeq[])
{
	if (!valid(n,inputSeq)) return 0;
	pair<int,int> v[n];
	int kapali = 0;
	int ans = n;
	for (int i = 0; i < n; ++i)
	{
		if (inputSeq[i]>n) {
			kapali++;
		}
		v[i]={inputSeq[i],i};
	}
	if (kapali!=n) ans=1;
	sort(v,v+n);
	int cnt = 0;
	for (int i = 0; i < n; i++){
		if (v[i].first<=n) continue;
		int kal = n-i;
		ans=(1LL*ans*fpow(kal,max(0,v[i].first-n-cnt-1)))%MOD;
		cnt=v[i].first-n;
		while (cnt<v[i].first-n) {
			cnt++;
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 17 ms 3940 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 22 ms 4480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2136 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 17 ms 3888 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 21 ms 4600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 12 ms 2140 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 31 ms 4796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 8 ms 1368 KB Output is correct
13 Correct 11 ms 1372 KB Output is correct
14 Correct 6 ms 1344 KB Output is correct
15 Correct 12 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 32 ms 4980 KB Output is correct
10 Correct 28 ms 4248 KB Output is correct
11 Correct 9 ms 1736 KB Output is correct
12 Correct 15 ms 2140 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 33 ms 5084 KB Output is correct
10 Correct 30 ms 4440 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 11 ms 2184 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 42 ms 6112 KB Output is correct
15 Correct 47 ms 6812 KB Output is correct
16 Correct 7 ms 1628 KB Output is correct
17 Correct 31 ms 4688 KB Output is correct
18 Correct 17 ms 2904 KB Output is correct