Submission #586214

#TimeUsernameProblemLanguageResultExecution timeMemory
586214SeDunion곤돌라 (IOI14_gondola)C++17
55 / 100
18 ms2260 KiB
#include "gondola.h"
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 1e6 + 123;

int u[N];

int valid(int n, int inputSeq[]) {
	int id = -1;
	for (int i = 0 ; i < n ; ++ i) {
		if (inputSeq[i] <= n) id = i;
	}
	for (int i = 0 ; i < n ; ++ i) u[i] = inputSeq[i];
	sort(u, u + n);
	for (int i = 1 ; i < n ; ++ i) if (u[i] == u[i - 1]) return 0;
	if (id == -1) return 1;
	int x = inputSeq[id];
	for (int i = 0 ; i + x <= n ; ++ i) {
		int j = (i + id) % n;
		if (inputSeq[j] != i + x) return 0;
	}
	for (int i = 0 ; i < x ; ++ i) {
		int j = (id - i + n) % n;
		if (inputSeq[j] != x - i) return 0;
	}
	return 1;
}

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

pair<int,int>pp[N];
int tt[N];

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	for (int i = 0 ; i < n ; ++ i) {
		pp[i] = {gondolaSeq[i], i};
	}
	sort(pp, pp + n);
	int id = 0, x = 1;
	if (pp[0].first <= n) id = pp[0].second, x = pp[0].first;
	for (int i = 0 ; i + x <= n ; ++ i) {
		int j = (i + id) % n;
		tt[j] = i + x;
	}
	for (int i = 1 ; i < x ; ++ i) {
		int j = (id - i + n) % n;
		tt[j] = x - i;
	}
	int m = 0;
	int t = n;
	for (int i = 0 ; i < n ; ++ i) {
		int x = pp[i].first;
		int y = pp[i].second;
		if (x <= n) continue;
		while (tt[y] < x) {
			replacementSeq[m++] = tt[y];
			tt[y] = ++t;
		}
	}
	return m;
}

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

int countReplacement(int n, int inputSeq[])
{
  return -3;
}
#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...