Submission #702160

# Submission time Handle Problem Language Result Execution time Memory
702160 2023-02-23T06:51:00 Z mychecksedad Gondola (IOI14_gondola) C++17
100 / 100
68 ms 6008 KB
#include <bits/stdc++.h>
#include <gondola.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000009;

ll po(ll a, ll b){ll res = 1; while(b){if(b&1) (res*=a)%=MOD; b>>=1; (a*=a)%=MOD;} return res;}

int valid(int n, int a[]){
	map<int, bool> m;
	for(int i = 0; i < n; ++i){
		if(m[a[i]]){
			return 0;
		}
		m[a[i]] = 1;
	}
	int mn = -1;
	for(int i = 0; i < n; ++i){
		if(a[i] <= n){
			mn = mn == -1 ? i : (a[mn] < a[i] ? mn : i);
		}
	}
	if(mn == -1) return 1;
	int s = a[mn];
	bool ok = 1;
	for(int i = mn; i != mn || ok; (i += 1) %= n, s++){
		if(s == n + 1) s = 1;
		ok = 0;
		if(a[i] <= n && a[i] != s){
			return 0;
		}
	}
	return 1;
}

int replacement(int n, int a[], int r[]){
	int l = 0, mn = -1;
	for(int i = 0; i < n; ++i){
		if(a[i] <= n){
			mn = mn == -1 ? i : (a[mn] < a[i] ? mn : i);
		}
	}
	int s;
	if(mn == -1)
		mn = 0, s = 1;
	else
		s = a[mn];
	bool ok = 1;
	set<array<int, 2>> S;
	for(int i = mn; i != mn || ok; (i += 1) %= n, s++){
		if(s == n + 1) s = 1;
		ok = 0;
		if(a[i] > n){
			S.insert({a[i], i});
			a[i] = s;
		}
	}
	for(int i = n + 1; !S.empty(); ){
		auto v = *S.begin();
		S.erase(S.begin());
		while(i <= v[0]){
			r[l] = a[v[1]];
			a[v[1]] = i;
			l++;
			i++;
		}
	}
	return l;
}

int countReplacement(int n, int a[]){
	if(valid(n, a) == 0){
		return 0;
	}
	vector<ll> v;
	for(int i = 0; i < n; ++i){
		if(a[i] > n)
			v.push_back(a[i]);
	}
	v.push_back(n);
	sort(v.begin(), v.end());
	ll ans = 1;
	for(int i = 1; i < v.size(); ++i){
		(ans *= po(ll(v.size() - i), v[i] - v[i - 1] - 1)) %= MOD;
		// cout << v.size() - i << ' ' <<  v[i] - v[i - 1] - 1 << '\n';
	}
	int mn = *min_element(a, a + n);
	return (ans * ll(mn > n ? n : 1)) % MOD;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:83:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for(int i = 1; i < v.size(); ++i){
      |                 ~~^~~~~~~~~~
# 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 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 16 ms 2132 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 29 ms 4032 KB Output is correct
9 Correct 8 ms 1364 KB Output is correct
10 Correct 28 ms 4468 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 1 ms 212 KB Output is correct
6 Correct 13 ms 2132 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 22 ms 3892 KB Output is correct
9 Correct 8 ms 1472 KB Output is correct
10 Correct 32 ms 4524 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 15 ms 2024 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 37 ms 4556 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 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 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 0 ms 212 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 0 ms 224 KB Output is correct
3 Correct 0 ms 220 KB Output is correct
4 Correct 0 ms 220 KB Output is correct
5 Correct 0 ms 228 KB Output is correct
6 Correct 1 ms 220 KB Output is correct
7 Correct 1 ms 216 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 604 KB Output is correct
12 Correct 8 ms 604 KB Output is correct
13 Correct 18 ms 2524 KB Output is correct
14 Correct 8 ms 604 KB Output is correct
15 Correct 20 ms 2792 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
# 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 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 1 ms 212 KB Output is correct
8 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 1 ms 212 KB Output is correct
4 Correct 0 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 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 37 ms 3924 KB Output is correct
10 Correct 34 ms 3296 KB Output is correct
11 Correct 11 ms 1372 KB Output is correct
12 Correct 14 ms 1668 KB Output is correct
13 Correct 3 ms 596 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 42 ms 3988 KB Output is correct
10 Correct 31 ms 3360 KB Output is correct
11 Correct 12 ms 1444 KB Output is correct
12 Correct 16 ms 1600 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 53 ms 5252 KB Output is correct
15 Correct 68 ms 6008 KB Output is correct
16 Correct 9 ms 1364 KB Output is correct
17 Correct 45 ms 4300 KB Output is correct
18 Correct 21 ms 2668 KB Output is correct