#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int a[])
{
int sm = INT_MAX, pos = -1;
map<int,int> M; M.clear();
for(int i = 0; i < n; i++)
{
M[a[i]]++;
if(M[a[i]]>=2)return 0;
}
for(int i = 0; i < n; i++)
if(sm>a[i] and a[i]<=n)sm=a[i], pos=i;
if(sm==INT_MAX)return 1;
int x = n;
while(x--){
if(a[pos]==n and a[(pos+1)%n]<=n and a[(pos+1)%n]!=1)return 0;
else if(a[pos]<n and a[(pos+1)%n]<=n and a[pos]!=a[(pos+1)%n]-1) return 0;
pos++, pos%=n;
}
return 1;
}
int replacement(int n, int a[], int b[])
{
map<int,int> M; M.clear();
set<int> S; S.clear();
vector<int> v; v.clear();
int x = n, pos = 0, mx = 0;
for(int i = 0; i < n; i++) S.insert(a[i]), mx = max(mx, a[i]);
for(int i = 0; i < n; i++)
if(a[i]<=n) pos = (i-a[i]+n+1)%n;
int z = 1; while(x--) M[a[pos]]=z, z++, pos++, pos%=n;
for(int i = n+1; i <= mx; i++){
if(S.count(i)) v.push_back(M[i]), M[i]=i;
else{
int x = *S.lower_bound(i);
v.push_back(M[x]), M[x]=i;
}
}
for(int i = 0; i < (int)v.size(); i++) b[i]=v[i];
return (int)v.size();
}
long long poww(long long a, long long b, long long MOD)
{
if(b<=0)return 1ll;
long long x = poww(a, b/2, MOD)%MOD;
x*=x, x%=MOD;
if(b%2)x*=a, x%=MOD;
return x;
}
int countReplacement(int n, int a[])
{
const long long MOD = 1e9+9;
if(!valid(n, a)) return 0;
if(*max_element(a, a+n)<=n)return 1;
vector<int> v; v.clear();
for(int i = 0; i < n; i++) if(a[i]>n) v.push_back(a[i]);
sort(v.begin(), v.end());
int m = (int)v.size();
long long ans = 1ll;
if(m==n)ans=n;
for(int i = 0; i < m; i++){
if(i==0) ans *= poww(m, v[0]-n-1, MOD);
else ans *= poww(m-i, v[i]-v[i-1]-1, MOD);
ans%=MOD;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
14 ms |
2108 KB |
Output is correct |
7 |
Correct |
10 ms |
640 KB |
Output is correct |
8 |
Correct |
31 ms |
3896 KB |
Output is correct |
9 |
Correct |
8 ms |
1456 KB |
Output is correct |
10 |
Correct |
33 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
14 ms |
2124 KB |
Output is correct |
7 |
Correct |
10 ms |
588 KB |
Output is correct |
8 |
Correct |
31 ms |
3840 KB |
Output is correct |
9 |
Correct |
8 ms |
1356 KB |
Output is correct |
10 |
Correct |
34 ms |
4492 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
19 ms |
1996 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
48 ms |
4548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
392 KB |
Output is correct |
11 |
Correct |
42 ms |
7976 KB |
Output is correct |
12 |
Correct |
48 ms |
9024 KB |
Output is correct |
13 |
Correct |
49 ms |
4460 KB |
Output is correct |
14 |
Correct |
41 ms |
7860 KB |
Output is correct |
15 |
Correct |
50 ms |
3776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
47 ms |
4028 KB |
Output is correct |
10 |
Correct |
39 ms |
3404 KB |
Output is correct |
11 |
Correct |
14 ms |
1440 KB |
Output is correct |
12 |
Correct |
17 ms |
1612 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
51 ms |
3912 KB |
Output is correct |
10 |
Correct |
37 ms |
3404 KB |
Output is correct |
11 |
Correct |
14 ms |
1356 KB |
Output is correct |
12 |
Correct |
17 ms |
1660 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
14 |
Correct |
63 ms |
5312 KB |
Output is correct |
15 |
Correct |
69 ms |
6020 KB |
Output is correct |
16 |
Correct |
11 ms |
1340 KB |
Output is correct |
17 |
Correct |
44 ms |
4132 KB |
Output is correct |
18 |
Correct |
25 ms |
2712 KB |
Output is correct |