Submission #168610

# Submission time Handle Problem Language Result Execution time Memory
168610 2019-12-14T09:01:14 Z johutha Gondola (IOI14_gondola) C++14
100 / 100
37 ms 3448 KB
#include "gondola.h"
#include <vector>
#include <algorithm>
#include <iostream>

#define int int64_t

using namespace std;

const int mod = 1e9 + 9;

signed fastpowmod(int base, int exp)
{
	int res = 1;
	for (; exp; exp /= 2)
	{
		if (exp & 1) res = (res*base) % mod;
		base = (base*base) % mod;
	}

	return res;
}

signed valid(signed n, signed inputSeq[])
{
	vector<int> dcheck;
	for (int i = 0; i < n; i++)
	{
		inputSeq[i]--;
		dcheck.push_back(inputSeq[i]);
	}
	
	sort(dcheck.begin(), dcheck.end());
	for (int i = 1; i < n; i++)
	{
		if (dcheck[i] == dcheck[i - 1]) return 0;
	}

	int zval = 0;
	for (int i = 0; i < n; i++)
	{
		if (inputSeq[i] < n)
		{
			zval = inputSeq[i] - i;
			break;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (inputSeq[i] < n)
		{
			if ((zval + i + n) % n != inputSeq[i]) return 0;
		}
	}

	return 1;
}

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

signed replacement(signed n, signed gondolaSeq[], signed replacementSeq[])
{
	vector<int> Seq;
	
	for (int i = 0; i < n; i++) Seq.push_back(gondolaSeq[i] - 1);

	int zval = 0;
	for (int i = 0; i < n; i++)
	{
		if (Seq[i] < n)
		{
			zval = Seq[i] - i;
			break;
		}
	}

	rotate(Seq.rbegin(), Seq.rbegin() + ((zval + n) % n), Seq.rend());
	int mmax = *max_element(Seq.begin(), Seq.end());
	int mind = -1;

	for (int i = 0; i <= mmax - n; i++) replacementSeq[i] = -1;

	for (int i = 0; i < n; i++)
	{
		if (Seq[i] == mmax) mind = i;
		if (Seq[i] >= n) replacementSeq[Seq[i] - n] = i + 1;
	}

	mind++;
	for (int i = 0; i <= mmax - n; i++)
	{
		if (replacementSeq[i] == -1)
		{
			replacementSeq[i] = mind;
			mind = n + i + 1;
		}
	}
	replacementSeq[mmax - n] = mind;

	return mmax - n + 1;
}

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

signed countReplacement(signed n, signed inputSeq[])
{
	if (!valid(n, inputSeq)) return 0;
	
	vector<int> ndef;
	int res = n;
	int nused = 0;

	for (int i = 0; i < n; i++)
	{
		if (inputSeq[i] < n) { res = 1; nused++; }
		else
		{
			ndef.push_back(inputSeq[i]);
		}
	}

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

	int curr = n;

	for (int i = 0; i < (int)ndef.size(); i++)
	{
		res = (res * fastpowmod(n - nused - i, ndef[i] - curr)) % mod;
		curr = ndef[i] + 1;
	}

	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 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
# 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 256 KB Output is correct
6 Correct 10 ms 1100 KB Output is correct
7 Correct 20 ms 1776 KB Output is correct
8 Correct 15 ms 1772 KB Output is correct
9 Correct 7 ms 760 KB Output is correct
10 Correct 21 ms 1776 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 10 ms 1140 KB Output is correct
7 Correct 21 ms 1904 KB Output is correct
8 Correct 15 ms 1780 KB Output is correct
9 Correct 7 ms 888 KB Output is correct
10 Correct 21 ms 1776 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 10 ms 1140 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 22 ms 1904 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
# 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 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
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 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 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
11 Correct 13 ms 1772 KB Output is correct
12 Correct 14 ms 1776 KB Output is correct
13 Correct 15 ms 1364 KB Output is correct
14 Correct 13 ms 1776 KB Output is correct
15 Correct 23 ms 2272 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 8 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 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 256 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 27 ms 1732 KB Output is correct
10 Correct 22 ms 1772 KB Output is correct
11 Correct 9 ms 956 KB Output is correct
12 Correct 11 ms 1040 KB Output is correct
13 Correct 4 ms 504 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 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 26 ms 1776 KB Output is correct
10 Correct 21 ms 1840 KB Output is correct
11 Correct 9 ms 1000 KB Output is correct
12 Correct 11 ms 1040 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 34 ms 3184 KB Output is correct
15 Correct 37 ms 3448 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 25 ms 2160 KB Output is correct
18 Correct 15 ms 1612 KB Output is correct