Submission #100238

# Submission time Handle Problem Language Result Execution time Memory
100238 2019-03-10T02:17:48 Z luciocf Gondola (IOI14_gondola) C++14
90 / 100
40 ms 2552 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];
	bool mark[250050];

	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;

	priority_queue<int, vector<int>, greater<int> > pq;

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

	less = pq.size();

	while (!pq.empty())
	{
		int v = pq.top();
		pq.pop();

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

		last = v+1, less--;
	}

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

	return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:16: warning: 'mark[<unknown>]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (mark[g[i]]) return 0;
       ~~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 3 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 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 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 3 ms 384 KB Output is correct
6 Correct 8 ms 896 KB Output is correct
7 Correct 19 ms 1280 KB Output is correct
8 Correct 12 ms 1280 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 40 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 8 ms 896 KB Output is correct
7 Correct 15 ms 1280 KB Output is correct
8 Correct 12 ms 1280 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 11 ms 1536 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 7 ms 1024 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 14 ms 1664 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 3 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 3 ms 256 KB Output is correct
5 Correct 2 ms 360 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 2 ms 384 KB Output is correct
10 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 2 ms 256 KB Output is correct
5 Correct 3 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 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
11 Correct 12 ms 1664 KB Output is correct
12 Correct 12 ms 1920 KB Output is correct
13 Correct 18 ms 1808 KB Output is correct
14 Correct 14 ms 1664 KB Output is correct
15 Correct 23 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 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 256 KB Output is correct
4 Correct 3 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
# 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 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 23 ms 1920 KB Output is correct
10 Correct 21 ms 1664 KB Output is correct
11 Correct 9 ms 1024 KB Output is correct
12 Correct 10 ms 1024 KB Output is correct
13 Correct 4 ms 576 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 256 KB Output is correct
4 Correct 3 ms 356 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 3 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 Correct 22 ms 1920 KB Output is correct
10 Correct 19 ms 1792 KB Output is correct
11 Correct 10 ms 1024 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 5 ms 484 KB Output is correct
14 Runtime error 17 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -