#include "gondola.h"
#include <set>
#include <vector>
#include <algorithm>
#include <cstdio>
int valid(int n, int inputSeq[])
{
int shift=-1;
std::set<int> used;
for(int i=0;i<n;i++){
if(used.count(inputSeq[i])) return 0;
used.insert(inputSeq[i]);
if(inputSeq[i]<=n){
int new_shift=(inputSeq[i]-i+n)%n;
if(shift!=-1&&shift!=new_shift) return 0;
shift=new_shift;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
for(int i=0;i<n;i++){
gondolaSeq[i]--;
}
int shift=0;
for(int i=0;i<n;i++){
if(gondolaSeq[i]<n){
shift=(gondolaSeq[i]-i+n)%n;
break;
}
}
std::vector<int> seq(n);
for(int i=0;i<n;i++){
seq[i]=(i+shift)%n;
}
/*
for(int i=0;i<n;i++){
printf("given: %d\n",gondolaSeq[i]);
}
for(int i=0;i<n;i++){
printf("seq: %d\n",seq[i]);
}
*/
auto max=std::max_element(gondolaSeq,gondolaSeq+n);
std::vector<int> where(*max+1,max-gondolaSeq);
for(int i=0;i<n;i++){
where[gondolaSeq[i]]=i;
}
for(int x=n;x<=*max;x++){
//printf("where[%d]=%d: %d\n",x,where[x],seq[where[x]]);
replacementSeq[x-n]=seq[where[x]];
seq[where[x]]=x;
}
int l=*max+1-n;
for(int i=0;i<l;i++){
replacementSeq[i]++;
}
return l;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
128 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
16 ms |
2304 KB |
Output is correct |
7 |
Correct |
12 ms |
768 KB |
Output is correct |
8 |
Correct |
29 ms |
3968 KB |
Output is correct |
9 |
Correct |
9 ms |
1408 KB |
Output is correct |
10 |
Correct |
37 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
16 ms |
2304 KB |
Output is correct |
7 |
Correct |
11 ms |
612 KB |
Output is correct |
8 |
Correct |
29 ms |
4088 KB |
Output is correct |
9 |
Correct |
9 ms |
1536 KB |
Output is correct |
10 |
Correct |
40 ms |
4600 KB |
Output is correct |
11 |
Correct |
2 ms |
432 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
11 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
12 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
1764 KB |
Output is correct |
12 |
Correct |
12 ms |
1920 KB |
Output is correct |
13 |
Correct |
12 ms |
1536 KB |
Output is correct |
14 |
Correct |
10 ms |
1792 KB |
Output is correct |
15 |
Correct |
18 ms |
2340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Integer -3 violates the range [0, 1000000008] |
2 |
Halted |
0 ms |
0 KB |
- |