Submission #809128

# Submission time Handle Problem Language Result Execution time Memory
809128 2023-08-05T18:05:17 Z OrazB Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 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 int 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;
		cmt--;
		lst = i;
	}
	return ans;
}

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	cout << countReplacement(n, A);
}	

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);
      |      ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:100:3: error: 'cmt' was not declared in this scope; did you mean 'cnt'?
  100 |   cmt--;
      |   ^~~
      |   cnt