#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;
}
}
/*
if (pos == -1) {
exit(1);
}
*/
vector <int> ar = {n};
for (int i = 0; i < n; ++i)
if (a[i] > n)
ar.app(a[i]);
sort(all(ar));
/*
cout << "ar : ";
for (int e : ar)
cout << e << ' ';
cout << endl;
*/
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));
}
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)
~~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:114:9: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
int pos = -1;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 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 |
17 ms |
2176 KB |
Output is correct |
7 |
Correct |
36 ms |
3704 KB |
Output is correct |
8 |
Correct |
29 ms |
3884 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
32 ms |
4572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
18 ms |
2176 KB |
Output is correct |
7 |
Correct |
35 ms |
3704 KB |
Output is correct |
8 |
Correct |
28 ms |
3960 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
33 ms |
4600 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
20 ms |
2048 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
44 ms |
4704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 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 |
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 |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 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 |
512 KB |
Output is correct |
11 |
Correct |
16 ms |
640 KB |
Output is correct |
12 |
Correct |
17 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 |
25 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 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 |
256 KB |
Output is correct |
5 |
Correct |
4 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 |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
45 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 |
18 ms |
1792 KB |
Output is correct |
13 |
Incorrect |
7 ms |
640 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
43 ms |
4092 KB |
Output is correct |
10 |
Correct |
35 ms |
3456 KB |
Output is correct |
11 |
Correct |
16 ms |
1408 KB |
Output is correct |
12 |
Correct |
19 ms |
1664 KB |
Output is correct |
13 |
Incorrect |
7 ms |
640 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |