Submission #239368

# Submission time Handle Problem Language Result Execution time Memory
239368 2020-06-15T12:50:31 Z kshitij_sodani Gondola (IOI14_gondola) C++17
100 / 100
63 ms 6008 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#include "gondola.h"
int valid(int n,int aa[]){
	vector<int> ind;
	set<int> ss;
	for(int i=0;i<n;i++){
		ss.insert(aa[i]);
	}
	if(ss.size()!=n){
		return 0;
	}
	for(int i=0;i<n;i++){
		if(aa[i]<=n){
			ind.pb(i);
		}
	}
	if(ind.size()<2){
		return 1;
	}
	int st=0;
	int bb[n];
	int co=aa[ind[0]];
	for(int i=ind[0];i<n;i++){
		bb[i]=co;
		co+=1;
		if(co==n+1){
			co=1;
		}
	}
	for(int i=0;i<ind[0];i++){
		bb[i]=co;
		co+=1;
		if(co==n+1){
			co=1;
		}
	}
	for(int i=0;i<n;i++){
		if(bb[i]!=aa[i] and aa[i]<=n){
			return 0;
		}
	}
	return 1;
}
int replacement(int n,int aa[],int bb[]){
/*	int vis[250001];
	int ma=0;
	for(int i=0;i<n;i++){
		vis[aa[i]]=1;
		ma=max(ma,aa[i]);
	}*/
	vector<int> ind;

	for(int i=0;i<n;i++){
		if(aa[i]<=n){
			ind.pb(i);
		}
	}
	/*if(ind.size()==0){
		int co=0;
		for(int i=1;i<=ma;i++){
			if(vis[i]==0){
				bb[co]=i;
				co++;
			}
		}
		return co;
	}*/
	int co;
	if(ind.size()==0){
		ind.pb(0);
		co=1;
	}
	else{
		co=aa[ind[0]];
	}

	int cc[n];
	for(int i=ind[0];i<n;i++){
		cc[i]=co;
		co+=1;
		if(co==n+1){
			co=1;
		}
	}
	for(int i=0;i<ind[0];i++){
		cc[i]=co;
		co+=1;
		if(co==n+1){
			co=1;
		}
	}
	vector<pair<int,int>> dd;
	for(int i=0;i<n;i++){
		if(aa[i]>n){
			dd.pb({aa[i],i});
		}
	}
	if(dd.size()==0){
		return 0;
	}
	sort(dd.begin(),dd.end());
	int cur=n+1;
	int ans=0;
/*	for(int i=0;i<n;i++){
		cout<<cc[i]<<',';
	}
	cout<<endl;*/
	for(auto i:dd){
		bb[ans]=cc[i.b];
		ans++;
		for(int j=cur;j<i.a;j++){
			bb[ans]=j;
			ans++;
		}
		cur=i.a+1;
	}
/*	for(int i=0;i<ans;i++){
		cout<<bb[i]<<",";
	}
	cout<<endl;
*/
	return ans;

}
llo e(llo aa,llo bb,llo cc){
	if(bb==0){
		return (llo)1;
	}
	llo ans=e(aa,bb/2,cc);
	ans*=ans;
	ans%=cc;
	if(bb%2==1){
		ans*=aa;
		ans%=cc;
	}
	return ans;
}
int countReplacement(int n,int aa[]){
	if(valid(n,aa)==0){
		return 0;
	}
	vector<int> ind;
	for(int i=0;i<n;i++){
		if(aa[i]>n){
			ind.pb(aa[i]);
		}
	}
	llo mod=1000000009;
	if(ind.size()==0){
		return 1;
	}

	sort(ind.begin(),ind.end());
	llo ans=1;
	if(ind.size()==n){
		ans=(llo)n;
	}
	int le=ind.size();
	int cur=n+1;
	for(auto i:ind){
		ans*=e((llo)le,(llo)(i-cur),mod);
		ans%=mod;
		le-=1;
		cur=i+1;
	//	cout<<ans<<endl;
	}
	return (int)ans;


}
/*int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int it[n];
	for(int i=0;i<n;i++){
		cin>>it[i];
	}
	int ac[25000];
	cout<<countReplacement(n,it)<<endl;



	return 0;
}*/

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:15:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(ss.size()!=n){
     ~~~~~~~~~^~~
gondola.cpp:26:6: warning: unused variable 'st' [-Wunused-variable]
  int st=0;
      ^~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:161:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(ind.size()==n){
     ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 17 ms 2688 KB Output is correct
7 Correct 35 ms 3704 KB Output is correct
8 Correct 27 ms 4604 KB Output is correct
9 Correct 11 ms 1792 KB Output is correct
10 Correct 32 ms 5372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 18 ms 2688 KB Output is correct
7 Correct 36 ms 3704 KB Output is correct
8 Correct 29 ms 4604 KB Output is correct
9 Correct 12 ms 1792 KB Output is correct
10 Correct 33 ms 5372 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 20 ms 2304 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 46 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 20 ms 1400 KB Output is correct
12 Correct 17 ms 1528 KB Output is correct
13 Correct 20 ms 1424 KB Output is correct
14 Correct 18 ms 1400 KB Output is correct
15 Correct 26 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 46 ms 4472 KB Output is correct
10 Correct 39 ms 3968 KB Output is correct
11 Correct 16 ms 1536 KB Output is correct
12 Correct 19 ms 1792 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 48 ms 4472 KB Output is correct
10 Correct 36 ms 3840 KB Output is correct
11 Correct 16 ms 1536 KB Output is correct
12 Correct 19 ms 1792 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 56 ms 5372 KB Output is correct
15 Correct 63 ms 6008 KB Output is correct
16 Correct 14 ms 1408 KB Output is correct
17 Correct 42 ms 4224 KB Output is correct
18 Correct 24 ms 2560 KB Output is correct