Submission #165015

# Submission time Handle Problem Language Result Execution time Memory
165015 2019-11-24T16:41:27 Z kostia244 Gondola (IOI14_gondola) C++17
Compilation error
0 ms 0 KB
#include "gondola.h"
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
int valid(int n, int a[]) {
	set<int> x;
	for (int i = 0; i < n; i++)
		x.insert(a[i]);
	if (x.size() != n)
		return 0;
	for (int i = 1; i < n; i++) {
		if (a[i] > n) {
			a[i] = a[i - 1] + 1;
		}
	}
	for (int i = n; i-- > 1;) {
		if (a[i] > n) {
			a[i] = a[i - 1] == n ? 1 : a[i - 1] + 1;
		}
	}
	int i = 0;
	while (a[i] != 1)
		i++;
	int p = 1;
	for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {
		if (p+1 != a[j])
			return 0;
		p = a[j];
	}
	return 1;
}

//----------------------
int pos[250250];
int replacement(int n, int a[], int b[]) {
	int mx = n, p = 1;
	bitset<250250> have;
	for(int i = 0; i < n; i++) {
		if(a[i]>n) {
			have.set(a[i]);
			pos[a[i]] = i;
		}
		if(a[i]>mx) mx = a[i], p = i;
		if(a[i]<mn) mn = a[i], p = i;
	}
	for(int i = 0; i < n; i++)
		if(a[i]>n) exit(-1);
	int j = 0;
	for(int i = n+1; i <= mx; i++) {
		if(have.test(i)) {
			b[j++] = a[pos[i]];
			a[pos[i]] = i;
		} else {
			b[j++] = a[p];
			a[p] = i;
		}
	}
	return max(0, mx-n);
}

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

int countReplacement(int n, int inputSeq[]) {
	return -3;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:12:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (x.size() != n)
      ~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:47:11: error: 'mn' was not declared in this scope
   if(a[i]<mn) mn = a[i], p = i;
           ^~
gondola.cpp:47:11: note: suggested alternative: 'mx'
   if(a[i]<mn) mn = a[i], p = i;
           ^~
           mx