Submission #809126

# Submission time Handle Problem Language Result Execution time Memory
809126 2023-08-05T18:01:53 Z OrazB Gondola (IOI14_gondola) C++14
60 / 100
42 ms 10064 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

const int N = 1e5+5;
int T[N]; 

int valid(int n, int A[]){
	map<int,int> mp;
	int pos = -1;
	for (int i = 0; i < n; i++){
		if (mp[A[i]]++) return 0;
		if (A[i] <= n){pos = i;break;}
	}
	if (pos == -1) return 1;
	int x = A[pos];
	for (int i = pos; i < n; i++){
		if (i > pos and mp[A[i]]++) return 0;
		if (A[i] <= n and A[i] != x) return 0;
		x++;
		if (x == n+1) x = 1;
	}
	return 1;
}

int replacement(int n, int A[], int replacementSeq[]){
	int x = valid(n, A);
	for (int i = 0; i < n; i++){
		T[i] = i+1;
	}
	int pos = -1;
	for (int i = 0; i < n; i++){
		if (A[i] <= n){pos = i;break;}
	}
	if (pos != -1){
		int x = A[pos];
		for (int i = pos; i >= 0; i--){
			T[i] = x;
			x--;
			if (!x) x = n;
		}
		x = A[pos];
		for (int i = pos; i < n; i++){
			T[i] = x;
			x++;
			if (x == n+1) x = 1;
		}
	}
	int mx = 0, ind = 0;
	map <int,int> idx;
	for (int i = 0; i < n; i++){
		idx[A[i]] = i+1;
		if (mx < A[i]){
			mx = A[i];
			ind = i;
		}
	}
	for (int i = n+1; i <= mx; i++){
		if (idx[i]){
			replacementSeq[i-n-1] = T[idx[i]-1];
		}else{
			replacementSeq[i-n-1] = T[ind];
			T[ind] = i;
		}
	}
	return mx-n;
}

const ll mod = 1000000009;

int F(int x, int y){
	int res = 1;
	while(y){
		if (y&1) res = (res*1ll*x)%mod;
		x = (x*1ll*x)%mod;
		y /= 2;
	}
	return res;
}

int countReplacement(int n, int A[]){
	if (!valid(n, A)) return 0;
	vector<int> vec;
	int ans = 1;
	for (int i = 0; i < n; i++){
		if (A[i] > n) vec.pb(A[i]);
	}
	sort(all(vec));
	int cnt = vec.size();
	if (cnt == n) ans = n;
	int lst = n;
	for (auto i : vec){
		ans = (ans*1ll*F(cnt, i-lst-1))%mod;
		lst = i;
	}
	return ans;
}	

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:33:6: warning: unused variable 'x' [-Wunused-variable]
   33 |  int x = valid(n, A);
      |      ^
# 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 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 212 KB Output is correct
6 Correct 8 ms 2132 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 14 ms 3916 KB Output is correct
9 Correct 4 ms 1364 KB Output is correct
10 Correct 17 ms 4436 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 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 2108 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 21 ms 3924 KB Output is correct
9 Correct 5 ms 1364 KB Output is correct
10 Correct 17 ms 4444 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 4 ms 352 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 6 ms 608 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 0 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 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 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 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 5 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 28 ms 4656 KB Output is correct
12 Correct 28 ms 5220 KB Output is correct
13 Correct 32 ms 4780 KB Output is correct
14 Correct 26 ms 4564 KB Output is correct
15 Correct 42 ms 10064 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
# 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 256 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -