#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int arr[]){
unordered_set<int>se;
bool amos=true;
deque<int>d;
int mini=INT_MAX;
set<int>shift;
for(int x=0;x<n;x++){
if(se.find(arr[x])!=se.end()) amos=false;
se.insert(arr[x]);
if(arr[x]<=n){
d.push_back(arr[x]);
mini=min(mini,arr[x]);
if(arr[x]>=x+1){
shift.insert(arr[x]-(x+1));
}
else{
shift.insert(arr[x]+n-(x+1));
}
}
}
if(shift.size()>1) amos=false;
return amos;
}
int replacement(int n, int arr[], int ans[]){
int maxi=0;
int shift=-1;
deque<int>d;
for(int x=0;x<n;x++){
maxi=max(maxi,arr[x]);
if(arr[x]<=n){
if(arr[x]>=x+1){
shift=arr[x]-(x+1);
}
else{
shift=arr[x]+n-(x+1);
}
}
d.push_back(arr[x]);
}
while(shift>0){
shift--;
d.push_front(d.back());
d.pop_back();
}
vector<pair<int,int>>v;
for(int x=0;x<n;x++){
if(d[x]>n){
v.push_back({d[x],x});
}
}
sort(v.begin(),v.end());
int index=0;
int cur=n;
for(auto it:v){
bool done=true;
while(cur<it.first){
if(done){
ans[index]=it.second+1;
done=false;
index++;
}
else{
ans[index]=cur;
index++;
}
cur++;
}
}
return maxi-n;
}
//----------------------
long long mod=1000000009;
long long f(long long a, long long b){
if(a==1||b==0) return 1;
if(b==1) return a;
int hold=f((a*a)%mod,b/2);
if(b%2) hold=(hold*a)%mod;
return hold;
}
int countReplacement(int n, int arr[]){
int arr2[n];
for(int x=0;x<n;x++) arr2[x]=arr[x];
if(valid(n,arr2)==0) return 0;
int maxi=0;
vector<int>v;
int mini=INT_MAX;
for(int x=0;x<n;x++){
maxi=max(maxi,arr[x]);
mini=min(mini,arr[x]);
if(arr[x]>n)v.push_back(arr[x]);
}
if(maxi==n) return 1;
int cur=n;
long long counter=1;
sort(v.begin(),v.end());
int sz=v.size();
for(auto it:v){
long long gap=max(0,it-cur-1);
gap%=mod;
counter=(counter*f(sz,gap))%mod;
cur=it;
sz--;
}
if(mini>n){
counter=(counter*n)%mod;
}
return counter;
}
//
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2232 KB |
Output is correct |
7 |
Correct |
27 ms |
5092 KB |
Output is correct |
8 |
Correct |
10 ms |
3692 KB |
Output is correct |
9 |
Correct |
4 ms |
1628 KB |
Output is correct |
10 |
Correct |
12 ms |
4204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
2232 KB |
Output is correct |
7 |
Correct |
22 ms |
5092 KB |
Output is correct |
8 |
Correct |
10 ms |
3692 KB |
Output is correct |
9 |
Correct |
4 ms |
1768 KB |
Output is correct |
10 |
Correct |
12 ms |
4200 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
1972 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
25 ms |
6980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
7 ms |
1116 KB |
Output is correct |
13 |
Correct |
11 ms |
1516 KB |
Output is correct |
14 |
Correct |
7 ms |
860 KB |
Output is correct |
15 |
Correct |
15 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
17 ms |
3948 KB |
Output is correct |
10 |
Correct |
15 ms |
3516 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
12 |
Correct |
7 ms |
1720 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
408 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
23 ms |
4072 KB |
Output is correct |
10 |
Correct |
14 ms |
3548 KB |
Output is correct |
11 |
Correct |
6 ms |
1708 KB |
Output is correct |
12 |
Correct |
7 ms |
1720 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
23 ms |
4972 KB |
Output is correct |
15 |
Correct |
28 ms |
6780 KB |
Output is correct |
16 |
Correct |
5 ms |
1624 KB |
Output is correct |
17 |
Correct |
18 ms |
4092 KB |
Output is correct |
18 |
Correct |
10 ms |
2488 KB |
Output is correct |