This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gondola.h"
#include <cstdio>
#include <cstring>
int valid(int n, int inputSeq[])
{
int offs = 0;
for(int i = 0; i < n; i++){
if(inputSeq[i] <= n) offs = i-inputSeq[i]+1;
}
for(int i = 0; i < n; i++){
if(inputSeq[(i+offs) % n] <= n && inputSeq[(i+offs) % n] != i+1) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int offs = 0;
int dummy = 0;
int mx = -1;
int* expect = new int[250005];
memset(expect, -1, 4*250005);
for(int i = 0; i < n; i++){
if(gondolaSeq[i] <= n) offs = i-gondolaSeq[i]+1;
else expect[gondolaSeq[i]] = i;
if(gondolaSeq[i] > mx){
mx = gondolaSeq[i];
dummy = i;
}
}
int* initSeq = new int[250005];
for(int i = 0; i < n; i++){
initSeq[(i+offs) % n] = i+1;
}
int rpidx = 0;
for(int i = n+1; i <= mx; i++){
if(expect[i] == -1){
replacementSeq[rpidx++] = initSeq[dummy];
initSeq[dummy] = i;
}else{
replacementSeq[rpidx++] = initSeq[expect[i]];
initSeq[expect[i]] = i;
}
}
return rpidx;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(!valid(n, inputSeq)) return 0;
else return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |