Submission #100240

# Submission time Handle Problem Language Result Execution time Memory
100240 2019-03-10T02:22:49 Z luciocf Gondola (IOI14_gondola) C++14
100 / 100
126 ms 6576 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;

const int mod = 1e9+9;

typedef long long ll;

typedef pair<int, int> pii;

int valid(int n, int inputSeq[])
{
	int g[n+1];
	
	map<int, bool> mark;

	int first = -1;

	for (int i = 0; i < n; i++)
	{
		g[i] = inputSeq[i];

		if (mark[g[i]]) return 0;
		mark[g[i]] = 1;

		if (g[i] <= n && first == -1) first = i;
	}

	int cur = g[first];

	for (int i = first+1; i < n; i++)
	{
		cur = (cur == n ? 1 : cur+1);
		if (g[i] <= n && g[i] != cur) return 0;
	}

	for (int i = 0; i < first; i++)
	{
		cur = (cur == n ? 1 : cur+1);
		if (g[i] <= n && g[i] != cur) return 0;
	}

	return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int g[n+1], ind[n+1];

	int first = -1;

	for (int i = 0; i < n; i++)
	{
		g[i] = gondolaSeq[i];

		if (g[i] <= n && first == -1) first = i;
	}

	if (first == -1)
	{
		for (int i = 0; i < n; i++)
			ind[i] = i+1;
	}
	else
	{
		int cur = g[first];

		for (int i = first+1; i < n; i++)
		{
			cur = (cur == n ? 1 : cur+1);

			ind[i] = cur;
		}

		for (int i = 0; i < first; i++)
		{
			cur = (cur == n ? 1 : cur+1);

			ind[i] = cur;
		}
	}

	int l = 0;
	priority_queue<pii, vector<pii>, greater<pii> > pq;

	for (int i = 0; i < n; i++) if (g[i] > n) pq.push({g[i], i});

	int cur = n+1;
	while (!pq.empty())
	{
		int v = pq.top().first, i = pq.top().second;
		pq.pop();

		replacementSeq[l++] = ind[i];
		
		while (cur < v) 
			replacementSeq[l++] = cur++;
		cur++;
	}

	return l;
}

//----------------------

ll pot(ll a, ll b)
{
	if (!b) return 1ll;

	ll t = pot(a, b/2);

	if (b%2 == 0) return (t*t)%mod;
	return (a*((t*t)%mod))%mod;
}

int countReplacement(int n, int inputSeq[])
{
	if (!valid(n, inputSeq)) return 0;

	int last = n+1, less;
	ll ans = 1ll;

	bool dif = 0;

	sort(inputSeq, inputSeq+n);

	int pos = n+1;

	for (int i = 0; i < n; i++)
	{
		if (inputSeq[i] > n && pos == n+1) pos = i;
		else if (inputSeq[i] <= n) dif = 1;
	}

	less = n-pos;

	for (int i = pos; i < n; i++)
	{
		int v = inputSeq[i];

		ans = (ans*pot(1ll*less, 1ll*(v-last)))%mod;

		last = v+1, less--;
	}

	if (!dif)
	{
		ans = (ans*1ll*n)%mod;
	}

	return ans;
}
# 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 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 19 ms 2432 KB Output is correct
7 Correct 15 ms 640 KB Output is correct
8 Correct 31 ms 4216 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 47 ms 4856 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 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 19 ms 2432 KB Output is correct
7 Correct 13 ms 700 KB Output is correct
8 Correct 40 ms 4216 KB Output is correct
9 Correct 14 ms 1536 KB Output is correct
10 Correct 43 ms 4860 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 24 ms 2304 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 57 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 380 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 428 KB Output is correct
7 Correct 2 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 3 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 3 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 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 16 ms 1272 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 22 ms 1552 KB Output is correct
14 Correct 13 ms 1280 KB Output is correct
15 Correct 33 ms 2408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 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 428 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 444 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 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 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 83 ms 4384 KB Output is correct
10 Correct 55 ms 3704 KB Output is correct
11 Correct 23 ms 1536 KB Output is correct
12 Correct 24 ms 1784 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 77 ms 4344 KB Output is correct
10 Correct 60 ms 3704 KB Output is correct
11 Correct 19 ms 1536 KB Output is correct
12 Correct 25 ms 1864 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 85 ms 4956 KB Output is correct
15 Correct 126 ms 6576 KB Output is correct
16 Correct 18 ms 1408 KB Output is correct
17 Correct 64 ms 4416 KB Output is correct
18 Correct 39 ms 2552 KB Output is correct