Submission #382702

# Submission time Handle Problem Language Result Execution time Memory
382702 2021-03-28T04:16:05 Z Trunkty Gondola (IOI14_gondola) C++14
100 / 100
291 ms 3184 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include "gondola.h"
using namespace std;
 
int valid(int n, int inputSeq[]){
	vector<int> ck={};
	for(int i=0;i<n;i++){
		ck.push_back(inputSeq[i]);
	}
	sort(ck.begin(),ck.end());
	for(int i=1;i<ck.size();i++){
		if(ck[i]==ck[i-1]){
			return 0;
		}
	}
	int ind=0;
	for(int i=0;i<n;i++){
		if(inputSeq[i]<=n){
			ind = i-(inputSeq[i]-1);
			if(ind<0){
				ind += n;
			}
			break;
		}
	}
	int now = 1;
	for(int i=ind;i<n;i++){
		if(inputSeq[i]<=n){
			if(inputSeq[i]!=now){
				return 0;
			}
		}
		now++;
	}
	for(int i=0;i<ind;i++){
		if(inputSeq[i]<=n){
			if(inputSeq[i]!=now){
				return 0;
			}
		}
		now++;
	}
	return 1;
}
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	int ind=0;
	for(int i=0;i<n;i++){
		if(gondolaSeq[i]<=n){
			ind = i-(gondolaSeq[i]-1);
			if(ind<0){
				ind += n;
			}
			break;
		}
	}
	int have[250005],maxi=-1,pos=0;
	for(int i=1;i<250005;i++){
		have[i] = -1;
	}
	for(int i=0;i<n;i++){
		have[gondolaSeq[i]] = ((i-ind+n)%n)+1;
		if(gondolaSeq[i]>maxi){
			maxi = gondolaSeq[i];
			pos = ((i-ind+n)%n)+1;
		}
	}
	for(int i=n+1;i<maxi;i++){
		if(have[i]==-1){
			replacementSeq[i-n-1] = pos;
			pos = i;
		}
		else{
			replacementSeq[i-n-1] = have[i];
		}
	}
	replacementSeq[maxi-n-1] = pos;
	return maxi-n;
}
long long mod=1000000009;
long long fastpow(long long base, long long exp){
	long long pow2[33];
	pow2[0] = base;
	for(int i=1;i<=32;i++){
		pow2[i] = pow2[i-1]*pow2[i-1];
		pow2[i] = pow2[i]%mod;
	}
	long long ans=1,now=0;
	for(int i=32;i>=0;i--){
		if(now+pow(2,i)<=exp){
			now += pow(2,i);
			ans *= pow2[i];
			ans = ans%mod;
		}
	}
	return ans;
}
int countReplacement(int n, int inputSeq[]){
	if(not valid(n,inputSeq)){
		return 0;
	}
	long long ans=1,now=n;
	vector<long long> have={};
	bool allbreak=true;
	for(int i=0;i<n;i++){
		if(inputSeq[i]<=n){
			allbreak = false;
		}
		else{
			have.push_back(inputSeq[i]);
		}
	}
	if(allbreak){
		ans = n;
	}
	sort(have.begin(),have.end());
	for(int i=0;i<have.size();i++){
		ans *= fastpow(have.size()-i,have[i]-now-1);
		ans = ans%mod;
		now = have[i];
	}
	int k = ans;
	return k;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=1;i<ck.size();i++){
      |              ~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:120:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |  for(int i=0;i<have.size();i++){
      |              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 8 ms 876 KB Output is correct
7 Correct 22 ms 1308 KB Output is correct
8 Correct 13 ms 1256 KB Output is correct
9 Correct 6 ms 680 KB Output is correct
10 Correct 18 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 8 ms 876 KB Output is correct
7 Correct 17 ms 1384 KB Output is correct
8 Correct 12 ms 1256 KB Output is correct
9 Correct 6 ms 620 KB Output is correct
10 Correct 18 ms 1256 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 8 ms 876 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 19 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Correct 2 ms 1260 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1408 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Correct 2 ms 1260 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
6 Correct 2 ms 1260 KB Output is correct
7 Correct 2 ms 1260 KB Output is correct
8 Correct 2 ms 1388 KB Output is correct
9 Correct 2 ms 1388 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
6 Correct 2 ms 1260 KB Output is correct
7 Correct 2 ms 1260 KB Output is correct
8 Correct 2 ms 1388 KB Output is correct
9 Correct 2 ms 1388 KB Output is correct
10 Correct 2 ms 1388 KB Output is correct
11 Correct 11 ms 1644 KB Output is correct
12 Correct 16 ms 1644 KB Output is correct
13 Correct 14 ms 2156 KB Output is correct
14 Correct 11 ms 1644 KB Output is correct
15 Correct 32 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 176 ms 1604 KB Output is correct
10 Correct 132 ms 1272 KB Output is correct
11 Correct 69 ms 808 KB Output is correct
12 Correct 80 ms 772 KB Output is correct
13 Correct 22 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 179 ms 1604 KB Output is correct
10 Correct 135 ms 1272 KB Output is correct
11 Correct 69 ms 788 KB Output is correct
12 Correct 80 ms 772 KB Output is correct
13 Correct 21 ms 492 KB Output is correct
14 Correct 269 ms 2204 KB Output is correct
15 Correct 291 ms 3184 KB Output is correct
16 Correct 54 ms 932 KB Output is correct
17 Correct 193 ms 1900 KB Output is correct
18 Correct 108 ms 1628 KB Output is correct