답안 #794758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794758 2023-07-26T21:46:58 Z aymanrs 곤돌라 (IOI14_gondola) C++14
100 / 100
15 ms 2176 KB
#include<bits/stdc++.h>
#include "gondola.h"
const int MOD = 1e9+9;
long long binp(long long a, long long n){
	long long r = 1;
	while(n){
		if(n&1) r = r*a%MOD;
		a = a*a%MOD;
		n>>=1;
	}
	return r;
}
using namespace std;
int valid(int n, int inputSeq[]){
	int p[n+1];
	fill(p, p+n+1, -1);
	vector<int> a;
	a.push_back(n);
	for(int i = 0;i < n;i++) {
		if(inputSeq[i] <= n) {
			if(p[inputSeq[i]] != -1) return 0;
			p[inputSeq[i]] = i;
		}
		else a.push_back(inputSeq[i]);
	}
	sort(a.begin(), a.end());
	bool f = false;
	for(int i = 1;i <= n;i++){
		if(p[i] == -1) continue;
		f = true;
		int pr = i == 1 ? n : i-1;
		if(p[pr] == -1) continue;
		if(p[pr] != (p[i]+n-1)%n) return 0;
	}
	long long ans = 1;
	for(int i = 1;i < a.size();i++){
		if(a[i] == a[i-1]) return 0;
		ans = ans*binp(int(a.size())-i, a[i]-a[i-1]-1)%MOD;
	}	
	if(!f) ans = ans*n%MOD;
	return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	int p1 = 0, o[n];
	for(int i = 0;i < n;i++){
		o[i] = i;
		if(gondolaSeq[i] <= n){
			p1 = (i+n-gondolaSeq[i]+1)%n;
		}
	}
	sort(o, o+n, [&gondolaSeq](int a, int b){return gondolaSeq[a] < gondolaSeq[b];});
	int ind = 0, x = n+1;
	for(int z = 0;z < n;z++){
		int i = o[z];
		if(gondolaSeq[i] <= n) continue;
		replacementSeq[ind++] = (i-p1+n)%n + 1;
		while(x < gondolaSeq[i]){
			replacementSeq[ind++] = x++;
		}
		x++;
	}
	return ind;
}
int countReplacement(int n, int inputSeq[]){
	int p[n+1];
	fill(p, p+n+1, -1);
	vector<int> a;
	a.push_back(n);
	for(int i = 0;i < n;i++) {
		if(inputSeq[i] <= n) {
			if(p[inputSeq[i]] != -1) return 0;
			p[inputSeq[i]] = i;
		}
		else a.push_back(inputSeq[i]);
	}
	sort(a.begin(), a.end());
	bool f = false;
	for(int i = 1;i <= n;i++){
		if(p[i] == -1) continue;
		f = true;
		int pr = i == 1 ? n : i-1;
		if(p[pr] == -1) continue;
		if(p[pr] != (p[i]+n-1)%n) return 0;
	}
	long long ans = 1;
	for(int i = 1;i < a.size();i++){
		if(a[i] == a[i-1]) return 0;
		ans = ans*binp(int(a.size())-i, a[i]-a[i-1]-1)%MOD;
	}	
	if(!f) ans = ans*n%MOD;
	return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i = 1;i < a.size();i++){
      |                ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for(int i = 1;i < a.size();i++){
      |                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 540 KB Output is correct
7 Correct 7 ms 980 KB Output is correct
8 Correct 7 ms 764 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 10 ms 852 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 1 ms 212 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 7 ms 896 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 8 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 8 ms 1108 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 1 ms 232 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 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 8 ms 1364 KB Output is correct
12 Correct 9 ms 1504 KB Output is correct
13 Correct 11 ms 1400 KB Output is correct
14 Correct 8 ms 1364 KB Output is correct
15 Correct 15 ms 2176 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 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
8 Correct 1 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 10 ms 1208 KB Output is correct
10 Correct 8 ms 1112 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 1 ms 340 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 1 ms 212 KB Output is correct
6 Correct 0 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 10 ms 1236 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 13 ms 1488 KB Output is correct
15 Correct 15 ms 1656 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 10 ms 1184 KB Output is correct
18 Correct 6 ms 980 KB Output is correct