#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#include "gondola.h"
signed valid(signed n, signed a[])
{
set <int> ms;
for (int i = 0; i < n; ++i)
ms.insert(a[i]);
if (ms.size() < n)
return 0;
int pos = -1;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
pos = i;
break;
}
}
if (pos == -1)
return 1;
else {
for (int sh = 0; sh < n; ++sh) {
int i = (pos + sh) % n;
int val = a[pos] + sh;
if (val > n)
val -= n;
if (a[i] <= n && a[i] != val)
return 0;
}
return 1;
}
}
//----------------------
signed replacement(signed n, signed a[], signed ans[])
{
int pos = -1, S;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
pos = i;
S = a[i];
break;
}
}
if (pos == -1) {
pos = 0;
S = 1;
}
vector <ii> ar;
for (int sh = 0; sh < n; ++sh) {
int i = (pos + sh) % n;
int val = S + sh;
if (val > n)
val -= n;
if (a[i] > n) {
ar.app(mp(a[i], val));
}
}
sort(all(ar));
int ptr = 0;
int xp = n + 1;
for (auto e : ar) {
int cur = e.s;
while (xp <= e.f) {
//cout << cur << "->" << xp << endl;
ans[ptr++] = cur;
cur = xp++;
}
}
return ptr;
}
//----------------------
const ll MOD = 1000 * 1000 * 1000 + 9;
ll mod(ll n) {
n %= MOD;
if (n < 0) return n + MOD;
else return n;
}
ll fp(ll a, ll p) {
ll ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
ll dv(ll a, ll b) { return mod(a * fp(b, MOD - 2)); }
signed countReplacement(signed n, signed a[])
{
if (!valid(n, a))
return 0;
int pos = -1;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
pos = i;
break;
}
}
vector <int> ar = {n};
for (int i = 0; i < n; ++i)
if (a[i] > n)
ar.app(a[i]);
sort(all(ar));
ll ans = 1;
int r = 0;
for (int i = (int)ar.size() - 2; i >= 0; --i) {
++r;
int len = ar[i + 1] - ar[i] - 1;
ans = mod(ans * fp(r, len));
}
if (pos == -1)
ans = mod(ans * n);
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ms.size() < n)
~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 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 |
5 ms |
256 KB |
Output is correct |
# |
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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
16 ms |
2176 KB |
Output is correct |
7 |
Correct |
36 ms |
3704 KB |
Output is correct |
8 |
Correct |
28 ms |
3968 KB |
Output is correct |
9 |
Correct |
12 ms |
1536 KB |
Output is correct |
10 |
Correct |
33 ms |
4608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
16 ms |
2176 KB |
Output is correct |
7 |
Correct |
34 ms |
3712 KB |
Output is correct |
8 |
Correct |
29 ms |
3968 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
32 ms |
4608 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
23 ms |
2176 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
42 ms |
4728 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 |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 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 |
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 |
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 |
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 |
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 |
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 |
15 ms |
640 KB |
Output is correct |
12 |
Correct |
16 ms |
640 KB |
Output is correct |
13 |
Correct |
20 ms |
1296 KB |
Output is correct |
14 |
Correct |
16 ms |
640 KB |
Output is correct |
15 |
Correct |
27 ms |
2424 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 |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
256 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 |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 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 |
5 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 |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
46 ms |
4088 KB |
Output is correct |
10 |
Correct |
36 ms |
3448 KB |
Output is correct |
11 |
Correct |
16 ms |
1408 KB |
Output is correct |
12 |
Correct |
19 ms |
1792 KB |
Output is correct |
13 |
Correct |
7 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
44 ms |
3992 KB |
Output is correct |
10 |
Correct |
36 ms |
3456 KB |
Output is correct |
11 |
Correct |
16 ms |
1408 KB |
Output is correct |
12 |
Correct |
19 ms |
1792 KB |
Output is correct |
13 |
Correct |
8 ms |
640 KB |
Output is correct |
14 |
Correct |
59 ms |
5368 KB |
Output is correct |
15 |
Correct |
69 ms |
6008 KB |
Output is correct |
16 |
Correct |
14 ms |
1408 KB |
Output is correct |
17 |
Correct |
41 ms |
4216 KB |
Output is correct |
18 |
Correct |
24 ms |
2432 KB |
Output is correct |