#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include "gondola.h"
typedef long long ll;
using namespace std;
int valid(int n, int v[])
{
vector<int> o(n, -1);
for (int i = 0; i < n; i++) v[i]--;
set<int> s(v, v + n);
for (int i = 0; i < n; i++)
{
if (v[i] >= n) continue;
o[i] = v[i];
for (int j = 0; j < n; j++) o[j] = (v[i] - i + j + n) % n;
break;
}
if (s.size() != n) return 0;
for (int i = 0; i < n; i++) if (v[i] < n && o[i] != v[i]) return 0;
return 1;
}
int replacement(int n, int v[], int r[]) { return 0; }
const ll mod = 1e9 + 9;
int mul(const int& a, const int& b) { return (a * 1ll * b) % mod; }
int add(const int& a, const int& b) { return (a + b) % mod; }
void upd(int& a, const int& b) { a = (a + b) % mod; }
int pwr(const int& a, const int& b)
{
if (!b) return 1;
int m = pwr(a, b >> 1); m = mul(m, m);
if (b & 1) m = mul(m, a);
return m;
}
int countReplacement(int n, int v[])
{
int *v2 = new int[n];
for (int i = 0; i < n; i++)v2[i] = v[i];
if (!valid(n, v2)) return 0;
int m = 1;
if (*min_element(v, v + n) > n)
m = n;
int num = 0;
vector<int> e;
for (int i = 0; i < n; i++)
{
if (v[i] > n) num++, e.push_back(v[i]);
}
sort(e.begin(), e.end()); int pv = n;
for (int i = 0; i < e.size(); i++)
{
m = mul(m, pwr(num, e[i] - pv - 1));
num--; pv = e[i];
}
return m;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:21:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
21 | if (s.size() != n) return 0;
| ~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < e.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
2508 KB |
Output is correct |
7 |
Correct |
35 ms |
4404 KB |
Output is correct |
8 |
Correct |
29 ms |
4528 KB |
Output is correct |
9 |
Correct |
6 ms |
1592 KB |
Output is correct |
10 |
Correct |
21 ms |
5288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
2508 KB |
Output is correct |
7 |
Correct |
32 ms |
4412 KB |
Output is correct |
8 |
Correct |
24 ms |
4580 KB |
Output is correct |
9 |
Correct |
6 ms |
1596 KB |
Output is correct |
10 |
Correct |
21 ms |
5304 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
16 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
42 ms |
5516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
43 ms |
5048 KB |
Output is correct |
10 |
Correct |
34 ms |
4160 KB |
Output is correct |
11 |
Correct |
15 ms |
1764 KB |
Output is correct |
12 |
Correct |
16 ms |
1996 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
53 ms |
4972 KB |
Output is correct |
10 |
Correct |
33 ms |
4168 KB |
Output is correct |
11 |
Correct |
12 ms |
1740 KB |
Output is correct |
12 |
Correct |
15 ms |
1996 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
52 ms |
5912 KB |
Output is correct |
15 |
Correct |
66 ms |
6772 KB |
Output is correct |
16 |
Correct |
10 ms |
1484 KB |
Output is correct |
17 |
Correct |
39 ms |
4548 KB |
Output is correct |
18 |
Correct |
21 ms |
2692 KB |
Output is correct |