Submission #399822

# Submission time Handle Problem Language Result Execution time Memory
399822 2021-05-06T17:21:07 Z Jasiekstrz Gondola (IOI14_gondola) C++17
100 / 100
67 ms 6020 KB
#include "gondola.h"
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int MOD=1e9+9;
void rot(int n,int inputSeq[])
{
	int gmn=0;
	for(int i=0;i<n;i++)
	{
		if(inputSeq[i]<inputSeq[gmn])
			gmn=i;
	}
	rotate(inputSeq,inputSeq+gmn,inputSeq+n);
	return;
}
int valid(int n,int inputSeq[])
{
	set<int> vis;
	for(int i=0;i<n;i++)
	{
		if(vis.find(inputSeq[i])!=vis.end())
			return 0;
		vis.insert(inputSeq[i]);
	}
	rot(n,inputSeq);
	for(int i=0;i<n;i++)
	{
		if(inputSeq[i]<=n && inputSeq[i]!=inputSeq[0]+i)
			return 0;
	}
	return 1;
}
bool comp_se(pair<int,int> a,pair<int,int> b)
{
	if(a.se==b.se)
		return a.fi<b.fi;
	return a.se<b.se;
}
int replacement(int n,int gondolaSeq[],int replacementSeq[])
{
	int l=0;
	vector<pair<int,int>> ch;
	rot(n,gondolaSeq);
	for(int i=0;i<n;i++)
	{
		if(gondolaSeq[i]>n)
			ch.emplace_back((gondolaSeq[0]+i-1)%n+1,gondolaSeq[i]);
	}
	sort(ch.begin(),ch.end(),comp_se);
	int nxt=n+1;
	for(auto v:ch)
	{
		replacementSeq[l++]=v.fi;
		while(nxt<v.se)
			replacementSeq[l++]=nxt++;
		nxt++;
	}
	return l;
}
int qp(int x,int y)
{
	if(y==0)
		return 1;
	long long pp=qp(x,y/2);
	pp=(pp*pp)%MOD;
	if(y%2==1)
		return (pp*x)%MOD;
	return pp;
}
int countReplacement(int n,int inputSeq[])
{
	if(valid(n,inputSeq)==0)
		return 0;
	long long ans=1;
	vector<int> ch;
	for(int i=0;i<n;i++)
	{
		if(inputSeq[i]>n)
			ch.emplace_back(inputSeq[i]);
	}
	sort(ch.begin(),ch.end());
	int lst=n,free=ch.size();
	for(auto v:ch)
	{
		ans=(ans*qp(free,v-lst-1))%MOD;
		lst=v;
		free--;
	}
	if(ch.size()==n)
		ans=(ans*n)%MOD;
	return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:91:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |  if(ch.size()==n)
      |     ~~~~~~~~~^~~
# 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 14 ms 2124 KB Output is correct
7 Correct 11 ms 588 KB Output is correct
8 Correct 30 ms 3864 KB Output is correct
9 Correct 8 ms 1356 KB Output is correct
10 Correct 33 ms 4504 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 14 ms 2112 KB Output is correct
7 Correct 12 ms 588 KB Output is correct
8 Correct 30 ms 3832 KB Output is correct
9 Correct 9 ms 1464 KB Output is correct
10 Correct 33 ms 4420 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 24 ms 1996 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 48 ms 4676 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 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 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 10 ms 588 KB Output is correct
12 Correct 14 ms 588 KB Output is correct
13 Correct 17 ms 1216 KB Output is correct
14 Correct 10 ms 588 KB Output is correct
15 Correct 25 ms 2156 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
# 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 208 KB Output is correct
5 Correct 1 ms 208 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 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 47 ms 3908 KB Output is correct
10 Correct 37 ms 3392 KB Output is correct
11 Correct 14 ms 1428 KB Output is correct
12 Correct 17 ms 1612 KB Output is correct
13 Correct 4 ms 588 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 208 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 208 KB Output is correct
9 Correct 48 ms 3996 KB Output is correct
10 Correct 37 ms 3408 KB Output is correct
11 Correct 14 ms 1384 KB Output is correct
12 Correct 17 ms 1692 KB Output is correct
13 Correct 4 ms 644 KB Output is correct
14 Correct 59 ms 5272 KB Output is correct
15 Correct 67 ms 6020 KB Output is correct
16 Correct 11 ms 1356 KB Output is correct
17 Correct 44 ms 4036 KB Output is correct
18 Correct 24 ms 2372 KB Output is correct