#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
for(int i=0;i<n;i++) inputSeq[i]--;
map<int,int> used;
int pos0 = -1;
for(int i=0;i<n;i++){
if(inputSeq[i] < n) pos0 = (i - inputSeq[i] + n) % n;
if(used[inputSeq[i]]) return 0;
used[inputSeq[i]] = 1;
}
if(pos0 == -1) return 1;
for(int i=0;i<n;i++){
if(inputSeq[i] < n){
if((pos0 + inputSeq[i]) % n != i) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
vector<int> pos(250000, -1);
int mx = 0;
for(int i=0;i<n;i++) gondolaSeq[i]--, pos[gondolaSeq[i]] = i, mx = max(mx, gondolaSeq[i]);
int pos0 = 0, ans = 0;
for(int i=0;i<n;i++){
if(gondolaSeq[i] < n) pos0 = (i - gondolaSeq[i] + n) % n;
}
/* for(int i=0;i<2*n;i++) cout<<pos[i]<<'\n'; */
int prev = n;
for(int i=n;i<=mx;i++){
if(pos[i] != -1){
replacementSeq[ans++] = (pos[i] - pos0 + n) % n + 1;
for(int j=prev;j<i;j++) replacementSeq[ans++] = j + 1;
prev = i+1;
}
}
return ans;
}
#define ll long long
//----------------------
const ll mod = 1000000009;
ll power(ll x,ll y){
ll ans = 1, mul = x;
while(y){
if(y&1) ans = ans * mul % mod;
mul = mul * mul % mod;
y>>=1;
}
return ans;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
for(int i=0;i<n;i++) inputSeq[i]++;
set<ll> s;
bool has = 0;
for(int i=0;i<n;i++){
s.insert(inputSeq[i]);
if(inputSeq[i] <= n) has = 1;
}
while(!s.empty() && *s.begin() <= n) s.erase(s.begin());
ll prev = n+1, ans = 1;
if(!has) ans = n;
while(!s.empty()){
ll x = *s.begin(), siz = s.size();
s.erase(s.begin());
ans = ans * power(siz, x-prev) % mod;
prev = x + 1;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
16 ms |
2432 KB |
Output is correct |
7 |
Correct |
15 ms |
1152 KB |
Output is correct |
8 |
Correct |
33 ms |
4408 KB |
Output is correct |
9 |
Correct |
10 ms |
1664 KB |
Output is correct |
10 |
Correct |
38 ms |
5044 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 |
17 ms |
2432 KB |
Output is correct |
7 |
Correct |
17 ms |
1152 KB |
Output is correct |
8 |
Correct |
34 ms |
4352 KB |
Output is correct |
9 |
Correct |
10 ms |
1568 KB |
Output is correct |
10 |
Correct |
39 ms |
4992 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
21 ms |
2304 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
57 ms |
5240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
1 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1280 KB |
Output is correct |
4 |
Correct |
1 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
1 ms |
1280 KB |
Output is correct |
3 |
Correct |
1 ms |
1280 KB |
Output is correct |
4 |
Correct |
1 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
1280 KB |
Output is correct |
8 |
Correct |
2 ms |
1280 KB |
Output is correct |
9 |
Correct |
2 ms |
1280 KB |
Output is correct |
10 |
Correct |
2 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
1 ms |
1280 KB |
Output is correct |
3 |
Correct |
1 ms |
1280 KB |
Output is correct |
4 |
Correct |
1 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1280 KB |
Output is correct |
9 |
Correct |
2 ms |
1280 KB |
Output is correct |
10 |
Correct |
2 ms |
1280 KB |
Output is correct |
11 |
Correct |
13 ms |
2048 KB |
Output is correct |
12 |
Correct |
20 ms |
2176 KB |
Output is correct |
13 |
Correct |
15 ms |
1920 KB |
Output is correct |
14 |
Correct |
19 ms |
2048 KB |
Output is correct |
15 |
Correct |
25 ms |
2220 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 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 |
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 |
256 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 |
256 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 |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
72 ms |
4488 KB |
Output is correct |
10 |
Correct |
58 ms |
3840 KB |
Output is correct |
11 |
Correct |
19 ms |
1536 KB |
Output is correct |
12 |
Correct |
24 ms |
1920 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 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 |
82 ms |
4580 KB |
Output is correct |
10 |
Correct |
58 ms |
3832 KB |
Output is correct |
11 |
Correct |
19 ms |
1664 KB |
Output is correct |
12 |
Correct |
24 ms |
1920 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
98 ms |
5404 KB |
Output is correct |
15 |
Correct |
112 ms |
6008 KB |
Output is correct |
16 |
Correct |
15 ms |
1408 KB |
Output is correct |
17 |
Correct |
68 ms |
4344 KB |
Output is correct |
18 |
Correct |
35 ms |
2424 KB |
Output is correct |