답안 #238205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238205 2020-06-10T08:06:33 Z Fasho 곤돌라 (IOI14_gondola) C++14
100 / 100
39 ms 3328 KB
#include <bits/stdc++.h>
#include "gondola.h"
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000009
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
 
using namespace std;
 
int ar[N];
 
int valid(int n, int inputSeq[])
{
	ll x=-1;
	// fo(i,0,n-1)
	// 	inputSeq[i]=ar[i];
	fo(i,1,n)
	{	
		// cout<<inputSeq[i-1]<<sp;
		ar[i]=inputSeq[i-1];
	}
	sort(ar+1,ar+n+1);
	fo(i,2,n)
		if(ar[i-1]==ar[i])
			return 0;
	fo(i,1,n)
		ar[i]=inputSeq[i-1];
	// cout<<endl;
 
	fo(i,1,n)
		if(ar[i]<=n)
		{
			x=i;
			break;
		}
 
	if(x==-1)
		return 1;
	
	// fo(i,1,n)
	// cout<<ar[i]<<sp;
	// cout<<endl;
	// cout<<x<<endl;
	int flag=0;
	fo(i,x+1,n)
	{
		if(ar[i]<=n)
		{
			if((i-x+ar[x])%n!=ar[i]%n)
				return 0;
		}
	}
	return 1;
 
}
 
//----------------------
 
ll tut[N],tutmac[N];
 
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  	fo(i,1,n)
  		ar[i]=gondolaSeq[i-1];
  		ar[0]=0;
 	ll mki=0;
  	fo(i,1,n)
  	{
		tut[ar[i]]=i;
  		if(ar[i]>ar[mki])
  			mki=i;
  	}
 
  	ll cnt=-1;
  	ll l=ar[mki]-n;
 
 	fo(i,1,n)
 		tutmac[i]=ar[i];
	ll x=0;
	ar[0]=0;
	fo(i,1,n)
		if(ar[i]<=n)
		{
			x=i;
			break;
		}
	// fo(i,1,n)
	// cout<<ar[i]<<sp;
	// cout<<endl;
	fo(i,x+1,n)
	{
		ar[i]=ar[i-1]+1;
	
		ar[i]%=n;
		if(ar[i]<=0)
			ar[i]+=n;
	}
	for(int i=x-1;i>=1;i--)
	{
		ar[i]=ar[i+1]-1;
		ar[i]%=n;
		if(ar[i]<=0)
			ar[i]+=n;
	}
	// fo(i,1,n)
	// cout<<ar[i]<<sp;
	// cout<<endl;
	// cout<<mki<<endl;
	fo(i,n+1,tutmac[mki])
	{
		// cout<<i<<sp<<tut[i]<<sp<<ar[tut[i]]<<endl;
		if(tut[i])
		{
			replacementSeq[i-n-1]=ar[tut[i]];
			ar[tut[i]]=i;
		}
		else
		{
			replacementSeq[i-n-1]=ar[mki];
			ar[mki]=i;
		}
 
	}
	// cout<<l<<endl;
	// fo(i,0,l-1)
	// cout<<replacementSeq[i]<<sp;
	// cout<<endl;
	if(l<0)
		return -1;
	return l;
 
}

ll carp(ll x,ll y)
{
	x%=mod;
	x*=y%mod;
	x%=mod;
	while(x<0)
		x+=mod;
	return x%mod;
}
ll fp(ll a,ll b)
{
	if(b==0)
		return 1;
	ll x=fp(a,b/2);
	x=carp(x,x);
	if(b%2==1)
		x=carp(x,a);
	return x%mod;
}
 
//----------------------
 
int countReplacement(int n, int inputSeq[])
{
	// fo(i,0,n-1)
	// 	inputSeq[i]=ar[i];
	if(!valid(n,inputSeq))
		return 0;

	fo(i,1,n)
		ar[i]=inputSeq[i-1];
	sort(ar+1,ar+n+1);
	ll sum=1;
	ar[0]=n;
	int flag=0;
	// fo(i,1,n)
	// cout<<ar[i]<<sp;
	// cout<<endl;
	fo(i,1,n)
	{
		if(ar[i]<=n)
		{
			flag=1;
			continue;
		}
		ll x=max(n,ar[i-1]);
		// cout<<ar[i]<<sp<<fp(n-i+1,ar[i]-x)<<sp<<x<<endl;
		// cout<<n-i+1<<sp<<ar[i]-x<<sp<<fp(n-i+1,ar[i]-x)<<endl;
		sum=carp(sum,fp(n-i+1,ar[i]-x-1));
	}
	if(flag==0)
		sum=carp(sum,n);
	return sum;
}
 
 
// int bos[N];
 
// int main()
// {
// 	fast;
// 	ll n;
// 	cin>>n;
// 	fo(i,0,n-1)
// 	cin>>ar[i];
// 	// fo(i,0,n-1)
// 	// cout<<ar[i]<<sp;
// 	cout<<endl;
// 	cout<<countReplacement(n,bos);
// }

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:58:6: warning: unused variable 'flag' [-Wunused-variable]
  int flag=0;
      ^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:18:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define fo(i,x,y) for(ll i=x;i<=y;i++)
                   ^
gondola.cpp:77:4: note: in expansion of macro 'fo'
    fo(i,1,n)
    ^~
gondola.cpp:79:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     ar[0]=0;
     ^~
gondola.cpp:88:7: warning: unused variable 'cnt' [-Wunused-variable]
    ll cnt=-1;
       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 13 ms 640 KB Output is correct
7 Correct 22 ms 1024 KB Output is correct
8 Correct 18 ms 896 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 23 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 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 16 ms 640 KB Output is correct
7 Correct 22 ms 1024 KB Output is correct
8 Correct 17 ms 896 KB Output is correct
9 Correct 9 ms 512 KB Output is correct
10 Correct 27 ms 1024 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 12 ms 640 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 24 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 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 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 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 16 ms 2176 KB Output is correct
12 Correct 19 ms 2432 KB Output is correct
13 Correct 17 ms 2432 KB Output is correct
14 Correct 16 ms 2176 KB Output is correct
15 Correct 23 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 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 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 29 ms 1408 KB Output is correct
10 Correct 23 ms 1152 KB Output is correct
11 Correct 12 ms 640 KB Output is correct
12 Correct 13 ms 768 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 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 5 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 29 ms 1408 KB Output is correct
10 Correct 24 ms 1152 KB Output is correct
11 Correct 12 ms 640 KB Output is correct
12 Correct 14 ms 768 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 34 ms 1792 KB Output is correct
15 Correct 39 ms 2048 KB Output is correct
16 Correct 11 ms 640 KB Output is correct
17 Correct 27 ms 1500 KB Output is correct
18 Correct 17 ms 896 KB Output is correct