답안 #261912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261912 2020-08-12T07:44:59 Z baluteshih 곤돌라 (IOI14_gondola) C++14
100 / 100
38 ms 3044 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD=1e9+9;
 
int valid(int n, int inputSeq[])
{
	int p=min_element(inputSeq,inputSeq+n)-inputSeq;
	vector<int> v(inputSeq,inputSeq+n);
	sort(ALL(v));
	for(int i=0;i+1<n;++i)
		if(v[i]==v[i+1]) return 0;
	if(inputSeq[p]>n) return 1;
	for(int i=p;i<p+n;++i)
		if(inputSeq[i%n]<=n&&inputSeq[i%n]!=inputSeq[p]+i-p)
			return 0;
	return 1;
}
 
//----------------------
 
int ans[300005];
 
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	vector<int> org(n);
	int p=min_element(gondolaSeq,gondolaSeq+n)-gondolaSeq;
	if(gondolaSeq[p]>n)
		for(int i=0;i<n;++i)
			org[i]=i+1;
	else
		for(int i=p;i<p+n;++i)
			org[i%n]=(gondolaSeq[p]+i-p-1)%n+1;
	vector<pii> v;
	for(int i=0;i<n;++i)
		if(gondolaSeq[i]>n)
			v.pb(MP(gondolaSeq[i],i));
	sort(ALL(v));
	int nw=n+1,tp=0;
	for(pii i:v)
	{
		ans[tp++]=org[i.S];
		while(nw<=i.F)
			ans[tp++]=nw++;
		--tp;
	}
	for(int i=0;i<tp;++i)
		replacementSeq[i]=ans[i];
	return tp;
}
 
//----------------------
 
ll pw(ll a,ll n)
{
	ll re=1;
	for(;n;n>>=1,a=a*a%MOD)
		if(n&1) re=re*a%MOD;
	return re;
}
 
int countReplacement(int n, int inputSeq[])
{
	if(!valid(n,inputSeq)) return 0;
	ll ans=1;
	if(*min_element(inputSeq,inputSeq+n)>n) ans=n;
	vector<int> v;
	for(int i=0;i<n;++i)
		if(inputSeq[i]>n)
			v.pb(inputSeq[i]);
	sort(ALL(v),greater<int>());
	for(int ls=n+1;!v.empty();ls=v.back()+1,v.pop_back())
		ans*=pw(v.size(),v.back()-ls),ans%=MOD;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 9 ms 896 KB Output is correct
7 Correct 21 ms 1536 KB Output is correct
8 Correct 16 ms 1280 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 22 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 9 ms 896 KB Output is correct
7 Correct 21 ms 1664 KB Output is correct
8 Correct 14 ms 1280 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 20 ms 1408 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 9 ms 896 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 22 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 13 ms 1408 KB Output is correct
12 Correct 15 ms 1528 KB Output is correct
13 Correct 18 ms 1952 KB Output is correct
14 Correct 13 ms 1408 KB Output is correct
15 Correct 24 ms 3044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 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 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 25 ms 1624 KB Output is correct
10 Correct 23 ms 1424 KB Output is correct
11 Correct 8 ms 784 KB Output is correct
12 Correct 10 ms 896 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 30 ms 1624 KB Output is correct
10 Correct 20 ms 1424 KB Output is correct
11 Correct 8 ms 768 KB Output is correct
12 Correct 10 ms 896 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 32 ms 2352 KB Output is correct
15 Correct 38 ms 2564 KB Output is correct
16 Correct 7 ms 800 KB Output is correct
17 Correct 24 ms 1668 KB Output is correct
18 Correct 13 ms 1268 KB Output is correct