Submission #136080

# Submission time Handle Problem Language Result Execution time Memory
136080 2019-07-24T17:13:20 Z arthurconmy Gondola (IOI14_gondola) C++14
100 / 100
108 ms 6648 KB
#include <bits/stdc++.h>
#ifndef ARTHUR_LOCAL
	#include "gondola.h"
#endif
using namespace std;
using ll = long long;

map<int,int> used;
const ll p = 1000000009;

ll modpow(ll a, ll b)
{
	if(b==0LL) return 1LL;

	ll cur = modpow(a,ll(b/2LL));
	cur*=cur;
	cur%=p;

	if(b%2 == 1LL) cur*=a;
	cur%=p;

	return cur;
}

int valid(int n, int S[])
{
	pair<int,int> minn = {int(1e9),int(1e9)};

	for(int i=0; i<n; i++)
	{
		if(used[S[i]]==1) return 0;
		used[S[i]]=1;

		minn = min(minn, make_pair(S[i],i));
	}

	int cur = minn.first;
	if(cur>n) return 1;

	int one_pos = (minn.second - minn.first + 1 + n)%n;

	for(int j=0; j<n; j++)
	{
		if(S[(one_pos+j)%n] == j+1 || S[(one_pos+j)%n]>n) continue;
		return 0;
	}

	return 1;
}

int replacement(int n, int G[], int R[])
{
	pair<int,int> minn = {int(1e9),int(1e9)};

	for(int i=0; i<n; i++)
	{
		minn = min(minn, make_pair(G[i],i));
	}

	int cur = minn.first;

	int one_pos = (minn.second - minn.first + 1 + n)%n;

	if(cur>n) one_pos=0;

	vector<pair<int,int>> reps;

	for(int j=0; j<n; j++)
	{
		if(G[(one_pos+j)%n] == j+1) continue;
		reps.push_back(make_pair(G[(one_pos+j)%n],j+1));
	}

	sort(reps.begin(),reps.end());

	int ans=0;
	int next_boat=n+1;

	for(auto rep:reps)
	{
		int cur = rep.second;

		for(int i=next_boat; i<=rep.first; i++)
		{
			// cout << cur << endl;
			R[ans] = cur;
			cur=next_boat;

			ans++;
			next_boat++;
		}
	}

	// cout << endl;

	return ans;
}

int countReplacement(int n, int S[])
{
	pair<int,int> minn = {int(1e9),int(1e9)};

	for(int i=0; i<n; i++)
	{
		if(used[S[i]]==1) return 0;
		used[S[i]]=1;

		minn = min(minn, make_pair(S[i],i));
	}

	int cur = minn.first;
	int one_pos=-1;
	bool orientation_lost=0;

	if(cur>n)
	{
		one_pos=0;
		orientation_lost=1;
	}

	else
	{
		one_pos = (minn.second - minn.first + 1 + n)%n;
		orientation_lost=0;
	}

	if(cur>n)
	{
		one_pos=0;
		orientation_lost=1;
	}

	for(int j=0; j<n; j++)
	{
		if(S[(one_pos+j)%n] == j+1 || S[(one_pos+j)%n]>n) continue;
		return 0;
	}

	vector<int> V={0};

	for(int j=0; j<n; j++)
	{
		if(S[(one_pos+j)%n] == j+1) continue;
		V.push_back(S[(one_pos+j)%n]-n);
	}

	if(V.size()==1) return 1;

	sort(V.begin(),V.end());
	// for(auto v:V) cout << v << endl;

	ll ans=1;

	for(int i=1; i<int(V.size()); i++)
	{
		ans*=modpow(ll(V.size())-ll(i),ll(V[i]-V[i-1]-1));
		ans%=p;
	}

	if(orientation_lost)
	{
		ans*=n;
		ans%=p;
	}

	return int(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 20 ms 2168 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 35 ms 3960 KB Output is correct
9 Correct 12 ms 1528 KB Output is correct
10 Correct 48 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 22 ms 2168 KB Output is correct
7 Correct 13 ms 636 KB Output is correct
8 Correct 36 ms 3960 KB Output is correct
9 Correct 12 ms 1528 KB Output is correct
10 Correct 108 ms 4600 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 24 ms 2168 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 57 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 12 ms 632 KB Output is correct
12 Correct 13 ms 632 KB Output is correct
13 Correct 17 ms 1400 KB Output is correct
14 Correct 12 ms 632 KB Output is correct
15 Correct 25 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 63 ms 4600 KB Output is correct
10 Correct 47 ms 3832 KB Output is correct
11 Correct 17 ms 1656 KB Output is correct
12 Correct 21 ms 1912 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 76 ms 4472 KB Output is correct
10 Correct 49 ms 3960 KB Output is correct
11 Correct 18 ms 1720 KB Output is correct
12 Correct 21 ms 1912 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 73 ms 5240 KB Output is correct
15 Correct 82 ms 6648 KB Output is correct
16 Correct 32 ms 1676 KB Output is correct
17 Correct 54 ms 4604 KB Output is correct
18 Correct 29 ms 2808 KB Output is correct