제출 #165012

#제출 시각아이디문제언어결과실행 시간메모리
165012kostia244Gondola (IOI14_gondola)C++17
25 / 100
48 ms4728 KiB
#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 = 0, p = 0;
	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;
	}
	for (int i = 1; i < n; i++) {
		if (a[i] > n&&a[i-1]<=n) {
			a[i] = (a[i - 1]%n) + 1;
		}
	}
	for (int i = n; i--;) {
		if (a[i] > n&&a[i+1]<=n) {
			a[i] = a[i + 1] == 1 ? n : a[i + 1] - 1;
		}
	}
	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;
}

컴파일 시 표준 에러 (stderr) 메시지

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)
      ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...