Submission #121660

# Submission time Handle Problem Language Result Execution time Memory
121660 2019-06-26T23:11:56 Z ly20 Gondola (IOI14_gondola) C++17
75 / 100
56 ms 5660 KB
#include<bits/stdc++.h>
using namespace std;
const int INF=1123456789,MAXN=250010,MOD=1000000009,MAXL=32;
#define debug(args...) //fprintf(stderr,args)
map<int,int> vld;
int marc[MAXN];
#include "gondola.h"
int valid(int n,int seq[])
{
	int mn=INF,at=INF,at2=INF,id0=0;
	int st=0;
	bool vl=1;
	for(int i=0;i<n;i++)
	{
		if(vl==0)debug("%d\n",i);
		if(vld[seq[i]]>0)vl=0;
		vld[seq[i]]++;
		if(st==0)
		{
			if(seq[i]>n)continue;
			if(seq[i]<at && at==INF)
			{
				at=seq[i];mn=seq[i];
				id0=(i+1-mn+n)%n;
			}
			else if(seq[i]<at)
			{
				at2=seq[i];st=1;
				if(at2>mn)vl=0;
			}
			else
			{
				if((id0+seq[i]-1)%n!=i)vl=0;
				at=seq[i];
			}
		}
		else
		{
			if(seq[i]>n)continue;
			if(seq[i]<at2 || seq[i]>mn || seq[i]>at)vl=0;
			if((id0+seq[i]-1)%n!=i)vl=0;
			at2=seq[i];
		}
		debug("%d %d %d\n",i,id0,(id0+seq[i])%n);
	}	
	return vl;
}
int replacement(int n,int seq[],int replacementseq[])
{
	vector<pair<int,int> > v;
	int mn=INF,at=INF,at2=INF,id0=0,mx=0,imx=0;
	int st=0;
	bool vl=1;
	for(int i=0;i<n;i++)
	{
		marc[seq[i]]=1;
		if(mx<seq[i])imx=i;
		mx=max(mx,seq[i]);
		if(vl==0)debug("%d\n",i);
		if(vld[seq[i]]>0)vl=0;
		vld[seq[i]]++;
		if(st==0)
		{
			if(seq[i]>n)continue;
			if(seq[i]<at && at==INF)
			{
				at=seq[i];mn=seq[i];
				id0=(i+1-mn+n)%n;
			}
			else if(seq[i]<at)
			{
				at2=seq[i];st=1;
				if(at2>mn)vl=0;
			}
			else
			{
				if((id0+seq[i]-1)%n!=i)vl=0;
				at=seq[i];
			}
		}
		else
		{
			if(seq[i]>n)continue;
			if(seq[i]<at2 || seq[i]>mn || seq[i]>at)vl=0;
			if((id0+seq[i]-1)%n!=i)vl=0;
			at2=seq[i];
		}
		debug("%d %d %d\n",i,id0,(id0+seq[i])%n);
	}
	int cnt=0,lst=(imx-id0+n)%n+1;
	for(int i=0;i<n;i++)if(seq[i]>n && seq[i]!=mx)replacementseq[seq[i]-n-1]=(i-id0+n)%n+1;
	for(int i=n+1;i<mx;i++)
	{
		if(!marc[i] && cnt==0)
		{
			replacementseq[i-n-1]=(imx-id0+n)%n+1;
			cnt=1;
			lst=i;
		}
		else if(!marc[i])
		{
			replacementseq[i-n-1]=lst;
			lst=i;
		}
	}
	for(int i=0;i<n;i++)if(seq[i]==mx)replacementseq[mx-n-1]=lst;
	//for(int i=0;i<mx-n;i++)printf("%d ",replacementseq[i]);
	//printf("\n");
	return mx-n;
}
long long fst_exp(long long n,int k)
{
	long long val=n;
	long long resp=1;
	for(int i=MAXL-1;i>=0;i--)
	{
		resp*=resp;
		if(k&(1<<i))resp*=val;
		if(resp>MOD)resp=resp%MOD;
	}
	return resp;
}
long long fat(long long n)
{
	if(n==1)return 1;
	else return (n*fat(n-1))%MOD;
}
int countReplacement(int n1,int seq[])
{
	long long n=(long long)n1;
	debug("%lld\n",n);
	vector<int> v;
	int mn=INF,at=INF,at2=INF,id0=0,mx=0,imx=0;
	int st=0;
	bool vl=1;
	for(int i=0;i<n;i++)
	{
		if(seq[i]>n)v.push_back(seq[i]);
		if(mx<seq[i])imx=i;
		mx=max(mx,seq[i]);
		if(vl==0)debug("%d\n",i);
		if(vld[seq[i]]>0)vl=0;
		vld[seq[i]]++;
		if(st==0)
		{
			if(seq[i]>n)continue;
			if(seq[i]<at && at==INF)
			{
				at=seq[i];mn=seq[i];
				id0=(i+1-mn+n)%n;
			}
			else if(seq[i]<at)
			{
				at2=seq[i];st=1;
				if(at2>mn)vl=0;
			}
			else
			{
				if((id0+seq[i]-1)%n!=i)vl=0;
				at=seq[i];
			}
		}
		else
		{
			if(seq[i]>n)continue;
			if(seq[i]<at2 || seq[i]>mn || seq[i]>at)vl=0;
			if((id0+seq[i]-1)%n!=i)vl=0;
			at2=seq[i];
		}
		debug("%d %d %d %d\n",i,id0,seq[i],(id0+seq[i])%n);
	}
	if(vl==0)return vl;
	sort(v.begin(),v.end());
	long long resp=1;
	int cnt=0,lst=n;
	for(int i=0;i<v.size();i++)
	{
		resp*=fst_exp((long long)v.size()-i,v[i]-lst-1);
		//printf("%lld %d %d %d %d\n",resp,v.size()-i,v[i]-lst-1,v[i],lst);
		if(resp>MOD)resp%=MOD;
		lst=v[i];
	}
	long long k1=n;
	if(v.size()==n)resp*=k1;
	if(v.size()==0)resp=1;
	resp%=MOD;
	//for(int i=0;i<mx-n;i++)printf("%d ",replacementseq[i]);
	//printf("\n");
	return resp;
}
/*int v[1123456];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	printf("%d\n",countReplacement(n,v));
	return 0;
}*/

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:176:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++)
              ~^~~~~~~~~
gondola.cpp:184:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(v.size()==n)resp*=k1;
     ~~~~~~~~^~~
gondola.cpp:133:39: warning: variable 'imx' set but not used [-Wunused-but-set-variable]
  int mn=INF,at=INF,at2=INF,id0=0,mx=0,imx=0;
                                       ^~~
gondola.cpp:175:6: warning: unused variable 'cnt' [-Wunused-variable]
  int cnt=0,lst=n;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 17 ms 2304 KB Output is correct
7 Correct 42 ms 4216 KB Output is correct
8 Correct 29 ms 4224 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 41 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 16 ms 2304 KB Output is correct
7 Correct 41 ms 4124 KB Output is correct
8 Correct 32 ms 4216 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 41 ms 4856 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 23 ms 2296 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 49 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 33 ms 5112 KB Output is correct
12 Correct 40 ms 5660 KB Output is correct
13 Correct 26 ms 3320 KB Output is correct
14 Correct 38 ms 4984 KB Output is correct
15 Correct 26 ms 3504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 52 ms 4724 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Incorrect 56 ms 4728 KB Output isn't correct
10 Halted 0 ms 0 KB -