#include "gondola.h"
#include <vector>
#include <algorithm>
using namespace std;
int valid(int n, int inputSeq[])
{
//duplication check
vector<int> dupe;
for(int i=0;i<n;i++)
dupe.push_back(inputSeq[i]);
sort(dupe.begin(),dupe.end());
for(int i=0;i<n-1;i++)
if(dupe[i]==dupe[i+1]) return 0;
//rotatable check
int key=-1;
for(int i=0;i<n;i++)
if(inputSeq[i]<=n)
key=i;
if(key==-1) return 1;
for(int i=0;i<n;i++)
{
if(inputSeq[i]>n) continue;
if((inputSeq[i]-inputSeq[key]+n)%n!=(i-key+n)%n) return 0;
//do not have same diff
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
if(!valid(n,gondolaSeq)) return 0;
int key=0;
for(int i=0;i<n;i++)
if(gondolaSeq[i]<=n)
key=i;
vector<int> newSeq;
for(int i=0;i<n;i++)
newSeq.push_back((i+(gondolaSeq[key]-1)-key+n)%n+1);
vector<pair<int,int> > targetSeq;
for(int i=0;i<n;i++)
if(gondolaSeq[i]>n) targetSeq.push_back(make_pair(gondolaSeq[i],i));
sort(targetSeq.begin(),targetSeq.end());
int tp=0; //top, return value
for(int i=0;i<targetSeq.size();i++)
{
int ind=targetSeq[i].second;
int val=targetSeq[i].first;
while(tp+n<val)
{
replacementSeq[tp++]=newSeq[ind];
newSeq[ind]=tp+n;
}
}
return tp;
}
//----------------------
static const int mod=1000000009;
static int pow(int a,int b)
{
if(b==0) return 1;
int res=pow(a,b/2);
res=(1LL*res*res)%mod;
if(b%2==1) res=(1LL*res*a)%mod;
return res;
}
int countReplacement(int n, int inputSeq[])
{
if(!valid(n,inputSeq)) return 0;
vector<int> p;
for(int i=0;i<n;i++)
if(inputSeq[i]>n)
p.push_back(inputSeq[i]);
sort(p.begin(),p.end());
int usin=p.size(); //using is keyword :(
int ginputed=n; //max gondola input
int ans=1;
for(int i=0;i<p.size();i++)
{
ans=(1LL*ans*pow(usin--,p[i]-ginputed-1))%mod;
ginputed=p[i];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
11 ms |
2972 KB |
Output is correct |
7 |
Correct |
16 ms |
3356 KB |
Output is correct |
8 |
Correct |
11 ms |
3356 KB |
Output is correct |
9 |
Correct |
7 ms |
2712 KB |
Output is correct |
10 |
Correct |
24 ms |
3356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
10 ms |
2972 KB |
Output is correct |
7 |
Correct |
25 ms |
3356 KB |
Output is correct |
8 |
Correct |
11 ms |
3356 KB |
Output is correct |
9 |
Correct |
6 ms |
2712 KB |
Output is correct |
10 |
Correct |
25 ms |
3356 KB |
Output is correct |
11 |
Correct |
0 ms |
2584 KB |
Output is correct |
12 |
Correct |
0 ms |
2584 KB |
Output is correct |
13 |
Correct |
9 ms |
2972 KB |
Output is correct |
14 |
Correct |
0 ms |
2584 KB |
Output is correct |
15 |
Correct |
21 ms |
3356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
0 ms |
2584 KB |
Output is correct |
7 |
Correct |
0 ms |
2584 KB |
Output is correct |
8 |
Correct |
0 ms |
2584 KB |
Output is correct |
9 |
Correct |
0 ms |
2584 KB |
Output is correct |
10 |
Correct |
0 ms |
2584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
0 ms |
2584 KB |
Output is correct |
7 |
Correct |
0 ms |
2584 KB |
Output is correct |
8 |
Correct |
0 ms |
2584 KB |
Output is correct |
9 |
Correct |
0 ms |
2584 KB |
Output is correct |
10 |
Correct |
0 ms |
2584 KB |
Output is correct |
11 |
Correct |
19 ms |
3604 KB |
Output is correct |
12 |
Correct |
18 ms |
3604 KB |
Output is correct |
13 |
Correct |
20 ms |
3348 KB |
Output is correct |
14 |
Correct |
19 ms |
3604 KB |
Output is correct |
15 |
Correct |
28 ms |
3096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
0 ms |
2584 KB |
Output is correct |
7 |
Correct |
0 ms |
2584 KB |
Output is correct |
8 |
Correct |
0 ms |
2584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
0 ms |
2584 KB |
Output is correct |
7 |
Correct |
0 ms |
2584 KB |
Output is correct |
8 |
Correct |
0 ms |
2584 KB |
Output is correct |
9 |
Correct |
20 ms |
3356 KB |
Output is correct |
10 |
Correct |
18 ms |
3092 KB |
Output is correct |
11 |
Correct |
6 ms |
2836 KB |
Output is correct |
12 |
Correct |
11 ms |
2836 KB |
Output is correct |
13 |
Incorrect |
0 ms |
2584 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2584 KB |
Output is correct |
2 |
Correct |
0 ms |
2584 KB |
Output is correct |
3 |
Correct |
0 ms |
2584 KB |
Output is correct |
4 |
Correct |
0 ms |
2584 KB |
Output is correct |
5 |
Correct |
0 ms |
2584 KB |
Output is correct |
6 |
Correct |
0 ms |
2584 KB |
Output is correct |
7 |
Correct |
0 ms |
2584 KB |
Output is correct |
8 |
Correct |
0 ms |
2584 KB |
Output is correct |
9 |
Correct |
18 ms |
3356 KB |
Output is correct |
10 |
Correct |
15 ms |
3092 KB |
Output is correct |
11 |
Correct |
7 ms |
2836 KB |
Output is correct |
12 |
Correct |
7 ms |
2836 KB |
Output is correct |
13 |
Incorrect |
3 ms |
2584 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |