Submission #656847

# Submission time Handle Problem Language Result Execution time Memory
656847 2022-11-08T10:01:33 Z happypotato Gondola (IOI14_gondola) C++17
100 / 100
35 ms 5004 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

int valid(int n, int inputSeq[])
{
	int seq[n];
	set<int> s;
	for (int i = 0; i < n; i++) {
		seq[i] = (inputSeq[i] <= n ? inputSeq[i] : -1);
		if (s.find(inputSeq[i]) != s.end()) return 0;
		s.insert(inputSeq[i]);
	}
	int samemod = -1;
	for (int i = 0; i < n; i++) {
		if (seq[i] == -1) continue;
		int curmod = (seq[i] + n - i) % n;
		if (samemod == -1) samemod = curmod;
		else if (samemod != curmod) return 0;
	}
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	vector<pair<int, int>> v;
	v.push_back({n, -1});
	int samemod = 0;
	for (int i = 0; i < n; i++) {
		if (gondolaSeq[i] <= n) {
			samemod = (gondolaSeq[i] + n - i) % n;
		} else {
			v.push_back({gondolaSeq[i], i});
		}
	}
	sort(v.begin(), v.end());
	int ptr = 0;
	for (int i = 1; i < int(v.size()); i++) {
		int ori = (v[i].second + samemod) % n;
		if (ori == 0) ori = n;
		replacementSeq[ptr++] = ori;
		for (int j = v[i - 1].first + 2; j <= v[i].first; j++) {
			replacementSeq[ptr++] = j - 1;
		}
	}
	return ptr;
}

//----------------------
const long long MOD = 1e9 + 9;
long long bigmod(long long b, int p) {
	long long ans = 1;
	while (p) {
		if (p & 1) ans = (ans * b) % MOD;
		p >>= 1;
		b = (b * b) % MOD;
	}
	return ans;
}
int countReplacement(int n, int inputSeq[])
{
	vector<int> v;
	v.push_back(n);
	int samemod = 0;
	for (int i = 0; i < n; i++) {
		if (inputSeq[i] > n) {
			v.push_back(inputSeq[i]);
		}
	}
	sort(v.begin(), v.end());
	int m = v.size();
	long long ans = (m == n + 1 ? n : 1);
	for (int i = 1; i < m; i++) {
		ans = (ans * bigmod(m - i, (v[i] - v[i - 1] - 1))) % MOD;
	}
	return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:66:6: warning: unused variable 'samemod' [-Wunused-variable]
   66 |  int samemod = 0;
      |      ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 8 ms 932 KB Output is correct
8 Correct 26 ms 4152 KB Output is correct
9 Correct 7 ms 1556 KB Output is correct
10 Correct 30 ms 4836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 13 ms 2324 KB Output is correct
7 Correct 8 ms 980 KB Output is correct
8 Correct 22 ms 4184 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 30 ms 4820 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 13 ms 2228 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 35 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 6 ms 616 KB Output is correct
12 Correct 8 ms 652 KB Output is correct
13 Correct 12 ms 1252 KB Output is correct
14 Correct 7 ms 584 KB Output is correct
15 Correct 17 ms 2216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 12 ms 1380 KB Output is correct
10 Correct 10 ms 1208 KB Output is correct
11 Correct 4 ms 684 KB Output is correct
12 Correct 6 ms 812 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 272 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 14 ms 1364 KB Output is correct
10 Correct 10 ms 1236 KB Output is correct
11 Correct 4 ms 704 KB Output is correct
12 Correct 8 ms 728 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 17 ms 2092 KB Output is correct
15 Correct 20 ms 2128 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 13 ms 1556 KB Output is correct
18 Correct 7 ms 1088 KB Output is correct