Submission #222744

# Submission time Handle Problem Language Result Execution time Memory
222744 2020-04-13T23:15:05 Z staniewzki Gondola (IOI14_gondola) C++17
100 / 100
33 ms 2292 KB
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.ST << ", " << p.ND << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
template<class T> int size(T && a) { return (int) a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

#include "gondola.h"

int valid(int n, int inputSeq[]) {
	int origin = -1, mx = -1;
	REP(i, n) {
		mx = max(mx, inputSeq[i]);
		if(inputSeq[i] <= n) {
			int x = (i - inputSeq[i] + n) % n;
			if(origin == -1) origin = x;
			if(origin != x) return false;
		}
	}

	vector<int> used(mx + 1);
	REP(i, n) {
		if(used[inputSeq[i]]) return false;
		used[inputSeq[i]] = true;
	}
	return true;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	int origin = -1, mx = -1;
	REP(i, n) {
		mx = max(mx, gondolaSeq[i]);
		if(gondolaSeq[i] <= n && origin == -1)
			origin = (i - gondolaSeq[i] + n) % n;
	}

	vector<int> pos(mx + 1, -1);
	REP(i, n) pos[gondolaSeq[i]] = i;

	vector<int> Q;
	int cur = 0;
	FOR(i, n + 1, mx) {
		Q.emplace_back(i);
		if(pos[i] != -1) {
			int last = (pos[i] - origin + n) % n;
			if(last == 0) last = n;
			for(int x : Q) {
				replacementSeq[cur++] = last;
				last = x;
			}
			Q.clear();
		}
	}

	return cur;
}

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

int countReplacement(int n, int inputSeq[]) {
	int origin = -1;
	REP(i, n) {
		if(inputSeq[i] <= n) {
			int x = (i - inputSeq[i] + n) % n;
			if(origin == -1) origin = x;
			if(origin != x) return false;
		}
	}

	vector<int> p = {n};
	REP(i, n) {
		if(inputSeq[i] > n) 
			p.emplace_back(inputSeq[i]);
	}

	sort(p.rbegin(), p.rend());

	const int mod = 1e9 + 9;
	int ans = (origin != -1 ? 1 : n) , suff = 0;

	function<int(int, int)> qpow = [&](int a, int x) -> int {
		if(x == 0) return 1;
		if(x % 2 == 1) return (LL) qpow(a, x - 1) * a % mod;
		return qpow((LL) a * a % mod, x / 2);
	};

	REP(i, size(p) - 1) {
		int len = p[i] - p[i + 1] - 1;
		if(len == -1) return false;
		ans = (LL) ans * qpow(++suff, len) % mod;
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 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 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 10 ms 640 KB Output is correct
7 Correct 17 ms 640 KB Output is correct
8 Correct 15 ms 896 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 17 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 10 ms 640 KB Output is correct
7 Correct 17 ms 640 KB Output is correct
8 Correct 15 ms 896 KB Output is correct
9 Correct 10 ms 512 KB Output is correct
10 Correct 16 ms 1024 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 10 ms 512 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 18 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 304 KB Output is correct
4 Correct 5 ms 384 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 384 KB Output is correct
8 Correct 5 ms 512 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 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 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 16 ms 896 KB Output is correct
12 Correct 17 ms 1024 KB Output is correct
13 Correct 18 ms 1248 KB Output is correct
14 Correct 16 ms 1024 KB Output is correct
15 Correct 25 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 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 6 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 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 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 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 23 ms 1024 KB Output is correct
10 Correct 19 ms 1024 KB Output is correct
11 Correct 10 ms 640 KB Output is correct
12 Correct 12 ms 640 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 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 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 4 ms 256 KB Output is correct
9 Correct 23 ms 1024 KB Output is correct
10 Correct 20 ms 896 KB Output is correct
11 Correct 10 ms 640 KB Output is correct
12 Correct 12 ms 640 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 30 ms 2172 KB Output is correct
15 Correct 33 ms 2292 KB Output is correct
16 Correct 10 ms 768 KB Output is correct
17 Correct 23 ms 1536 KB Output is correct
18 Correct 15 ms 1280 KB Output is correct