#include "gondola.h"
#include <bits/stdc++.h>
//💖
using namespace std;
typedef long long ll;
ll MOD=1000000009;
map<int, bool>check;
map<int, int>convent;
vector<int>ord;
int valid(int n, int* inputSeq)
{
int last=-1, pos=-1;
for(int i=0; i<n; i++)
{
if(inputSeq[i]<=n and last==-1){last=inputSeq[i]; pos=i;}
else if(inputSeq[i]<=n)
{
if((last+i-pos)%n==(inputSeq[i])%n){last=inputSeq[i]; pos=i;}
else {return 0;}
}
else if(check[inputSeq[i]])return 0;
check[inputSeq[i]]=true;
}
return 1;
}
int replacement(int n, int* gondolaSeq, int* replacementSeq)
{
int maks=-1, g=-1, k=1;
for(int i=0; i<n; i++)
{
//cout<<gondolaSeq[i]<<" "<<n<<endl;
if(gondolaSeq[i]>n)
{
convent[gondolaSeq[i]]=i+1;
if(gondolaSeq[i]>maks){maks=gondolaSeq[i]; g=i;}
}
else {k=i;}
}
for(int i=0; i<n; i++)
{
gondolaSeq[i]=(gondolaSeq[k]+i-k+n)%n;
if(gondolaSeq[i]==0)gondolaSeq[i]=n;
}
if (maks==-1)return 0;
for(int i=n+1; i<=maks; i++)
{
if(convent[i]==0){replacementSeq[i-n-1]=gondolaSeq[g]; gondolaSeq[g]=i;}
else{replacementSeq[i-n-1]=gondolaSeq[convent[i]-1]; gondolaSeq[convent[i]-1]=i;}
}
return maks-n;
}
int countReplacement(int n, int* inputSeq)
{
int last=-1, pos=-1;
for(int i=0; i<n; i++)
{
if(inputSeq[i]<=n and last==-1){last=inputSeq[i]; pos=i;}
else if(inputSeq[i]<=n)
{
if((last+i-pos)%n==(inputSeq[i])%n){last=inputSeq[i]; pos=i;}
else {return 0;}
}
else if(check[inputSeq[i]])return 0;
check[inputSeq[i]]=true;
}
int cnt=0;
ll maks=0;
for(int i=0; i<n; i++)
{
if(inputSeq[i]>n)
{
cnt++; ord.push_back(inputSeq[i]);
if(inputSeq[i]>maks){maks=inputSeq[i];}
}
}
sort(ord.begin(), ord.end());
ll res=1, pp=0;
for(int i=n+1; i<=maks; i++)
{
if(i==ord[pp])pp++;
else
{
res=(res*(ord.size()-pp))%MOD;
}
}
if(pp==n)res=(res*n)%MOD;
return res;
}
/*int main()
{
int n; cin>>n;
int gondole[n];
for(int i=0; i<n; i++)cin>>gondole[i];
cout<<countReplacement(n, gondole)<<endl;
//for(int i=0; i<11; i++)cout<<zamena[i]<<" ";
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
2132 KB |
Output is correct |
7 |
Correct |
6 ms |
544 KB |
Output is correct |
8 |
Correct |
14 ms |
3832 KB |
Output is correct |
9 |
Correct |
5 ms |
1384 KB |
Output is correct |
10 |
Correct |
19 ms |
4416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
6 ms |
596 KB |
Output is correct |
8 |
Correct |
14 ms |
3848 KB |
Output is correct |
9 |
Correct |
4 ms |
1364 KB |
Output is correct |
10 |
Correct |
17 ms |
4528 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
6 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
7 ms |
640 KB |
Output is correct |
13 |
Correct |
27 ms |
4576 KB |
Output is correct |
14 |
Correct |
6 ms |
596 KB |
Output is correct |
15 |
Correct |
40 ms |
9968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
31 ms |
4308 KB |
Output is correct |
10 |
Correct |
24 ms |
3700 KB |
Output is correct |
11 |
Correct |
11 ms |
1620 KB |
Output is correct |
12 |
Correct |
13 ms |
1876 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
31 ms |
4364 KB |
Output is correct |
10 |
Correct |
24 ms |
3752 KB |
Output is correct |
11 |
Correct |
11 ms |
1620 KB |
Output is correct |
12 |
Correct |
12 ms |
1876 KB |
Output is correct |
13 |
Correct |
4 ms |
700 KB |
Output is correct |
14 |
Execution timed out |
1087 ms |
5136 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |