Submission #232107

# Submission time Handle Problem Language Result Execution time Memory
232107 2020-05-16T04:05:47 Z spdskatr Gondola (IOI14_gondola) C++14
100 / 100
32 ms 2428 KB
#include "gondola.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#define fi first
#define se second
#define MOD 1000000009

using namespace std;
typedef pair<int, int> pii;

int valid(int n, int inputSeq[]) {
	int offset = -1;
	for (int i = 0; i < n; i++) {
		if (inputSeq[i] <= n) {
			offset = (i - inputSeq[i] + 1 + n) % n;
			break;
		}
	}
	set<int> seen;
	if (offset == -1) {
		for (int i = 0; i < n; i++) {
			if (seen.find(inputSeq[i]) != seen.end()) return 0;
			seen.insert(inputSeq[i]);
		}
		return 1;
	} else {
		for (int i = 0; i < n; i++) {
			int ind = (offset+i) % n;
			if (inputSeq[ind] <= n) {
				if (inputSeq[ind] != i+1) return 0;
			} else {
				if (seen.find(inputSeq[ind]) != seen.end()) return 0;
				seen.insert(inputSeq[ind]);
			}
		}
	}
	return 1;
}

//----------------------
namespace T2 {
	int original[100005], cnt;
	vector<pii> elems;

	int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
		int offset = -1;
		for (int i = 0; i < n; i++) {
			if (gondolaSeq[i] <= n) {
				offset = (i - gondolaSeq[i] + 1 + n) % n;
				break;
			}
		}
		if (offset == -1) {
			for (int i = 0; i < n; i++) original[i] = i+1;
		} else {
			for (int i = 0; i < n; i++) {
				original[(offset+i)%n] = i+1;
			}
		}
		for (int i = 0; i < n; i++) {
			if (gondolaSeq[i] > n) {
				elems.push_back({ gondolaSeq[i], i });
			}
		}
		sort(elems.begin(), elems.end());
		int cur = n+1;
		for (int i = 0; i < elems.size(); i++) {
			while (elems[i].fi >= cur) {
				replacementSeq[cnt++] = original[elems[i].se];
				original[elems[i].se] = cur++;
			}
		}
		return cnt;
	}
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	return T2::replacement(n, gondolaSeq, replacementSeq);
}

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

namespace T3 {
	typedef long long ll;
	vector<pii> elems;
	
	ll ex(ll n, ll p) {
		ll res = 1, cur = n;
		for (int b = 0; p > 0; b++) {
			if ((p >> b) & 1) {
				res = (res * cur) % MOD;
				p ^= (1 << b);
			}
			cur = (cur * cur) % MOD;
		}
		return res;
	}
	int countReplacement(int n, int inputSeq[]) {
		int offset = -1;
		ll ans = 1;
		for (int i = 0; i < n; i++) {
			if (inputSeq[i] <= n) {
				offset = (i - inputSeq[i] + 1 + n) % n;
				break;
			}
		}
		if (offset == -1) {
			ans *= n;
		} else {
			for (int i = 0; i < n; i++) {
				int ind = (offset+i) % n;
				if (inputSeq[ind] < n && inputSeq[ind] != i+1) return 0;
			}
		}
		for (int i = 0; i < n; i++) {
			if (inputSeq[i] > n) {
				elems.push_back({ inputSeq[i], i });
			}
		}
		sort(elems.begin(), elems.end());
		int cur = n+1;
		for (int i = 0; i < elems.size(); i++) {
			if (elems[i].fi < cur) return 0;
			ll p = (elems[i].fi - cur);
			ans = (ans * (ex(elems.size() - i, p) % MOD)) % MOD;
			cur = elems[i].fi + 1;
		}
		return (int)ans;
	}
}

int countReplacement(int n, int inputSeq[])
{
	return T3::countReplacement(n, inputSeq);
}

Compilation message

gondola.cpp: In function 'int T2::replacement(int, int*, int*)':
gondola.cpp:71:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < elems.size(); i++) {
                   ~~^~~~~~~~~~~~~~
gondola.cpp: In function 'int T3::countReplacement(int, int*)':
gondola.cpp:126:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < elems.size(); i++) {
                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 17 ms 640 KB Output is correct
8 Correct 14 ms 640 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 15 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 16 ms 688 KB Output is correct
8 Correct 15 ms 640 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 15 ms 640 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 10 ms 768 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 17 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 128 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 15 ms 896 KB Output is correct
12 Correct 17 ms 1024 KB Output is correct
13 Correct 21 ms 1660 KB Output is correct
14 Correct 15 ms 896 KB Output is correct
15 Correct 28 ms 2428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 128 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 22 ms 1276 KB Output is correct
10 Correct 19 ms 1148 KB Output is correct
11 Correct 10 ms 768 KB Output is correct
12 Correct 12 ms 896 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 23 ms 1268 KB Output is correct
10 Correct 19 ms 1148 KB Output is correct
11 Correct 11 ms 768 KB Output is correct
12 Correct 11 ms 768 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 28 ms 1784 KB Output is correct
15 Correct 32 ms 1784 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 22 ms 1148 KB Output is correct
18 Correct 14 ms 1148 KB Output is correct