#include <bits/stdc++.h>
#include "gondola.h"
#define F first
#define S second
using namespace std;
bool f[1000006],F[1000006];
int Gondol[250003],b[250003];
pair < int , int > a[250003];
long long mod=1e9+9;
int valid(int n, int inputSeq[]) {
int idx=-1;
for (int i=0; i<n; i++)
b[i]=inputSeq[i];
sort(b,b+n);
for (int i=1; i<n; i++)
if (b[i]==b[i-1]) return 0;
for (int i=0; i<n; i++)
if (inputSeq[i]<=n) { idx=i; break; }
if (idx==-1) return 1;
int x=inputSeq[idx];
for (int i=idx+1; ; i++) {
x++;
if (x>n) x-=n;
if (i==n) i-=n;
if (i==idx) break;
if (inputSeq[i]<=n && inputSeq[i]!=x) return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int l=0,M=0,idx=-1;
for (int i=0; i<n; i++)
if (gondolaSeq[i]<=n) { idx=i; break; }
for (int i=0; i<n; i++)
a[i].F=gondolaSeq[i],a[i].S=i;
sort(a,a+n);
if (idx==-1) {
for (int i=0; i<n; i++)
Gondol[i]=i+1;
}
else {
int x=gondolaSeq[idx];
Gondol[idx]=x;
for (int i=idx+1; ; i++) {
x++;
if (x>n) x-=n;
if (i==n) i-=n;
if (i==idx) break;
Gondol[i]=x;
}
}
int last=n;
for (int i=0; i<n; i++) {
if (a[i].F<=n) continue;
int id=a[i].S;
replacementSeq[l++]=Gondol[id];
for (int j=last+1; j<a[i].F; j++)
replacementSeq[l++]=j;
last=a[i].F;
}
return l;
}
long long int po(long long a,long long b) {
long long int res=1;
while (b>0) { if (b%2) res=(res*a)%mod; a=(a*a)%mod; b/=2; }
return res;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n,inputSeq)) return 0;
sort(inputSeq,inputSeq+n);
long long int ANS=1,last=n;
if (inputSeq[0]>n) ANS=(ANS*n)%mod;
for (int i=0; i<n; i++) {
if (inputSeq[i]<=n) continue;
ANS=(ANS*po(n-i,inputSeq[i]-last-1))%mod;
last=inputSeq[i];
}
return ANS;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:36:10: warning: unused variable 'M' [-Wunused-variable]
int l=0,M=0,idx=-1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
10 ms |
632 KB |
Output is correct |
7 |
Correct |
33 ms |
988 KB |
Output is correct |
8 |
Correct |
14 ms |
888 KB |
Output is correct |
9 |
Correct |
7 ms |
552 KB |
Output is correct |
10 |
Correct |
19 ms |
988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 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 |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
636 KB |
Output is correct |
7 |
Correct |
20 ms |
1144 KB |
Output is correct |
8 |
Correct |
14 ms |
888 KB |
Output is correct |
9 |
Correct |
7 ms |
548 KB |
Output is correct |
10 |
Correct |
19 ms |
1020 KB |
Output is correct |
11 |
Correct |
11 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
11 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
21 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 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 |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
15 ms |
1568 KB |
Output is correct |
12 |
Correct |
17 ms |
1784 KB |
Output is correct |
13 |
Correct |
16 ms |
1528 KB |
Output is correct |
14 |
Correct |
14 ms |
1528 KB |
Output is correct |
15 |
Correct |
23 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
27 ms |
884 KB |
Output is correct |
10 |
Correct |
21 ms |
760 KB |
Output is correct |
11 |
Correct |
10 ms |
508 KB |
Output is correct |
12 |
Correct |
11 ms |
504 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
11 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
52 ms |
888 KB |
Output is correct |
10 |
Correct |
23 ms |
844 KB |
Output is correct |
11 |
Correct |
10 ms |
504 KB |
Output is correct |
12 |
Correct |
11 ms |
504 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
34 ms |
1016 KB |
Output is correct |
15 |
Correct |
39 ms |
2040 KB |
Output is correct |
16 |
Correct |
9 ms |
632 KB |
Output is correct |
17 |
Correct |
26 ms |
1400 KB |
Output is correct |
18 |
Correct |
16 ms |
1016 KB |
Output is correct |