Submission #379219

# Submission time Handle Problem Language Result Execution time Memory
379219 2021-03-17T14:19:36 Z Mounir Gondola (IOI14_gondola) C++14
100 / 100
74 ms 6500 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
using namespace std;
 
int valid(int n, int inputSeq[]) {
	vector<int> restant;
	map<int, bool> vu;
	for (int ind = 0; ind < n; ++ind){
		if (vu[inputSeq[ind]])
			return 0;
		vu[inputSeq[ind]] = true;
		if (inputSeq[ind] <= n)
			restant.pb(ind);
	}
 
	for (int ind = 0; ind < sz(restant) - 1; ++ind){
		int a = restant[ind] - inputSeq[restant[ind]], b = restant[ind + 1] - inputSeq[restant[ind + 1]];
		a += n; a %= n;
		b += n; b %= n;
 
		if (a != b)
			return 0;
	}
	return 1;
}
 
//----------------------
 
struct Element {
	int ind, val;
 
	bool operator < (const Element &autre) const {
		return val < autre.val;
	}
};
 
int get(int id, int deb, int n){
	if (id > deb)
		return id - deb;
	else
		return n - deb + id;
}
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	int maxi = 0, deb = 0;
	set<Element> reste;
	for (int ind = 0; ind < n; ++ind){
		chmax(maxi, gondolaSeq[ind]);
		if (gondolaSeq[ind] > n){
			//cout << "val " << ind << " " << gondolaSeq[ind] << endl;
			reste.insert({ind, gondolaSeq[ind]});
		}
		else
			deb = (ind -gondolaSeq[ind] + n)%n;
	}
 
	vector<int> actu(n);
	for (int i = 0; i < n; ++i)
		actu[i] = get(i, deb, n);
 
	for (int tour = n + 1; tour <= maxi; ++tour){
		int id = reste.begin()->ind;
		replacementSeq[tour - n - 1] = actu[id];
		actu[id] = tour;
		reste.erase(reste.begin());
		if (tour != gondolaSeq[id])
			reste.insert({id, tour});
	}
	return maxi - n;
}
 
//----------------------
 
const int MOD = 1e9 + 9;
 
long long fastExpo(int val, int exposant){
	if (exposant == 0)
		return 1;
	if (exposant == 1)
		return val;
	long long res = fastExpo(val, exposant/2);
	res = (res * res)%MOD;
	if (exposant%2 == 1)
		res = (res * val)%MOD;
	return res;
}

int countReplacement(int n, int inputSeq[]){
	long long nb = 1;
	bool entier = true;
	vector<int> reste;
	for (int ind = 0; ind < n; ++ind){
		if (inputSeq[ind] > n)
			reste.pb(inputSeq[ind]);
		else 
			entier = false;
	}
 
 	reste.pb(n);
	sort(all(reste));
	for (int ind = 1; ind < sz(reste); ++ind){
	//	cout << sz(reste) - ind << " " << reste[ind] << " " <<  reste[ind - 1] << endl;
		int a = fastExpo(sz(reste) - ind, reste[ind] - reste[ind - 1] - 1)%MOD;
	//	cout << a << endl << endl;
		nb = (nb * a)%MOD;
	}

	if (entier) nb = (nb * n)%MOD;
	return (valid(n, inputSeq) * (nb + MOD)%MOD)%MOD;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 16 ms 2408 KB Output is correct
7 Correct 12 ms 748 KB Output is correct
8 Correct 31 ms 4200 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 38 ms 4836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 18 ms 2408 KB Output is correct
7 Correct 11 ms 748 KB Output is correct
8 Correct 31 ms 4200 KB Output is correct
9 Correct 9 ms 1516 KB Output is correct
10 Correct 38 ms 4836 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 20 ms 2156 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 52 ms 4968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 11 ms 876 KB Output is correct
12 Correct 12 ms 1004 KB Output is correct
13 Correct 26 ms 2532 KB Output is correct
14 Correct 13 ms 896 KB Output is correct
15 Correct 35 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 49 ms 4328 KB Output is correct
10 Correct 38 ms 3688 KB Output is correct
11 Correct 14 ms 1516 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 5 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 61 ms 4328 KB Output is correct
10 Correct 43 ms 3816 KB Output is correct
11 Correct 14 ms 1516 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 4 ms 748 KB Output is correct
14 Correct 64 ms 4964 KB Output is correct
15 Correct 74 ms 6500 KB Output is correct
16 Correct 11 ms 1516 KB Output is correct
17 Correct 45 ms 4456 KB Output is correct
18 Correct 24 ms 2664 KB Output is correct