#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define sz size()
#define pb push_back
#define ll long long
map <int, bool> m;
ll md = 1e9 + 9;
int valid(int n, int inputSeq[]) {
int ind = -1;
for (int i = 0; i < n; ++i) {
if (m[inputSeq[i]]) return 0;
m[inputSeq[i]] = 1;
}
for (int i = 0; i < n; ++i) {
if (inputSeq[i] <= n) {
ind = i;
break;
}
}
if (ind == -1) return 1;
int val = inputSeq[ind] - 1;
for (int i = 0; i < n; ++i) {
if (inputSeq[ind] <= n and (val + 1) != inputSeq[ind]) {
return 0;
}
ind++;
val++;
ind %= n;
val %= n;
}
return 1;
}
int replacement(int n, int arr[], int rep[]) {
int mx = -1, mn = 1e9;
for (int i = 0; i < n; ++i) {
mx = max(mx, arr[i]);
mn = min (mn, arr[i]);
}
int o = 0;
if (mx <= n)
return 0;
vector <int> orig(n, 0);
if (mn > n) {
for (int i = 0; i < n; ++i) {
orig[i] = i + 1;
}
}
else {
int pos;
for (int i = 0; i < n; ++i) {
if (arr[i] <= n) {
pos = i;
break;
}
}
int val = arr[pos];
for (int i = 0; i < n; ++i) {
orig[pos] = val;
pos++;
val++;
if (val > n) val = 1;
if (pos == n) pos = 0;
}
}
vector <int> idx;
for (int i = 0; i < n; ++i) {
if (arr[i] > n) {
idx.pb (i);
}
}
sort (idx.begin(), idx.end(), [&] (int x, int y) {
return (arr[x] < arr[y]);
});
int last = n + 1;
for (int i = 0; i < (int)idx.sz; ++i) {
rep[o++] = orig[idx[i]];
while (last < arr[idx[i]]) {
rep[o++] = last++;
}
last++;
}
return o;
}
ll solve (int x, int y) {
if (y == 0) return 1;
ll jp = solve (x, y / 2);
jp *= jp;
jp %= md;
if (y % 2 == 1) {
jp *= x;
jp %= md;
}
return jp;
}
int countReplacement(int n, int arr[]) {
if (!valid(n, arr)) {
return 0;
}
int mx = 0, mn = 1e9;
for (int i = 0; i < n; ++i) {
mx = max(mx, arr[i]);
mn = min (mn, arr[i]);
}
int o = 0;
if (mx <= n)
return 1;
vector <int> orig(n, 0);
if (mn > n) {
for (int i = 0; i < n; ++i) {
orig[i] = i + 1;
}
}
else {
int pos;
for (int i = 0; i < n; ++i) {
if (arr[i] <= n) {
pos = i;
break;
}
}
int val = arr[pos];
for (int i = 0; i < n; ++i) {
orig[pos] = val;
pos++;
val++;
if (val > n) val = 1;
if (pos == n) pos = 0;
}
}
vector <int> idx;
for (int i = 0; i < n; ++i) {
if (arr[i] > n) {
idx.pb (i);
}
}
sort (idx.begin(), idx.end(), [&] (int x, int y) {
return (arr[x] < arr[y]);
});
ll jogap = 1;
if (mn > n) jogap = n;
int last = n + 1;
for (int i = 0; i < (int)idx.sz; ++i) {
ll jj = idx.sz - i;
ll ii = (arr[idx[i]]-1) - last + 1;
ll kp = solve (jj, ii);
if (kp == 0) kp = 1;
jogap *= kp;
// jogap *= (ii * jj) % md;
jogap %= md;
last = arr[idx[i]] + 1;
}
return jogap;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:113:6: warning: unused variable 'o' [-Wunused-variable]
113 | int o = 0;
| ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:60:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | int val = arr[pos];
| ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:130:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
130 | int val = arr[pos];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 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 |
10 ms |
2388 KB |
Output is correct |
7 |
Correct |
10 ms |
1236 KB |
Output is correct |
8 |
Correct |
19 ms |
4328 KB |
Output is correct |
9 |
Correct |
6 ms |
1492 KB |
Output is correct |
10 |
Correct |
23 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2428 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
21 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
1492 KB |
Output is correct |
10 |
Correct |
32 ms |
4884 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
17 ms |
2272 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
31 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
1 ms |
256 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
1060 KB |
Output is correct |
12 |
Correct |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
11 ms |
1492 KB |
Output is correct |
14 |
Correct |
9 ms |
1064 KB |
Output is correct |
15 |
Correct |
17 ms |
2436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
44 ms |
5144 KB |
Output is correct |
10 |
Correct |
28 ms |
4300 KB |
Output is correct |
11 |
Correct |
11 ms |
1876 KB |
Output is correct |
12 |
Correct |
13 ms |
2132 KB |
Output is correct |
13 |
Correct |
3 ms |
700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
336 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 |
9 |
Correct |
37 ms |
5144 KB |
Output is correct |
10 |
Correct |
29 ms |
4404 KB |
Output is correct |
11 |
Correct |
10 ms |
1876 KB |
Output is correct |
12 |
Correct |
15 ms |
2132 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
44 ms |
6348 KB |
Output is correct |
15 |
Correct |
50 ms |
6980 KB |
Output is correct |
16 |
Correct |
12 ms |
1620 KB |
Output is correct |
17 |
Correct |
45 ms |
4684 KB |
Output is correct |
18 |
Correct |
17 ms |
2996 KB |
Output is correct |