Submission #320051

# Submission time Handle Problem Language Result Execution time Memory
320051 2020-11-07T12:14:41 Z keta_tsimakuridze Gondola (IOI14_gondola) C++14
100 / 100
82 ms 12772 KB
#include<bits/stdc++.h>
#include "gondola.h"
#define f first
#define s second
#define mp make_pair
#include <stdio.h>
#include <assert.h>
using namespace std;
const int mod=1e9+9;
const int N=2e5+5;
int c[N];
map<long long,int> fix;
int valid(int n, int a[])
{

	vector<pair<int,int> > V;
  for(int i=0;i<n;i++){
  	if(fix[a[i]]) return 0;
  	if(a[i]<=n) {
  		V.push_back(mp(a[i],i));
	  }
	fix[a[i]]=1;
  }	
  for(int i=1;i<V.size();i++){
  	if(V[i].f>V[i-1].f){
	  if(V[i].f-V[i-1].f!=V[i].s-V[i-1].s)	return 0;}
	  else {
	  	if(V[i].s-V[i-1].s!=n-V[i-1].f+V[i].f) return 0;
	  }
  }
  return 1;
}
//--------------------
int replacement(int n, int a[], int b[])
{ 
	int mx=0;
	int ind=-1;
	for(int i=0;i<n;i++){
		mx=max(mx,a[i]);
		if(a[i]<=n) ind=i;
		fix[a[i]]=i+1; }
	if(ind==-1){
	
	for(int i=0;i<n;i++)
	c[i]=i+1;}
	else {
		for(int i=ind;i<n;i++){
			c[i]=(a[ind]-1+i-ind)%n;
			c[i]++;
		}
		for(int i=ind-1;i>=0;i--){
			c[i]=(a[ind]-1-(ind-i)+n)%n;
			c[i]++;
		}
	}
	for(int i=n+1;i<=mx;i++){
		if(fix[i]) {
			b[i-n-1]=c[fix[i]-1];
			c[fix[i]-1]=i;
		}
		else {
			b[i-n-1]=c[fix[mx]-1];
			c[fix[mx]-1]=i;
		}
	}
  return mx-n;
}

//----------------------
long long pwr(int u,int v){
	if(v==1) return u;
	if(v%2) return pwr(u,v-1)*u%mod;
	long long p=pwr(u,v/2);
	return p*p%mod;
}
int countReplacement(int n, int a[])
{
	vector<int>V;
	long long ans=1;
	for(int i=0;i<n;i++){
	if(fix[a[i]]) return 0;
	if(a[i]>n) V.push_back(a[i]); fix[a[i]]=1;}
	
	if(!V.size())return 1;
	V.push_back(n);
	sort(V.begin(),V.end());
	for(int i=1;i<V.size();i++){
		if(V[i]==V[i-1]+1) continue;
		ans*=pwr(V.size()-i,V[i]-V[i-1]-1);
		ans%=mod;
	}
	if(V.size()==n+1)ans*=n,ans%=mod;
	
	
  return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i=1;i<V.size();i++){
      |               ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:82:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   82 |  if(a[i]>n) V.push_back(a[i]); fix[a[i]]=1;}
      |  ^~
gondola.cpp:82:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   82 |  if(a[i]>n) V.push_back(a[i]); fix[a[i]]=1;}
      |                                ^~~
gondola.cpp:87:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i=1;i<V.size();i++){
      |              ~^~~~~~~~~
gondola.cpp:92:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |  if(V.size()==n+1)ans*=n,ans%=mod;
      |     ~~~~~~~~^~~~~
# 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 492 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 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 18 ms 3172 KB Output is correct
7 Correct 12 ms 768 KB Output is correct
8 Correct 35 ms 5732 KB Output is correct
9 Correct 11 ms 2028 KB Output is correct
10 Correct 41 ms 6616 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 18 ms 3172 KB Output is correct
7 Correct 11 ms 748 KB Output is correct
8 Correct 34 ms 5732 KB Output is correct
9 Correct 11 ms 2024 KB Output is correct
10 Correct 42 ms 6488 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 20 ms 2668 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 55 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 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 512 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 3 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 3 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 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 3 ms 620 KB Output is correct
11 Correct 30 ms 5864 KB Output is correct
12 Correct 34 ms 6636 KB Output is correct
13 Correct 44 ms 6116 KB Output is correct
14 Correct 30 ms 5868 KB Output is correct
15 Correct 79 ms 12772 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 512 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
# 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 55 ms 6004 KB Output is correct
10 Correct 42 ms 4968 KB Output is correct
11 Correct 14 ms 2028 KB Output is correct
12 Correct 18 ms 2412 KB Output is correct
13 Correct 4 ms 876 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 55 ms 5984 KB Output is correct
10 Correct 42 ms 4968 KB Output is correct
11 Correct 15 ms 2156 KB Output is correct
12 Correct 18 ms 2560 KB Output is correct
13 Correct 4 ms 876 KB Output is correct
14 Correct 71 ms 7124 KB Output is correct
15 Correct 82 ms 7900 KB Output is correct
16 Correct 12 ms 1772 KB Output is correct
17 Correct 48 ms 5472 KB Output is correct
18 Correct 26 ms 3180 KB Output is correct