Submission #120608

# Submission time Handle Problem Language Result Execution time Memory
120608 2019-06-25T05:16:07 Z turbat Gondola (IOI14_gondola) C++14
100 / 100
128 ms 11508 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define N 2000005

map <int, int> pos, note;
int arr[N], mx, cnt, p;
bool can;
long long mod = 1e9 + 9, ans = 1;
vector <int> vc;

int valid(int n, int inputSeq[]){
	for (int i = 0;i < n;i++){
		if (mx < inputSeq[i]){
			mx = inputSeq[i];
			p = i;
		}
		pos[inputSeq[i]] = i;
		if (note[inputSeq[i]]) return 0;
		note[inputSeq[i]] = 1;
	}
	for (int i = 0;i < n;i++)
		if (inputSeq[i] <= n){
			can = 1;
			int now = inputSeq[i];
			arr[i] = now;
			for (int j = i + 1;j < n;j++){
				now++;
				if (now > n) now = 1;
				arr[j] = now;
			}
			for (int j = 0;j < i;j++){
				now++;
				if (now > n) now = 1;
				arr[j] = now;
			}
			break;
		}
	if (!can)
		for (int i = 0;i < n;i++)
			arr[i] = i + 1;
	int ok = 1;
	for (int i = 0;i < n;i++)
		if (inputSeq[i] <= n && inputSeq[i] != arr[i])
			ok = 0;
	return ok;
}


int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	if (!valid(n, gondolaSeq)) return 0;
	for (int i = 0;i < n;i++)
		if (gondolaSeq[i] > n)
			vc.push_back(gondolaSeq[i]);
	for (int i = n + 1;i <= mx;i++){
		if (!note[i]) {
			replacementSeq[i - n - 1] = arr[p];
			arr[p] = i;
		}
		else replacementSeq[i - n - 1] = arr[pos[i]];
	}
	return mx - n;
}

long long gg(long long x, int y){
	long long s = 1;
	while (y){
		if (y % 2) s = (s * x) % mod;
		x = (1ll * x * x) % mod;
		y /= 2;
	}
	return s;
}

int countReplacement(int n, int inputSeq[]){
	if (!valid(n, inputSeq)) return 0;
	if (!can) ans = n;
	for (int i = 0;i < n;i++)
		if (inputSeq[i] > n)
			vc.push_back(inputSeq[i]);
	sort(vc.begin(), vc.end());
	reverse(vc.begin(), vc.end());
	int bef = n;
	while (!vc.empty()){
		ans = (ans * gg(vc.size(), vc.back() - bef - 1)) % mod;
		bef = vc.back();
		vc.pop_back();
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 324 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 26 ms 4096 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 53 ms 7664 KB Output is correct
9 Correct 16 ms 2688 KB Output is correct
10 Correct 64 ms 8824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 26 ms 4088 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 50 ms 7544 KB Output is correct
9 Correct 15 ms 2724 KB Output is correct
10 Correct 85 ms 8952 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 304 KB Output is correct
13 Correct 37 ms 3960 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 103 ms 9080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 59 ms 8312 KB Output is correct
12 Correct 72 ms 9592 KB Output is correct
13 Correct 62 ms 6648 KB Output is correct
14 Correct 65 ms 8440 KB Output is correct
15 Correct 69 ms 11000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 85 ms 8188 KB Output is correct
10 Correct 64 ms 6904 KB Output is correct
11 Correct 22 ms 2816 KB Output is correct
12 Correct 27 ms 3328 KB Output is correct
13 Correct 9 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 90 ms 8184 KB Output is correct
10 Correct 69 ms 6904 KB Output is correct
11 Correct 26 ms 2816 KB Output is correct
12 Correct 30 ms 3320 KB Output is correct
13 Correct 8 ms 1152 KB Output is correct
14 Correct 119 ms 9596 KB Output is correct
15 Correct 128 ms 11508 KB Output is correct
16 Correct 18 ms 2560 KB Output is correct
17 Correct 88 ms 7928 KB Output is correct
18 Correct 40 ms 4728 KB Output is correct