Submission #809123

#TimeUsernameProblemLanguageResultExecution timeMemory
809123OrazBGondola (IOI14_gondola)C++14
Compilation error
0 ms0 KiB
#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 (int i = 0; i < vec.size(); i++){
		ans = (ans*1ll*F(cnt, vec[i]-lst-1));
		lst = vec[i];
	}
	return ans;
}

Compilation message (stderr)

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:98:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |  for (int i = 0; i < vec.size(); i++){
      |                  ~~^~~~~~~~~~~~
/usr/bin/ld: /tmp/ccEOs8la.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status