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<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int correct[MAXN], pos[3 * MAXN], ans[3 * MAXN];
bool marc1[3 * MAXN];
void calc(int n, int seq[])
{
int id = -1;
for(int i = 0; i < n; i++)
if(seq[i] <= n)
{ id = i; break; }
if(id != -1) correct[id] = seq[id];
else id = 0, correct[id] = 1;
for(int i = id + 1; i < n; i++)
{
correct[i] = correct[i - 1] + 1;
if(correct[i] > n) correct[i] = 1;
}
for(int i = id - 1; i >= 0; i--)
{
correct[i] = correct[i + 1] - 1;
if(correct[i] < 1) correct[i] = n;
}
// for(int i = 0; i < n; i++)
// printf("correct[%d] = %d\n", i, correct[i]);
}
int valid(int n, int seq[])
{
calc(n, seq);
for(int i = 0; i < n; i++)
{
if(seq[i] <= n && correct[i] != seq[i]) return 0;
if(seq[i] > n && marc1[seq[i]]) return 0;
marc1[seq[i]] = true;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
calc(n, gondolaSeq);
for(int i = 0; i < 3 * MAXN; i++) pos[i] = -1;
int mx = n;
for(int i = 0; i < n; i++)
if(gondolaSeq[i] > n)
pos[gondolaSeq[i]] = i, mx = max(mx, gondolaSeq[i]);
for(int i = mx - 1; i > n; i--)
if(pos[i] == -1)
pos[i] = pos[i + 1];
int l = 0;
for(int i = n + 1; i <= mx; i++)
{
replacementSeq[l] = correct[pos[i]];
correct[pos[i]] = i;
l++;
}
/*
printf("l = %d\n", l);
for(int i = 0; i < l; i++) printf("%d ", replacementSeq[i]);
printf("\n");
*/
return l;
}
int countReplacement(int n, int inputSeq[])
{
return -1;
}
/*
int N, SEQ[MAXN];
int main ()
{
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%d", &SEQ[i]);
printf("valid = %d\n", valid(N, SEQ));
replacement(N, SEQ, ans);
}
*/
# | 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... |