#include<iostream>
#include<algorithm>
#include "gondola.h"
#define DIM 100005
#define mod 1000000009
using namespace std;
static int w[DIM];
static pair<int, int> p[DIM];
static int mult(int x, int e){
if(e == 0){
return 1;
}
else{
int a = mult(x, e / 2);
if(e % 2 == 0){
return a * 1LL * a % mod;
}
else{
return a * 1LL * a % mod * x % mod;
}
}
}
int valid(int n, int v[]){
int i, j, x;
for(i = 0; i < n; i++){
w[i] = v[i];
}
sort(w, w + n);
for(i = 1; i < n; i++){
if(w[i] == w[i - 1]){
return 0;
}
}
for(i = 0; i < n; i++){
if(v[i] <= n){
x = v[i];
for(j = i; j < n; j++){
if(v[j] <= n && v[j] != x){
return 0;
}
x++;
if(x == n + 1){
x = 1;
}
}
for(j = 0; j < i; j++){
if(v[j] <= n && v[j] != x){
return 0;
}
x++;
if(x == n + 1){
x = 1;
}
}
break;
}
}
return 1;
}
int replacement(int n, int v[], int r[]){
int i, nr, x, y, k, j;
for(i = 0; i < n; i++){
if(v[i] <= n){
x = i;
y = v[x];
break;
}
}
if(i == n){
x = 0;
y = 1;
}
nr = k = 0;
for(i = x; i < n; i++){
if(v[i] != y){
p[++nr] = make_pair(v[i], y);
}
y++;
if(y == n + 1){
y = 1;
}
}
for(i = 0; i < x; i++){
if(v[i] != y){
p[++nr] = make_pair(v[i], y);
}
y++;
if(y == n + 1){
y = 1;
}
}
sort(p + 1, p + nr + 1);
p[0].first = n;
for(i = 1; i <= nr; i++){
r[k++] = p[i].second;
for(j = p[i - 1].first + 1; j < p[i].first; j++){
r[k++] = j;
}
}
return k;
}
int countReplacement(int n, int v[]){
if( valid(n, v) == 0){
return 0;
}
int i, ok, sol, nr;
nr = ok = 0;
for(i = 0; i < n; i++){
if(v[i] > n){
w[++nr] = v[i];
}
else{
ok = 1;
}
}
sort(w + 1, w + nr + 1);
sol = 1;
w[0] = n;
for(i = 1; i <= nr; i++){
sol = sol * 1LL * mult(nr - i + 1, w[i] - w[i - 1] - 1) % mod;
}
if(ok == 0){
sol = sol * 1LL * n % mod;
}
return sol;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:81:10: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
81 | y++;
| ~^~
gondola.cpp:86:18: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
86 | for(i = 0; i < x; i++){
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
7 |
Correct |
20 ms |
1024 KB |
Output is correct |
8 |
Correct |
13 ms |
820 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
20 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
7 |
Correct |
19 ms |
1024 KB |
Output is correct |
8 |
Correct |
16 ms |
1024 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
19 ms |
1024 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
9 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
23 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
416 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
640 KB |
Output is correct |
12 |
Correct |
13 ms |
640 KB |
Output is correct |
13 |
Correct |
25 ms |
1408 KB |
Output is correct |
14 |
Correct |
12 ms |
640 KB |
Output is correct |
15 |
Correct |
25 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
896 KB |
Output is correct |
10 |
Correct |
18 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
896 KB |
Output is correct |
10 |
Correct |
19 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
10 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
31 ms |
1792 KB |
Output is correct |
15 |
Correct |
35 ms |
2048 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
24 ms |
1408 KB |
Output is correct |
18 |
Correct |
15 ms |
1024 KB |
Output is correct |