#include "gondola.h"
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <set>
#define LMT 1000000009
using namespace std;
int valid(int n, int inputSeq[])
{
int i,p;
set<int> ch;
ch.clear();
for(i=0;i<n;i++){
if(ch.find(inputSeq[i])!=ch.end()) return 0;
ch.insert(inputSeq[i]);
}
for(i=0;i<n;i++) if(inputSeq[i]<=n) break;
p=inputSeq[i];
for(;i<n;i++,p++) if(inputSeq[i]<=n && inputSeq[i]!=(p-1)%n+1) return 0;
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int i,p,l;
vector<pair<int,int> > v;
for(i=0;i<n;i++) if(gondolaSeq[i]>n) v.push_back(make_pair(gondolaSeq[i],i));
sort(v.begin(),v.end());
for(i=0;i<n;i++) if(gondolaSeq[i]<=n) break;
if(i==n) gondolaSeq[i=0]=1;
for(p=1;p<n;p++) gondolaSeq[(p+i)%n]=(gondolaSeq[i]+p-1)%n+1;
for(i=n+1,p=0,l=0;p<v.size();i++){
replacementSeq[l++]=gondolaSeq[v[p].second];
gondolaSeq[v[p].second]=i;
if(v[p].first==i) p++;
}
return l;
}
//----------------------
int mpow(int x,int y){
if(!y) return 1;
int k=mpow(x,y/2);
if(y&1) return (long long)((long long)k*k%LMT)*x%LMT;
else return (long long)k*k%LMT;
}
int countReplacement(int n, int inputSeq[])
{
if(!valid(n,inputSeq)) return 0;
int i,p,s=1;
vector<int> v;
for(i=0;i<n;i++) if(inputSeq[i]>n) v.push_back(inputSeq[i]);
v.push_back(n);
sort(v.begin(),v.end());
for(i=1;i<v.size();i++) s=(long long)s*mpow(((int)v.size()-i),(v[i]-v[i-1]-1))%LMT;
return s;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
17 ms |
4300 KB |
Output is correct |
7 |
Correct |
12 ms |
2584 KB |
Output is correct |
8 |
Correct |
34 ms |
5884 KB |
Output is correct |
9 |
Correct |
11 ms |
3640 KB |
Output is correct |
10 |
Correct |
47 ms |
6412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
13 ms |
4300 KB |
Output is correct |
7 |
Correct |
15 ms |
2584 KB |
Output is correct |
8 |
Correct |
26 ms |
5884 KB |
Output is correct |
9 |
Correct |
7 ms |
3640 KB |
Output is correct |
10 |
Correct |
57 ms |
6412 KB |
Output is correct |
11 |
Correct |
0 ms |
2584 KB |
Output is correct |
12 |
Correct |
0 ms |
2584 KB |
Output is correct |
13 |
Correct |
22 ms |
4168 KB |
Output is correct |
14 |
Correct |
0 ms |
2584 KB |
Output is correct |
15 |
Correct |
57 ms |
6544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
2584 KB |
Output is correct |
10 |
Correct |
0 ms |
2584 KB |
Output is correct |
11 |
Correct |
15 ms |
2584 KB |
Output is correct |
12 |
Correct |
0 ms |
2584 KB |
Output is correct |
13 |
Correct |
18 ms |
2972 KB |
Output is correct |
14 |
Correct |
12 ms |
2584 KB |
Output is correct |
15 |
Correct |
34 ms |
2972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
65 ms |
6012 KB |
Output is correct |
10 |
Correct |
34 ms |
5352 KB |
Output is correct |
11 |
Correct |
16 ms |
3504 KB |
Output is correct |
12 |
Correct |
22 ms |
3768 KB |
Output is correct |
13 |
Incorrect |
4 ms |
2844 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
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 |
50 ms |
6012 KB |
Output is correct |
10 |
Correct |
40 ms |
5352 KB |
Output is correct |
11 |
Correct |
15 ms |
3504 KB |
Output is correct |
12 |
Correct |
17 ms |
3768 KB |
Output is correct |
13 |
Incorrect |
2 ms |
2844 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |