#include <bits/stdc++.h>
#include "gondola.h"
#define DIM 100010
#define MOD 1000000009
using namespace std;
map <int,int> f;
pair <int,int> w[DIM];
int sol[DIM],a[DIM];
int get_next (int val, int n){
if (val == n)
return 1;
return val+1;
}
int get_ant (int val, int n){
if (val == 1)
return n;
return val-1;
}
inline int cmp (pair<int,int> a, pair<int,int> b){
return a.second < b.second;
}
int lg_put (int a, int b){
if (!b)
return 1;
int nr = lg_put (a,b/2);
if (b%2)
return 1LL*(1LL * nr * nr % MOD) * a % MOD;
else return (1LL * nr * nr % MOD);
}
int valid (int n, int v[]){
int i, poz = -1;
for (i=0;i<n;i++){
f[v[i]]++;
if (f[v[i]] >= 2)
return 0;
}
for (i=0;i<n;i++)
if (v[i] <= n){
poz = i;
break;
}
if (poz == -1)
return 1;
int val = v[poz];
for (i=poz+1;i<n;i++){
val = get_next (val,n);
if (v[i] <= n && v[i] != val)
return 0;
}
val = v[poz];
for (i=poz-1;i>=0;i--){
val = get_ant (val,n);
if (v[i] <= n && v[i] != val)
return 0;
}
return 1;
}
int replacement (int n, int v[], int replacementSeq[]){
int i, poz = -1, k = 0;
for (i=0;i<n;i++)
if (v[i] <= n){
poz = i;
break;
}
/// if (poz == -1) ???
int val = v[poz];
for (i=poz+1;i<n;i++){
val = get_next (val,n);
if (v[i] > n)
w[++k] = make_pair(val,v[i]);
}
val = v[poz];
for (i=poz-1;i>=0;i--){
val = get_ant (val,n);
if (v[i] > n)
w[++k] = make_pair(val,v[i]);
}
sort (w+1,w+k+1,cmp);
int last = n+1, el = 0;
for (i=1;i<=k;i++){
replacementSeq[el++] = w[i].first;
while (last <= w[i].second){
if (last < w[i].second)
replacementSeq[el++] = last;
last++;
}
}
return el;
}
int countReplacement(int n, int v[]){
if (!valid(n,v))
return 0;
int i, k = 0;
for (i=0;i<n;i++){
if (v[i] > n)
a[++k] = v[i];
}
sort (a+1,a+k+1);
a[0] = n;
long long sol = 1;
for (i=1;i<=k;i++)
sol = sol * lg_put (k-i+1,a[i]-a[i-1]-1) % MOD;
if (k == n)
sol = sol * n % MOD;
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 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 |
256 KB |
Output is correct |
6 |
Correct |
18 ms |
2304 KB |
Output is correct |
7 |
Correct |
17 ms |
768 KB |
Output is correct |
8 |
Correct |
33 ms |
3960 KB |
Output is correct |
9 |
Correct |
13 ms |
1536 KB |
Output is correct |
10 |
Correct |
39 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
19 ms |
2304 KB |
Output is correct |
7 |
Correct |
16 ms |
768 KB |
Output is correct |
8 |
Correct |
32 ms |
3968 KB |
Output is correct |
9 |
Correct |
12 ms |
1536 KB |
Output is correct |
10 |
Correct |
39 ms |
4600 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
23 ms |
2176 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
53 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 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 |
# |
Verdict |
Execution time |
Memory |
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 |
4 |
Correct |
5 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 |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 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 |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
640 KB |
Output is correct |
12 |
Correct |
17 ms |
816 KB |
Output is correct |
13 |
Correct |
21 ms |
1408 KB |
Output is correct |
14 |
Correct |
16 ms |
640 KB |
Output is correct |
15 |
Correct |
26 ms |
2296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
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 |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 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 |
256 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 |
74 ms |
4216 KB |
Output is correct |
10 |
Correct |
50 ms |
3704 KB |
Output is correct |
11 |
Correct |
18 ms |
1536 KB |
Output is correct |
12 |
Correct |
21 ms |
1792 KB |
Output is correct |
13 |
Correct |
8 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 |
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 |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
61 ms |
4344 KB |
Output is correct |
10 |
Correct |
42 ms |
3576 KB |
Output is correct |
11 |
Correct |
20 ms |
1568 KB |
Output is correct |
12 |
Correct |
22 ms |
1792 KB |
Output is correct |
13 |
Correct |
8 ms |
768 KB |
Output is correct |
14 |
Correct |
63 ms |
4856 KB |
Output is correct |
15 |
Correct |
75 ms |
5496 KB |
Output is correct |
16 |
Correct |
15 ms |
1280 KB |
Output is correct |
17 |
Correct |
47 ms |
3832 KB |
Output is correct |
18 |
Correct |
29 ms |
2304 KB |
Output is correct |