Submission #805691

# Submission time Handle Problem Language Result Execution time Memory
805691 2023-08-03T20:34:12 Z IvanJ Gondola (IOI14_gondola) C++17
100 / 100
35 ms 5908 KB
#include "gondola.h"
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int MOD = 1e9 + 9;

int mult(ll x, ll y) {return x * y % MOD;}
int pot(int n, int k) {
	int ret = 1, pot = n;
	for(;k > 0;k >>= 1, pot = mult(pot, pot)) 
		if(k & 1) ret = mult(ret, pot);
	return ret;
}
int add(int x, int y) {x += y;if(x >= MOD) x -= MOD;return x;}

int valid(int n, int A[]) {
	int pos = -1;
	for(int i = 0;i < n;i++) A[i]--;
	set<int> s;
	for(int i = 0;i < n;i++) s.insert(A[i]);
	if((int)s.size() != n) return 0;
	for(int i = 0;i < n;i++) 
		if(A[i] < n) pos = i;
	if(pos == -1) return 1;
	for(int i = pos;i < pos + n;i++)
		if(A[i % n] < n && A[i % n] != (A[pos] + (i - pos)) % n)
			return 0;
	return 1;
}

int replacement(int n, int A[], int R[]) {
	int maxi = 0;
	for(int i = 0;i < n;i++) 
		maxi = max(maxi, --A[i]);
	
	vector<int> v(maxi + 1, -1);
	for(int i = 0;i < n;i++) 
		v[A[i]] = i;
	
	vector<int> poc;
	for(int i = 0;i < n;i++) poc.pb(i);
	int pos = -1;
	for(int i = 0;i < n;i++) 
		if(A[i] < n) pos = i;
	if(pos != -1) 
		for(int i = pos;i < pos + n;i++) 
			poc[i % n] = (A[pos] + (i - pos)) % n;
	
	pos = -1;
	for(int i = 0;i < n;i++) 
		if(A[i] == maxi) pos = i;
	
	int idx = 0;
	for(int i = n;i <= maxi;i++) {
		if(v[i] != -1) 
			R[idx++] = poc[v[i]] + 1;
		else R[idx++] = poc[pos] + 1, poc[pos] = i;
	}
	return idx;
}

int countReplacement(int n, int A[]) {
	if(!valid(n, A)) return 0;
	
	int flag = 0;
	for(int i = 0;i < n;i++) 
		if(A[i] < n) flag = 1;
	
	vector<int> v;
	for(int i = 0;i < n;i++) 
		if(A[i] >= n) v.pb(A[i]);
	
	sort(all(v));
	int ans = 1;
	int lst = n - 1, cnt = (int)v.size();
	for(int i : v) {
		ans = mult(ans, pot(cnt, i - lst - 1));
		lst = i, cnt--;
	}
	if(flag == 0) ans = mult(ans, n);
	return ans;
}
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2132 KB Output is correct
7 Correct 21 ms 3652 KB Output is correct
8 Correct 15 ms 3928 KB Output is correct
9 Correct 5 ms 1416 KB Output is correct
10 Correct 22 ms 4460 KB Output is correct
# Verdict Execution time Memory 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 8 ms 2132 KB Output is correct
7 Correct 24 ms 3588 KB Output is correct
8 Correct 14 ms 3940 KB Output is correct
9 Correct 5 ms 1472 KB Output is correct
10 Correct 22 ms 4536 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 12 ms 2004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 23 ms 4560 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 236 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 7 ms 1488 KB Output is correct
12 Correct 8 ms 1616 KB Output is correct
13 Correct 9 ms 1360 KB Output is correct
14 Correct 7 ms 1488 KB Output is correct
15 Correct 15 ms 2200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 32 ms 4468 KB Output is correct
10 Correct 21 ms 3700 KB Output is correct
11 Correct 9 ms 1544 KB Output is correct
12 Correct 9 ms 1828 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 25 ms 4424 KB Output is correct
10 Correct 22 ms 3776 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 9 ms 1868 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 31 ms 5308 KB Output is correct
15 Correct 35 ms 5908 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 23 ms 4148 KB Output is correct
18 Correct 12 ms 2488 KB Output is correct