제출 #379212

#제출 시각아이디문제언어결과실행 시간메모리
379212Mounir곤돌라 (IOI14_gondola)C++14
90 / 100
1090 ms5476 KiB
#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
using namespace std;
 
int valid(int n, int inputSeq[]) {
	vector<int> restant;
	map<int, bool> vu;
	for (int ind = 0; ind < n; ++ind){
		if (vu[inputSeq[ind]])
			return 0;
		vu[inputSeq[ind]] = true;
		if (inputSeq[ind] <= n)
			restant.pb(ind);
	}
 
	for (int ind = 0; ind < sz(restant) - 1; ++ind){
		int a = restant[ind] - inputSeq[restant[ind]], b = restant[ind + 1] - inputSeq[restant[ind + 1]];
		a += n; a %= n;
		b += n; b %= n;
 
		if (a != b)
			return 0;
	}
	return 1;
}
 
//----------------------
 
struct Element {
	int ind, val;
 
	bool operator < (const Element &autre) const {
		return val < autre.val;
	}
};
 
int get(int id, int deb, int n){
	if (id > deb)
		return id - deb;
	else
		return n - deb + id;
}
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	int maxi = 0, deb = 0;
	set<Element> reste;
	for (int ind = 0; ind < n; ++ind){
		chmax(maxi, gondolaSeq[ind]);
		if (gondolaSeq[ind] > n){
			//cout << "val " << ind << " " << gondolaSeq[ind] << endl;
			reste.insert({ind, gondolaSeq[ind]});
		}
		else
			deb = (ind -gondolaSeq[ind] + n)%n;
	}
 
	vector<int> actu(n);
	for (int i = 0; i < n; ++i)
		actu[i] = get(i, deb, n);
 
	for (int tour = n + 1; tour <= maxi; ++tour){
		int id = reste.begin()->ind;
		replacementSeq[tour - n - 1] = actu[id];
		actu[id] = tour;
		reste.erase(reste.begin());
		if (tour != gondolaSeq[id])
			reste.insert({id, tour});
	}
	return maxi - n;
}
 
//----------------------
 
const int MOD = 1e9 + 9;
 
int countReplacement(int n, int inputSeq[]){
	long long nb = 1;
	int maxi = 0, deb = 0;
	bool entier = true;
	vector<int> reste;
	for (int ind = 0; ind < n; ++ind){
		chmax(maxi, inputSeq[ind]);
		if (inputSeq[ind] > n)
			reste.pb(inputSeq[ind]);
		else entier = false;
	}
 
	sort(all(reste));
	int pt = 0;
	for (int tour = n + 1; tour <= maxi; ++tour){
		while (pt < sz(reste) && reste[pt] < tour)
			++pt;
		if (reste[pt] == tour)
			++pt;
		else{
			//cout << "val " << tour << " " << sz(reste) << " " << reste.top() << endl;
			nb = (nb * (sz(reste) - pt))%MOD;
		}
	}

	if (entier)
		nb = (nb * n)%MOD;

	return (valid(n, inputSeq) * (nb + MOD)%MOD)%MOD;
}

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

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:82:16: warning: unused variable 'deb' [-Wunused-variable]
   82 |  int maxi = 0, deb = 0;
      |                ^~~
#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...