# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
292794 |
2020-09-07T13:31:59 Z |
TMJN |
Gondola (IOI14_gondola) |
C++17 |
|
32 ms |
2688 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
int t=1;
for(int i=0;i<n;i++){
if(inputSeq[i]<=n){
for(int j=0;j<n;j++){
if(inputSeq[(i+j)%n]<=n){
if((inputSeq[i]+j)%n!=inputSeq[(i+j)%n]%n){
t=0;
}
}
}
break;
}
}
sort(inputSeq,inputSeq+n);
for(int i=0;i<n-1;i++){
if(inputSeq[i]==inputSeq[i+1])t=0;
}
return t;
}
int K[100000],P[250001];
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int mx=0;
for(int i=0;i<n;i++){
mx=max(mx,gondolaSeq[i]);
}
for(int i=0;i<n;i++){
K[i]=i+1;
}
for(int i=0;i<n;i++){
if(gondolaSeq[i]<=n){
for(int j=0;j<n;j++){
K[(i+j)%n]=(gondolaSeq[i]+j)%n;
}
for(int j=0;j<n;j++){
if(!K[j])K[j]=n;
}
break;
}
}
for(int i=0;i<n;i++){
P[gondolaSeq[i]]=K[i];
}
for(int i=0;i<n;i++){
if(gondolaSeq[i]==mx){
int c=0;
int t=K[i];
for(int j=n+1;j<=mx-1;j++){
if(!P[j]){
replacementSeq[c]=t;
t=j;
}
else{
replacementSeq[c]=P[j];
}
c++;
}
replacementSeq[c]=t;
}
}
return mx-n;
}
long long pw(long long x,int y){
long long a=1;
while(y){
if(y&1)a=a*x%1000000009;
x=x*x%1000000009;
y/=2;
}
return a;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n,inputSeq))return 0;
long long k;
if(inputSeq[0]<=n)k=1;
else k=n;
int p=n;
for(int i=0;i<n;i++){
if(inputSeq[i]<=p)continue;
k*=pw(n-i,inputSeq[i]-p-1);
k%=1000000009;
p=inputSeq[i];
}
return k;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
512 KB |
Output is correct |
7 |
Correct |
20 ms |
640 KB |
Output is correct |
8 |
Correct |
14 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
24 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
512 KB |
Output is correct |
7 |
Correct |
20 ms |
640 KB |
Output is correct |
8 |
Correct |
14 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
24 ms |
640 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
21 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1280 KB |
Output is correct |
12 |
Correct |
15 ms |
1408 KB |
Output is correct |
13 |
Correct |
19 ms |
1792 KB |
Output is correct |
14 |
Correct |
14 ms |
1180 KB |
Output is correct |
15 |
Correct |
23 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
19 ms |
640 KB |
Output is correct |
10 |
Correct |
16 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
19 ms |
640 KB |
Output is correct |
10 |
Correct |
16 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
416 KB |
Output is correct |
14 |
Correct |
32 ms |
672 KB |
Output is correct |
15 |
Correct |
28 ms |
1664 KB |
Output is correct |
16 |
Correct |
7 ms |
512 KB |
Output is correct |
17 |
Correct |
19 ms |
1152 KB |
Output is correct |
18 |
Correct |
14 ms |
768 KB |
Output is correct |