#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[])
{
int i;
int chk[250010];
memset(chk, 0, sizeof(chk));
for (i=0; i<n; i++) chk[inputSeq[i]]++;
for (i=0; i<n; i++) if (chk[inputSeq[i]]!=1) return 0;
for (i=0; i<n; i++) if (inputSeq[i]<=n) break;
if (i>=n) return 1;
int ar[100010];
for (int j=0; j<n; j++) ar[(inputSeq[i]-1+j)%n]=inputSeq[(i+j)%n];
for (i=0; i<n; i++) if (ar[i]<=n&&i+1!=ar[i]) return 0;
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int chk[250010]; int i, j;
int ar[100010];
memset(chk, 0, sizeof(chk));
int mx=0;
for (i=0; i<n; i++) mx=max(mx, gondolaSeq[i]);
for (i=0; i<n; i++) if (gondolaSeq[i]<=n) break;
if (i<n) {
for (j=0; j<n; j++) ar[(gondolaSeq[i]-1+j)%n]=gondolaSeq[(i+j)%n];
for (i=0; i<n; i++) gondolaSeq[i]=ar[i];
}
for (i=0; i<n; i++) chk[gondolaSeq[i]]=i+1;
int fr=0;
for (i=0; i<n; i++) ar[i]=i+1;
for (i=n+1; i<=mx; i++) {
if (chk[i]) {
replacementSeq[i-n-1]=ar[chk[i]-1];
ar[chk[i]-1]=i;
}
else {
for (; ar[fr]==gondolaSeq[fr]; fr++) {}
replacementSeq[i-n-1]=ar[fr];
ar[fr]=i;
}
}
return mx-n;
}
//----------------------
typedef long long ll;
const ll MAX=1000000009ll;
ll mypow(ll n, int k)
{
if (n==0) return 1;
if (k==0) return 1;
int i;
ll ret=1;
for (i=0; (1<<i)<=k; i++) {} i--;
for (; i>=0; i--) {
ret=ret*ret%MAX;
if ((1<<i)&k) ret=ret*n%MAX;
}
return ret;
}
int arr[100010];
int countReplacement(int n, int gondolaSeq[])
{
if (n==0) return 1;
int i, j;
for (i=0; i<n; i++) if (gondolaSeq[i]<=n) break;
if (i<n) {
for (j=0; j<n; j++) arr[(gondolaSeq[i]-1+j)%n]=gondolaSeq[(i+j)%n];
for (i=0; i<n; i++) if (arr[i]<=n&&i+1!=arr[i]) return 0;
}
sort(gondolaSeq, gondolaSeq+n);
for (i=0; i<n-1; i++) if (gondolaSeq[i]==gondolaSeq[i+1]) return 0;
long long ret=1, cnt=0;
for (i=0; i<n; i++) if (gondolaSeq[i]>n) break;
cnt=n-i;
ret=mypow(cnt, gondolaSeq[i]-n-1);
i++;
for (; i<n; i++) {
cnt--;
if (cnt==0) assert(false);
ret=ret*mypow(cnt, gondolaSeq[i]-gondolaSeq[i-1]-1)%MAX;
}
if (gondolaSeq[0]>n) return ret*n%MAX;
return (int)ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1276 KB |
Output is correct |
3 |
Correct |
3 ms |
1340 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1244 KB |
Output is correct |
6 |
Correct |
8 ms |
1528 KB |
Output is correct |
7 |
Correct |
15 ms |
1784 KB |
Output is correct |
8 |
Correct |
13 ms |
1912 KB |
Output is correct |
9 |
Correct |
6 ms |
1528 KB |
Output is correct |
10 |
Correct |
15 ms |
1916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1276 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1400 KB |
Output is correct |
6 |
Correct |
8 ms |
1528 KB |
Output is correct |
7 |
Correct |
15 ms |
1656 KB |
Output is correct |
8 |
Correct |
13 ms |
1832 KB |
Output is correct |
9 |
Correct |
6 ms |
1528 KB |
Output is correct |
10 |
Correct |
14 ms |
1912 KB |
Output is correct |
11 |
Correct |
3 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1272 KB |
Output is correct |
13 |
Correct |
9 ms |
1656 KB |
Output is correct |
14 |
Correct |
3 ms |
1272 KB |
Output is correct |
15 |
Correct |
16 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1276 KB |
Output is correct |
2 |
Correct |
4 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
4 ms |
1372 KB |
Output is correct |
9 |
Correct |
4 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
4 ms |
1400 KB |
Output is correct |
10 |
Correct |
3 ms |
1272 KB |
Output is correct |
11 |
Correct |
15 ms |
1916 KB |
Output is correct |
12 |
Correct |
15 ms |
2044 KB |
Output is correct |
13 |
Correct |
17 ms |
2228 KB |
Output is correct |
14 |
Correct |
14 ms |
1912 KB |
Output is correct |
15 |
Correct |
23 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
21 ms |
888 KB |
Output is correct |
10 |
Correct |
17 ms |
760 KB |
Output is correct |
11 |
Correct |
8 ms |
508 KB |
Output is correct |
12 |
Correct |
9 ms |
504 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
21 ms |
888 KB |
Output is correct |
10 |
Correct |
17 ms |
760 KB |
Output is correct |
11 |
Correct |
8 ms |
504 KB |
Output is correct |
12 |
Correct |
9 ms |
504 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
24 ms |
632 KB |
Output is correct |
15 |
Correct |
28 ms |
1668 KB |
Output is correct |
16 |
Correct |
7 ms |
632 KB |
Output is correct |
17 |
Correct |
20 ms |
1272 KB |
Output is correct |
18 |
Correct |
11 ms |
888 KB |
Output is correct |