Submission #899253

# Submission time Handle Problem Language Result Execution time Memory
899253 2024-01-05T16:19:33 Z aqxa Gondola (IOI14_gondola) C++17
100 / 100
69 ms 6740 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; 

#include "gondola.h"

int valid(int n, int a[]) {
  	set<int> st; 
	set<int> xs; 
	for (int i = 0; i < n; ++i) {
		if (a[i] <= n) {
			st.insert((a[i] - i + n) % n); 
		}
		if (xs.find(a[i]) != xs.end()) return 0; 
		xs.insert(a[i]); 
	}
	return (st.size() > 1 ? 0 : 1); 
}

//----------------------

int replacement(int n, int a[], int ans[]) {
	int v = 1; 
	for (int i = 0; i < n; ++i) {
		if (a[i] <= n) {
			v = (a[i] - i + n) % n; 
		}
	}
	vector<int> b(n); 
	for (int i = 0; i < n; ++i) {
		b[i] = (v + i + n) % n; 
		if (b[i] == 0) b[i] = n; 
	}
	set<pair<int, int>> xs; 
	for (int i = 0; i < n; ++i) {
		if (a[i] > n) xs.insert({a[i], i}); 
	}

	int l = 0, last = n; 
	for (auto [x, p]: xs) {
		while (b[p] < x) {
			ans[l++] = b[p]; 
			b[p] = ++last; 
		}
	}

	// for (int i = 0; i < l; ++i) {
	// 	cout << ans[i] << " \n"[i + 1 == l]; 
	// }

  	return l;
}

//----------------------

const int M = 1e9 + 9; 

ll pw(ll x, ll e) {
	ll res = 1; 
	ll cur = x; 
	for (int b = 0; b < 30; ++b) {
		if ((1LL << b) & e) {
			res = (res * cur) % M; 
		}
		cur = (cur * cur) % M; 
	}
	return res; 
}

int countReplacement(int n, int a[]) {
  	if (!valid(n, a)) return -1; 
	int ok = 0, v = 1; 
	ll cp = 0; 
	set<ll> st; 
	for (int i = 0; i < n; ++i) {
		if (a[i] <= n) {
			v = (a[i] - i + n) % n; 
			ok = 1; 
		} else {
			cp++; 
			st.insert(a[i]); 
		}
	}
	ll ans = 1; 

	ll last = n; 
	for (ll x: st) {
		ll cnt = x - last - 1; 
		ans = (ans * (pw(cp, cnt))) % M; 
		cp--; 
		last = x; 
	}

	if (!ok) ans = (ans * n) % M; 

	return (int) (ans % M); 
}

// int32_t main() {
// 	ios::sync_with_stdio(false);
// 	cin.tie(nullptr);
	
// 	int t; 
// 	cin >> t; 
// 	while (t--) {
// 		int n; 
// 		cin >> n; 
// 		int a[n]; 
// 		for (int i = 0; i < n; ++i) cin >> a[i]; 
// 		cout << countReplacement(n, a) << "\n";
// 	}
 
// 	return 0; 
// }	 

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:73:14: warning: variable 'v' set but not used [-Wunused-but-set-variable]
   73 |  int ok = 0, v = 1;
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 12 ms 2140 KB Output is correct
7 Correct 6 ms 804 KB Output is correct
8 Correct 19 ms 4296 KB Output is correct
9 Correct 6 ms 1628 KB Output is correct
10 Correct 24 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 10 ms 2136 KB Output is correct
7 Correct 6 ms 780 KB Output is correct
8 Correct 20 ms 4444 KB Output is correct
9 Correct 6 ms 1628 KB Output is correct
10 Correct 24 ms 4944 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 12 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 41 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 856 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 16 ms 2516 KB Output is correct
14 Correct 6 ms 856 KB Output is correct
15 Correct 17 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 47 ms 4156 KB Output is correct
10 Correct 35 ms 3404 KB Output is correct
11 Correct 13 ms 1368 KB Output is correct
12 Correct 16 ms 1832 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 4160 KB Output is correct
10 Correct 36 ms 3520 KB Output is correct
11 Correct 13 ms 1372 KB Output is correct
12 Correct 16 ms 1728 KB Output is correct
13 Correct 4 ms 768 KB Output is correct
14 Correct 61 ms 4700 KB Output is correct
15 Correct 69 ms 5228 KB Output is correct
16 Correct 10 ms 1116 KB Output is correct
17 Correct 43 ms 3676 KB Output is correct
18 Correct 24 ms 2300 KB Output is correct