Submission #413753

# Submission time Handle Problem Language Result Execution time Memory
413753 2021-05-29T10:36:16 Z Antekb Gondola (IOI14_gondola) C++14
100 / 100
33 ms 2600 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[])
{
	bool b=0;
	int V[n];
	for(int i=0; i<n; i++)V[i]=inputSeq[i];
	sort(V, V+n);
	for(int i=1; i<n; i++)if(V[i]==V[i-1])return 0;
	for(int i=0; i<n; i++){
		if(inputSeq[i]<=n){
			int t=inputSeq[i]-i-1;
			//cout<<inputSeq[i]<<"\n";
			for(int j=0; j<n; j++)V[j]=inputSeq[(j-t+n)%n];
			//for(int j=0; j<n; j++)cout<<V[j]<<" ";
			b=1;
			break;
		}
	}
	if(b==0)return 1;
	for(int i=0; i<n; i++)if(V[i]<=n && V[i]!=i+1)b=0;
	for(int i=0; i<n; ++i)inputSeq[i]=V[i];
	return b;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	if(!valid(n, gondolaSeq))return 0;
	/*vector<int > V(n);
	for(int i=0; i<n; i++)V[i]=inputSeq[i];
	sort(V.begin(), V.end());*/
	int m=0;
	for(int i=0; i<n; i++){
		if(gondolaSeq[i]>gondolaSeq[m])m=i;
	}
	int l=gondolaSeq[m]-n;
	bool b=1;
	//for(int i=0; i<n; i++)cout<<gondolaSeq[i]<<" ";
	//cout<<"\n"<<m<<"\n";
	for(int i=0; i<n; i++){
		if(gondolaSeq[i]>n && i!=m)replacementSeq[gondolaSeq[i]-n-1]=i+1;
	}
	gondolaSeq[m]=m+1;
	for(int i=0; i<l; i++){
		if(!replacementSeq[i]){
			replacementSeq[i]=gondolaSeq[m];
			gondolaSeq[m]=i+n+1;
		}
	}
	return l;
}

//----------------------
typedef long long ll;
const int mod=1e9+9;
ll pot(int a, int b){
	if(b==0)return 1;
	if(b==1)return a;
	ll c=pot(a, b/2);
	c=c*c%mod;
	return c*pot(a, b&1)%mod;
}
int countReplacement(int n, int inputSeq[])
{
	if(!valid(n, inputSeq))return 0;
	long long ans=1;
	bool b=0;
	for(int i=0; i<n; i++)if(inputSeq[i]==i+1)b=1;
	if(!b)ans=n;
	vector<int> V;
	for(int i=0; i<n; i++)if(inputSeq[i]>n)V.push_back(inputSeq[i]);
	V.push_back(n);
	sort(V.begin(), V.end());
	for(int i=1; i<V.size(); i++){
		ans=ans*pot(V.size()-i, V[i]-V[i-1]-1)%mod;
	}
	return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:40:7: warning: unused variable 'b' [-Wunused-variable]
   40 |  bool b=1;
      |       ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:77:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i=1; i<V.size(); i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 8 ms 588 KB Output is correct
7 Correct 16 ms 976 KB Output is correct
8 Correct 12 ms 856 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 21 ms 872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 9 ms 588 KB Output is correct
7 Correct 16 ms 928 KB Output is correct
8 Correct 12 ms 844 KB Output is correct
9 Correct 7 ms 388 KB Output is correct
10 Correct 17 ms 948 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 8 ms 460 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 18 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 13 ms 844 KB Output is correct
12 Correct 15 ms 940 KB Output is correct
13 Correct 16 ms 1228 KB Output is correct
14 Correct 13 ms 844 KB Output is correct
15 Correct 31 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 27 ms 1624 KB Output is correct
10 Correct 22 ms 1484 KB Output is correct
11 Correct 7 ms 844 KB Output is correct
12 Correct 9 ms 844 KB Output is correct
13 Correct 3 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 21 ms 1740 KB Output is correct
10 Correct 18 ms 1484 KB Output is correct
11 Correct 9 ms 844 KB Output is correct
12 Correct 9 ms 716 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 27 ms 2336 KB Output is correct
15 Correct 33 ms 2600 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 21 ms 1808 KB Output is correct
18 Correct 15 ms 1232 KB Output is correct