Submission #52100

#TimeUsernameProblemLanguageResultExecution timeMemory
52100spencercomptonGondola (IOI14_gondola)C++17
100 / 100
104 ms9800 KiB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef long long ll;
ll mod = 1000000009LL;
ll expo(ll base, ll ex){
	if(ex==0LL){
		return 1LL;
	}
	if(ex==1LL){
		return base;
	}
	if(ex%2LL==0LL){
		ll now = expo(base,ex/2LL);
		now *= now;
		now %= mod;
		return now;
	}
	else{
		ll now = expo(base,ex-1LL) * base;
		now %= mod;
		return now;
	}
}
int valid(int n, int inputSeq[])
{
	set<int> ss;
	for(int i = 0; i<n; i++){
		ss.insert(inputSeq[i]);
	}
	if(ss.size()!=n){
		return 0;
	}
	pair<int, int> first;
	first.first = n+1;
	first.second = -1;
	for(int i = 0; i<n; i++){
		if(inputSeq[i]<first.first){
			first.first = inputSeq[i];
			first.second = i;
		}
	}
	if(first.second==-1){
		return 1;
	}
	int pos = first.second;
	for(int i = 0; i<n; i++){
		if(inputSeq[i]<=n && i!=((first.second+inputSeq[i]-first.first)%n)){
			return 0;
		}
	}
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	pair<int, int> first;
	first.first = n+1;
	first.second = -1;
	for(int i = 0; i<n; i++){
		if(gondolaSeq[i]<first.first){
			first.first = gondolaSeq[i];
			first.second = i;
		}
	}
	if(first.second==-1){
		first.first = 1;
		first.second = 0;
	}
	int cur[n];
	for(int i = 1; i<=n; i++){
		int pos = (i-first.first+first.second+n+n)%n;
		cur[pos] = i;
	}
	vector<pair<int, int> > final;
	for(int i = 0; i<n; i++){
		final.push_back(make_pair(gondolaSeq[i],i));
	}
	sort(final.begin(),final.end());
	int point = n+1;
	int p = 0;
	for(int i = 0; i<n; i++){
		while(point<=final[i].first){
			replacementSeq[p++] = cur[final[i].second];
			cur[final[i].second] = point++;
		}
	}
	return p;
}

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

int countReplacement(int n, int inputSeq[])
{
	if(valid(n,inputSeq)==0){
		return 0;
	}
	pair<int, int> first;
	first.first = n+1;
	first.second = -1;
	for(int i = 0; i<n; i++){
		if(inputSeq[i]<first.first){
			first.first = inputSeq[i];
			first.second = i;
		}
	}
	bool all = false;
	if(first.second==-1){
		all = true;
		first.first = 1;
		first.second = 0;
	}
	vector<int> li;
	for(int i = 0; i<n; i++){
		li.push_back(inputSeq[i]);
	}
	sort(li.begin(),li.end());
	ll ans = 1LL;
	for(int i = 0; i<li.size(); i++){
		if(li[i]<=n){
			continue;
		}
		int bef = n;
		if(i>0){
			bef = max(bef,li[i-1]);
		}
		int bet = li[i]-bef-1;
		ll here = expo(li.size()-i,bet);
		ans *= here;
		ans %= mod;
	}
	if(all){
		ans *= n;
		ans %= mod;
	}
	return ans;
}

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:31:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(ss.size()!=n){
     ~~~~~~~~~^~~
gondola.cpp:46:6: warning: unused variable 'pos' [-Wunused-variable]
  int pos = first.second;
      ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:121:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<li.size(); i++){
                 ~^~~~~~~~~~
#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...