제출 #237154

#제출 시각아이디문제언어결과실행 시간메모리
237154mode149256곤돌라 (IOI14_gondola)C++14
25 / 100
120 ms11128 KiB
/*input

*/
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}
}
using namespace my_template;

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;

vi kur(250002);

int valid(int n, int inputSeq[])
{
	set<int> dabar;
	for (int i = 0; i < n; ++i)
	{
		if (dabar.find(inputSeq[i]) != dabar.end()) return 0;
		dabar.insert(inputSeq[i]);
	}

	set<int> nera;
	int did = *(--dabar.end());

	for (int i = 0; i < n; ++i)
		kur[inputSeq[i]] = i;

	for (int i = 1; i < did; ++i)
	{
		if (dabar.find(i) == dabar.end())
			nera.insert(i);
	}

	while (*(--dabar.end()) != n) {
		int c = *(--dabar.end());
		int n = *(--nera.end());

		inputSeq[kur[c]] = n;
		kur[n] = kur[c];

		dabar.erase(c);
		nera.erase(n);
		dabar.insert(n);
	}

	for (int i = 0; i < n; ++i)
	{
		if (inputSeq[(kur[1] + i) % n] != i + 1)
			return 0;
	}

	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	set<int> dabar;
	for (int i = 0; i < n; ++i)
	{
		if (dabar.find(gondolaSeq[i]) != dabar.end()) return 0;
		dabar.insert(gondolaSeq[i]);
	}

	set<int> nera;
	int did = *(--dabar.end());

	for (int i = 0; i < n; ++i)
		kur[gondolaSeq[i]] = i;

	for (int i = 1; i < did; ++i)
	{
		if (dabar.find(i) == dabar.end())
			nera.insert(i);
	}

	int sz = did - n;
	int ret = sz;

	while (*(--dabar.end()) != n) {
		int c = *(--dabar.end());
		int n = *(--nera.end());

		replacementSeq[--sz] = n;
		gondolaSeq[kur[c]] = n;
		kur[n] = kur[c];

		dabar.erase(c);
		nera.erase(n);
		dabar.insert(n);
	}

	return ret;
}

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

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...