#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000009;
long long power(long long b, long long p){
if(p == 0) return 1;
if(p % 2 == 0){
long long a = power(b,p/2);
return (a * a) % mod;
}
else{
return (power(b,p-1) * b) % mod;
}
}
int valid(int n, int arr[]) {
set<int> sset;
for(int i = 0;i < n;i++){
sset.insert(arr[i]);
}
if(sset.size() != n) return 0;
int anchor = -1;
for(int i = 0;i < n;i++){
if(arr[i] <= n){
anchor = (arr[i] - i + n) % n;
break;
}
}
if(anchor == -1) return 1;
for(int i = 0;i < n;i++){
if(arr[i] <= n){
if(arr[i] % n != (anchor + i) % n){
return 0;
}
}
}
return 1;
}
int replacement(int n, int arr[], int replacementSeq[]) {
int anchor = 0;
int ori[n];
map<int,int> m;
set<int> s;
for(int i = 0;i < n;i++){
if(arr[i] <= n){
anchor = (arr[i] - i + n) % n;
break;
}
}
int maxv = 0;
int maxpos = 0;
for(int i = 0;i < n;i++){
ori[i] = (anchor+i) % n;
if(ori[i] == 0) ori[i] = n;
if(arr[i] > maxv){
maxv = arr[i];
maxpos = i;
}
if(arr[i] > n){
m[arr[i]] = i;
}
}
int cnt = 0;
for(int r = n+1;r <= maxv;r++){
int rindex = 0;
if(m.find(r) == m.end()){
rindex = maxpos;
}
else{
rindex = m[r];
}
replacementSeq[cnt] = ori[rindex];
ori[rindex] = r;
cnt++;
}
return cnt;
}
int countReplacement(int n, int arr[]) {
if(!valid(n,arr)) return 0;
long long ans = 1;
int maxv = 0;
int freee = n;
set<int> s;
bool has = true;
vector<int> v;
for(int i = 0;i < n;i++){
maxv = max(maxv, arr[i]);
if(arr[i] <= n){
freee--;
has = false;
}
else{
v.push_back(arr[i]);
}
}
sort(v.begin(),v.end());
int pre = n;
for(int x : v){
long long p = x - pre - 1;
ans *= power(freee,p);
ans %= mod;
pre = x;
freee--;
}
if(has){
ans *= n;
ans %= mod;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:20:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(sset.size() != n) return 0;
~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
16 ms |
2296 KB |
Output is correct |
7 |
Correct |
38 ms |
3708 KB |
Output is correct |
8 |
Correct |
29 ms |
4032 KB |
Output is correct |
9 |
Correct |
10 ms |
1528 KB |
Output is correct |
10 |
Correct |
37 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
16 ms |
2296 KB |
Output is correct |
7 |
Correct |
37 ms |
3768 KB |
Output is correct |
8 |
Correct |
29 ms |
4088 KB |
Output is correct |
9 |
Correct |
10 ms |
1528 KB |
Output is correct |
10 |
Correct |
36 ms |
4472 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
20 ms |
2144 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
48 ms |
4648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
12 ms |
892 KB |
Output is correct |
12 |
Correct |
13 ms |
1016 KB |
Output is correct |
13 |
Correct |
33 ms |
2680 KB |
Output is correct |
14 |
Correct |
12 ms |
1016 KB |
Output is correct |
15 |
Correct |
34 ms |
2936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
296 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
404 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
50 ms |
4088 KB |
Output is correct |
10 |
Correct |
39 ms |
3448 KB |
Output is correct |
11 |
Correct |
16 ms |
1400 KB |
Output is correct |
12 |
Correct |
19 ms |
1656 KB |
Output is correct |
13 |
Correct |
5 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
75 ms |
4088 KB |
Output is correct |
10 |
Correct |
43 ms |
3576 KB |
Output is correct |
11 |
Correct |
18 ms |
1400 KB |
Output is correct |
12 |
Correct |
19 ms |
1656 KB |
Output is correct |
13 |
Correct |
6 ms |
632 KB |
Output is correct |
14 |
Correct |
66 ms |
4728 KB |
Output is correct |
15 |
Correct |
121 ms |
6152 KB |
Output is correct |
16 |
Correct |
13 ms |
1400 KB |
Output is correct |
17 |
Correct |
48 ms |
4216 KB |
Output is correct |
18 |
Correct |
27 ms |
2540 KB |
Output is correct |