답안 #809130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
809130 2023-08-05T18:06:13 Z OrazB 곤돌라 (IOI14_gondola) C++14
100 / 100
48 ms 10056 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

const int N = 1e5+5;
int T[N]; 

int valid(int n, int A[]){
	map<int,int> mp;
	int pos = -1;
	for (int i = 0; i < n; i++){
		if (mp[A[i]]++) return 0;
		if (A[i] <= n){pos = i;break;}
	}
	if (pos == -1) return 1;
	int x = A[pos];
	for (int i = pos; i < n; i++){
		if (i > pos and mp[A[i]]++) return 0;
		if (A[i] <= n and A[i] != x) return 0;
		x++;
		if (x == n+1) x = 1;
	}
	return 1;
}

int replacement(int n, int A[], int replacementSeq[]){
	int x = valid(n, A);
	for (int i = 0; i < n; i++){
		T[i] = i+1;
	}
	int pos = -1;
	for (int i = 0; i < n; i++){
		if (A[i] <= n){pos = i;break;}
	}
	if (pos != -1){
		int x = A[pos];
		for (int i = pos; i >= 0; i--){
			T[i] = x;
			x--;
			if (!x) x = n;
		}
		x = A[pos];
		for (int i = pos; i < n; i++){
			T[i] = x;
			x++;
			if (x == n+1) x = 1;
		}
	}
	int mx = 0, ind = 0;
	map <int,int> idx;
	for (int i = 0; i < n; i++){
		idx[A[i]] = i+1;
		if (mx < A[i]){
			mx = A[i];
			ind = i;
		}
	}
	for (int i = n+1; i <= mx; i++){
		if (idx[i]){
			replacementSeq[i-n-1] = T[idx[i]-1];
		}else{
			replacementSeq[i-n-1] = T[ind];
			T[ind] = i;
		}
	}
	return mx-n;
}

const int mod = 1000000009;

int F(int x, int y){
	int res = 1;
	while(y){
		if (y&1) res = (res*1ll*x)%mod;
		x = (x*1ll*x)%mod;
		y /= 2;
	}
	return res;
}

int countReplacement(int n, int A[]){
	if (!valid(n, A)) return 0;
	vector<int> vec;
	int ans = 1;
	for (int i = 0; i < n; i++){
		if (A[i] > n) vec.pb(A[i]);
	}
	sort(all(vec));
	int cnt = vec.size();
	if (cnt == n) ans = n;
	int lst = n;
	for (auto i : vec){
		ans = (ans*1ll*F(cnt, i-lst-1))%mod;
		cnt--;
		lst = i;
	}
	return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:33:6: warning: unused variable 'x' [-Wunused-variable]
   33 |  int x = valid(n, A);
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 2128 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 18 ms 3840 KB Output is correct
9 Correct 5 ms 1396 KB Output is correct
10 Correct 16 ms 4540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 2132 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 16 ms 3924 KB Output is correct
9 Correct 4 ms 1364 KB Output is correct
10 Correct 17 ms 4464 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 27 ms 4564 KB Output is correct
12 Correct 27 ms 5232 KB Output is correct
13 Correct 33 ms 4892 KB Output is correct
14 Correct 27 ms 4588 KB Output is correct
15 Correct 42 ms 10056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 29 ms 4408 KB Output is correct
10 Correct 21 ms 3796 KB Output is correct
11 Correct 8 ms 1484 KB Output is correct
12 Correct 12 ms 1860 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 26 ms 4508 KB Output is correct
10 Correct 22 ms 3796 KB Output is correct
11 Correct 8 ms 1472 KB Output is correct
12 Correct 10 ms 1752 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 42 ms 5068 KB Output is correct
15 Correct 48 ms 5664 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 26 ms 4084 KB Output is correct
18 Correct 14 ms 2388 KB Output is correct