Submission #1015174

# Submission time Handle Problem Language Result Execution time Memory
1015174 2024-07-06T07:02:21 Z AmirAli_H1 Gondola (IOI14_gondola) C++17
75 / 100
12 ms 6236 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e6 + 4;
const int mod = 1e9 + 9;
int ind[maxn], val[maxn];

int valid(int n, int a[]) {
	int j = -1, mx = 0;
	fill(ind, ind + maxn, -1);
	for (int i = 0; i < n; i++) {
		a[i]--;
		if (ind[a[i]] != -1) return 0;
		else ind[a[i]] = i;
		if (a[i] > a[mx]) mx = i;
		if (a[i] < n) {
			int k = (i - a[i] + n) % n;
			if (j == -1 || j == k) j = k;
			else return 0;
		}
	}
	return 1;
}

int replacement(int n, int a[], int res[]) {
	int j = -1, mx = 0;
	fill(ind, ind + maxn, -1);
	for (int i = 0; i < n; i++) {
		a[i]--;
		if (ind[a[i]] != -1) return 0;
		else ind[a[i]] = i;
		if (a[i] > a[mx]) mx = i;
		if (a[i] < n) {
			int k = (i - a[i] + n) % n;
			if (j == -1 || j == k) j = k;
			else return 0;
		}
	}
	if (j == -1) j = 0;
	
	for (int i = j; i < j + n; i++) val[i % n] = i - j;
	for (int i = n; i <= a[mx]; i++) {
		if (ind[i] != -1) {
			int j = ind[i];
			res[i - n] = val[j] + 1;
			val[j] = i;
		}
		else {
			int j = ind[a[mx]];
			res[i - n] = val[j] + 1;
			val[j] = i;
		}
	}
	return (a[mx] + 1) - n;
}

int countReplacement(int n, int a[]) {
	int j = -1, mx = 0;
	fill(ind, ind + maxn, -1);
	for (int i = 0; i < n; i++) {
		a[i]--;
		if (ind[a[i]] != -1) return 0;
		else ind[a[i]] = i;
		if (a[i] > a[mx]) mx = i;
		if (a[i] < n) {
			int k = (i - a[i] + n) % n;
			if (j == -1 || j == k) j = k;
			else return 0;
		}
	}
	
	ll ans = 1, R = 0;
	for (int i = 0; i < n; i++) {
		if (ind[i] == -1) R++;
	}
	for (int i = n; i <= a[mx]; i++) {
		if (ind[i] == -1) {
			ans *= R; ans %= mod;
		}
		else R--;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 3 ms 4184 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 5 ms 4444 KB Output is correct
7 Correct 9 ms 4700 KB Output is correct
8 Correct 6 ms 4644 KB Output is correct
9 Correct 3 ms 4444 KB Output is correct
10 Correct 7 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4248 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 4 ms 4444 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
8 Correct 7 ms 4444 KB Output is correct
9 Correct 3 ms 4444 KB Output is correct
10 Correct 6 ms 4700 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4324 KB Output is correct
13 Correct 4 ms 4684 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 10 ms 5116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 3 ms 4288 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4252 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4184 KB Output is correct
6 Correct 2 ms 4280 KB Output is correct
7 Correct 3 ms 4288 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4300 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 8 ms 5208 KB Output is correct
12 Correct 8 ms 5468 KB Output is correct
13 Correct 8 ms 5464 KB Output is correct
14 Correct 7 ms 5208 KB Output is correct
15 Correct 12 ms 6236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 3 ms 4184 KB Output is correct
5 Correct 2 ms 4184 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 7 ms 4952 KB Output is correct
10 Correct 7 ms 4956 KB Output is correct
11 Correct 4 ms 4620 KB Output is correct
12 Correct 5 ms 4444 KB Output is correct
13 Incorrect 3 ms 4444 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4184 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 9 ms 4956 KB Output is correct
10 Correct 7 ms 4952 KB Output is correct
11 Correct 4 ms 4440 KB Output is correct
12 Correct 4 ms 4444 KB Output is correct
13 Incorrect 3 ms 4444 KB Output isn't correct
14 Halted 0 ms 0 KB -