#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define f0(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
const long long mod = 1e9 + 9;
long long powMod(long long a, long long b) {
long long res = 1;
while(b) {
if(b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int valid(int n, int inputSeq[]) {
set<int> s;
f0(i, n) {
s.insert(inputSeq[i]);
}
if(s.size() != n) return 0;
f0(i, n) {
if(inputSeq[i] <= n) {
f0(j, n) {
if(inputSeq[(i+j)%n] <= n) {
if((inputSeq[(i+j)%n] - inputSeq[i] + n) % n != j)
return 0;
}
}
break;
}
}
return 1;
return -1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int mx = -1;
f0(i, n) mx = max(mx, gondolaSeq[i]);
bool used[mx + 1] = {false};
f0(i, n) used[gondolaSeq[i]] = true;
int l = mx - n;
f0(i, l) replacementSeq[i] = -1;
int delta = 0;
f0(i, n) {
if(gondolaSeq[i] <= n) {
delta = (gondolaSeq[i] - i - 1 + n) % n;
break;
}
}
f0(i, n) {
if(gondolaSeq[i] > n) {
if(gondolaSeq[i] == mx) {
int ind = l-1;
for(int j = mx; j > n; j--) {
if(!used[j]) {
replacementSeq[ind] = j;
ind = j - n - 1;
}
}
replacementSeq[ind] = (i + delta) % n + 1;
} else {
replacementSeq[gondolaSeq[i] - n - 1] = (i + delta) % n + 1;
}
}
}
return l;
return -2;
}
//----------------------
int countReplacement(int n, int inputSeq[]) {
int val = valid(n, inputSeq);
if(val == 0) return 0;
long long res = n;
// long long bigCnt = 0;
// f0(i, n) {
// if(inputSeq[i] > n) {
// bigCnt++;
// }
// // mx = max(mx, (long long)inputSeq[i]);
// }
// bool used[mx + 1] = {false};
// f0(i, n) used[inputSeq[i]] = true;
vector<int> used = {n};
f0(i, n) {
if(inputSeq[i] > n) {
used.push_back(inputSeq[i]);
} else {
res = 1;
}
}
int bigCnt = used.size() - 1;
sort(used.begin(), used.end());
int nn = used.size();
f0(i, nn-1) {
int cnt = used[i+1] - used[i] - 1;
res = (res * powMod(bigCnt, cnt)) % mod;
bigCnt--;
}
// cout << bigCnt << endl;
return res;
return -3;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:28:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
28 | if(s.size() != n) return 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 |
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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
2104 KB |
Output is correct |
7 |
Correct |
25 ms |
3572 KB |
Output is correct |
8 |
Correct |
18 ms |
3908 KB |
Output is correct |
9 |
Correct |
6 ms |
1364 KB |
Output is correct |
10 |
Correct |
27 ms |
4488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
2172 KB |
Output is correct |
7 |
Correct |
25 ms |
3640 KB |
Output is correct |
8 |
Correct |
23 ms |
3924 KB |
Output is correct |
9 |
Correct |
6 ms |
1364 KB |
Output is correct |
10 |
Correct |
28 ms |
4400 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
11 ms |
2012 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
39 ms |
4704 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
2 ms |
340 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 |
1 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 |
7 ms |
612 KB |
Output is correct |
12 |
Correct |
9 ms |
740 KB |
Output is correct |
13 |
Correct |
15 ms |
1196 KB |
Output is correct |
14 |
Correct |
9 ms |
628 KB |
Output is correct |
15 |
Correct |
16 ms |
2232 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
212 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 |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
30 ms |
3972 KB |
Output is correct |
10 |
Correct |
23 ms |
3352 KB |
Output is correct |
11 |
Correct |
8 ms |
1440 KB |
Output is correct |
12 |
Correct |
15 ms |
1620 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
220 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 |
224 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
31 ms |
4040 KB |
Output is correct |
10 |
Correct |
26 ms |
3320 KB |
Output is correct |
11 |
Correct |
10 ms |
1340 KB |
Output is correct |
12 |
Correct |
10 ms |
1620 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
39 ms |
5332 KB |
Output is correct |
15 |
Correct |
52 ms |
5964 KB |
Output is correct |
16 |
Correct |
7 ms |
1340 KB |
Output is correct |
17 |
Correct |
27 ms |
4052 KB |
Output is correct |
18 |
Correct |
14 ms |
2476 KB |
Output is correct |