답안 #298002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298002 2020-09-12T09:27:46 Z Plurm 곤돌라 (IOI14_gondola) C++11
100 / 100
70 ms 6456 KB
#include "gondola.h"
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
bool flag = false;
int valid(int n, int inputSeq[])
{
	int offs = 0;
	for(int i = 0; i < n; i++){
		if(inputSeq[i] <= n) offs = (n+i-inputSeq[i]+1) % n;
	}
	for(int i = 0; i < n; i++){
		if(flag){
			if(inputSeq[(i+offs) % n] <= n && inputSeq[(i+offs) % n] != i+1) return 0;
		}else{
			if(inputSeq[(i+offs) % n] != i+1) return 0;
		}
	}
	return 1;
}

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

int expect[250005];
int initSeq[100005];
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int offs = 0;
	int dummy = 0;
	int mx = -1;
	memset(expect, -1, sizeof(expect));
	for(int i = 0; i < n; i++){
		if(gondolaSeq[i] <= n) offs = (n+i-gondolaSeq[i]+1) % n;
		else expect[gondolaSeq[i]] = i;
		if(gondolaSeq[i] > mx){
			mx = gondolaSeq[i];
			dummy = i;
		}
	}
	for(int i = 0; i < n; i++){
		initSeq[(i+offs) % n] = i+1;
	}
	int rpidx = 0;
	for(int i = n+1; i <= mx; i++){
		if(expect[i] == -1){
			replacementSeq[rpidx++] = initSeq[dummy];
			initSeq[dummy] = i;
		}else{
			replacementSeq[rpidx++] = initSeq[expect[i]];
			initSeq[expect[i]] = i;
		}
	}
	return rpidx;
}

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

const int MOD = 1e9+9;
int upow(int b, int e){
	if(e == 0) return 1;
	int r = upow(b, e/2);
	r = 1ll * r * r % MOD;
	if(e % 2 == 1) r = 1ll * r * b % MOD;
	return r;
}
int countReplacement(int n, int inputSeq[])
{
	flag = true;
	if(!valid(n, inputSeq)) return 0;
	flag = false;
	int offs = -1;
	int dummy = 0;
	int mx = -1;
	int dcnt = 0;
	map<int,int> expect;
	for(int i = 0; i < n; i++){
		if(inputSeq[i] <= n) offs = (n+i-inputSeq[i]+1) % n;
		else expect[inputSeq[i]] = i;
		if(inputSeq[i] > mx){
			mx = inputSeq[i];
			dummy = i;
		}
	}
	int ans = offs == -1 ? n : 1;
	if(offs == -1) offs = 0;
	for(int i = 0; i < n; i++){
		initSeq[(i+offs) % n] = i+1;
	}
	for(int i = 0; i < n; i++){
		if(initSeq[i] == inputSeq[i]) dcnt++;
	}
	int last = n;
	for(auto p : expect){
		ans = 1ll * ans * upow(n-dcnt, p.first - 1 - last) % MOD;
		dcnt++;
		last = p.first;
	}
	return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:73:6: warning: variable 'dummy' set but not used [-Wunused-but-set-variable]
   73 |  int dummy = 0;
      |      ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 14 ms 1152 KB Output is correct
8 Correct 11 ms 1024 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 13 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 14 ms 1152 KB Output is correct
8 Correct 12 ms 1024 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 13 ms 1152 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 15 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1280 KB Output is correct
2 Correct 1 ms 1280 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1280 KB Output is correct
2 Correct 1 ms 1280 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1280 KB Output is correct
6 Correct 1 ms 1280 KB Output is correct
7 Correct 1 ms 1312 KB Output is correct
8 Correct 2 ms 1280 KB Output is correct
9 Correct 1 ms 1280 KB Output is correct
10 Correct 2 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1280 KB Output is correct
2 Correct 1 ms 1280 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1280 KB Output is correct
6 Correct 1 ms 1280 KB Output is correct
7 Correct 1 ms 1280 KB Output is correct
8 Correct 2 ms 1280 KB Output is correct
9 Correct 2 ms 1408 KB Output is correct
10 Correct 2 ms 1280 KB Output is correct
11 Correct 13 ms 2304 KB Output is correct
12 Correct 15 ms 2560 KB Output is correct
13 Correct 16 ms 2432 KB Output is correct
14 Correct 13 ms 2304 KB Output is correct
15 Correct 24 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 41 ms 3636 KB Output is correct
10 Correct 28 ms 2808 KB Output is correct
11 Correct 12 ms 1536 KB Output is correct
12 Correct 14 ms 1792 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 41 ms 3576 KB Output is correct
10 Correct 30 ms 2808 KB Output is correct
11 Correct 12 ms 1536 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 63 ms 4856 KB Output is correct
15 Correct 70 ms 6456 KB Output is correct
16 Correct 10 ms 1408 KB Output is correct
17 Correct 44 ms 4472 KB Output is correct
18 Correct 22 ms 2560 KB Output is correct