#include<bits/stdc++.h>
#include<gondola.h>
#define maxn 250005
#define MOD 1000000009
#define pii pair<int,int>
using namespace std;
int b[maxn];
int valid(int n, int a[])
{
int minn=0;
for(int i=1;i<n;i++)if(a[i]<a[minn])minn=i;
for(int i=0;i<n;i++)b[i]=a[(i+minn)%n];
if(b[0]>n)return 1;
sort(a,a+n);
for(int i=0;i<n-1;i++)if(a[i]==a[i+1])return 0;
int pre=0;
for(int i=1;i<n;i++)
{
if(b[i]<=n)
{
if(b[i]-b[pre]!=i-pre)return 0;
pre=i;
}
}
return 1;
}
vector<pii>v;
int replacement(int n, int g[], int r[])
{
if(!valid(n,g))return -1;
int s=b[0];
for(int i=0;i<n;i++)if(b[i]>n)
{
int br=(s+i)%n;if(br==0)br=n;
v.push_back({b[i],br});
}
sort(v.begin(),v.end());
int len=v.size();
if(len==0)
{
return 0;
}
int duz=0;
for(int i=0;i<len;i++)
{
r[duz]=v[i].second;duz++;
int pre=n;
if(i!=0)pre=v[i-1].first;
for(int j=pre+1;j<v[i].first;j++)
{
r[duz]=j;
duz++;
}
}
return v[len-1].first-n;
}
long long ste(int x,int y)
{
if(y==0)return 1;
if(y%2==1)return (ste(x,y-1)*x)%MOD;
long long res=ste(x,y/2);
return (res*res)%MOD;
}
vector<int>br;
int countReplacement(int n, int a[])
{
if(!valid(n,a))return 0;
for(int i=0;i<n;i++)if(b[i]>n)br.push_back(b[i]);
sort(br.begin(),br.end());
long long sol=1;
int len=br.size();
for(int i=0;i<len;i++)
{
int pre=n;
if(i!=0)pre=br[i-1];
sol*=ste(len-i,br[i]-pre-1);
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
840 KB |
Output is correct |
5 |
Correct |
2 ms |
840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
840 KB |
Output is correct |
2 |
Correct |
2 ms |
936 KB |
Output is correct |
3 |
Correct |
3 ms |
936 KB |
Output is correct |
4 |
Correct |
3 ms |
936 KB |
Output is correct |
5 |
Correct |
3 ms |
936 KB |
Output is correct |
6 |
Correct |
19 ms |
1276 KB |
Output is correct |
7 |
Correct |
27 ms |
2260 KB |
Output is correct |
8 |
Correct |
27 ms |
2512 KB |
Output is correct |
9 |
Correct |
9 ms |
2512 KB |
Output is correct |
10 |
Correct |
40 ms |
3188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3188 KB |
Output is correct |
2 |
Correct |
2 ms |
3188 KB |
Output is correct |
3 |
Correct |
3 ms |
3188 KB |
Output is correct |
4 |
Correct |
3 ms |
3188 KB |
Output is correct |
5 |
Correct |
2 ms |
3188 KB |
Output is correct |
6 |
Correct |
18 ms |
3188 KB |
Output is correct |
7 |
Correct |
37 ms |
4036 KB |
Output is correct |
8 |
Correct |
17 ms |
4276 KB |
Output is correct |
9 |
Correct |
11 ms |
4276 KB |
Output is correct |
10 |
Correct |
25 ms |
5064 KB |
Output is correct |
11 |
Correct |
2 ms |
5064 KB |
Output is correct |
12 |
Correct |
4 ms |
5064 KB |
Output is correct |
13 |
Correct |
16 ms |
5064 KB |
Output is correct |
14 |
Incorrect |
2 ms |
5064 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5064 KB |
Output is correct |
2 |
Correct |
3 ms |
5064 KB |
Output is correct |
3 |
Correct |
4 ms |
5064 KB |
Output is correct |
4 |
Correct |
3 ms |
5064 KB |
Output is correct |
5 |
Correct |
3 ms |
5064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5064 KB |
Output is correct |
2 |
Correct |
7 ms |
5064 KB |
Output is correct |
3 |
Correct |
3 ms |
5064 KB |
Output is correct |
4 |
Correct |
2 ms |
5064 KB |
Output is correct |
5 |
Correct |
3 ms |
5064 KB |
Output is correct |
6 |
Correct |
2 ms |
5064 KB |
Output is correct |
7 |
Correct |
3 ms |
5064 KB |
Output is correct |
8 |
Correct |
3 ms |
5064 KB |
Output is correct |
9 |
Correct |
2 ms |
5064 KB |
Output is correct |
10 |
Correct |
3 ms |
5064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5064 KB |
Output is correct |
2 |
Correct |
2 ms |
5064 KB |
Output is correct |
3 |
Correct |
3 ms |
5064 KB |
Output is correct |
4 |
Correct |
2 ms |
5064 KB |
Output is correct |
5 |
Correct |
2 ms |
5064 KB |
Output is correct |
6 |
Correct |
3 ms |
5064 KB |
Output is correct |
7 |
Correct |
3 ms |
5064 KB |
Output is correct |
8 |
Correct |
4 ms |
5064 KB |
Output is correct |
9 |
Correct |
5 ms |
5064 KB |
Output is correct |
10 |
Correct |
3 ms |
5064 KB |
Output is correct |
11 |
Correct |
16 ms |
5952 KB |
Output is correct |
12 |
Correct |
19 ms |
6532 KB |
Output is correct |
13 |
Correct |
21 ms |
7432 KB |
Output is correct |
14 |
Correct |
16 ms |
7432 KB |
Output is correct |
15 |
Correct |
39 ms |
8772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8772 KB |
Output is correct |
2 |
Correct |
3 ms |
8772 KB |
Output is correct |
3 |
Correct |
4 ms |
8772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8772 KB |
Output is correct |
2 |
Correct |
3 ms |
8772 KB |
Output is correct |
3 |
Correct |
2 ms |
8772 KB |
Output is correct |
4 |
Correct |
3 ms |
8772 KB |
Output is correct |
5 |
Correct |
3 ms |
8772 KB |
Output is correct |
6 |
Correct |
2 ms |
8772 KB |
Output is correct |
7 |
Incorrect |
3 ms |
8772 KB |
Integer 1676884508 violates the range [0, 1000000008] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8772 KB |
Output is correct |
2 |
Correct |
2 ms |
8772 KB |
Output is correct |
3 |
Correct |
3 ms |
8772 KB |
Output is correct |
4 |
Correct |
3 ms |
8772 KB |
Output is correct |
5 |
Correct |
2 ms |
8772 KB |
Output is correct |
6 |
Correct |
3 ms |
8772 KB |
Output is correct |
7 |
Incorrect |
4 ms |
8772 KB |
Integer 1676884508 violates the range [0, 1000000008] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8772 KB |
Output is correct |
2 |
Correct |
2 ms |
8772 KB |
Output is correct |
3 |
Correct |
2 ms |
8772 KB |
Output is correct |
4 |
Correct |
3 ms |
8772 KB |
Output is correct |
5 |
Correct |
2 ms |
8772 KB |
Output is correct |
6 |
Correct |
2 ms |
8772 KB |
Output is correct |
7 |
Incorrect |
2 ms |
8772 KB |
Integer 1676884508 violates the range [0, 1000000008] |
8 |
Halted |
0 ms |
0 KB |
- |