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 <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int valid(int n, int inputSeq[])
{
set<int> S;
int prev = -1, prev_pos = -1;
for(int i = 0; i < n; i++)
{
if(S.find(inputSeq[i]) != S.end()) return 0;
S.insert(inputSeq[i]);
if(inputSeq[i] > n) continue;
if(prev != -1)
{
if((i - prev_pos + n) % n != (inputSeq[i] - prev + n) % n) return 0;
}
prev = inputSeq[i];
prev_pos = i;
}
return 1;
}
int* gondolaSeqGlobal;
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
gondolaSeqGlobal = gondolaSeq;
vector<int> I(n);
for(int i = 0; i < n; i++) I[i] = i;
sort(I.begin(), I.end(), [] (int x, int y)
{
return gondolaSeqGlobal[x] < gondolaSeqGlobal[y];
});
int pos1 = 0;
for(int i = 0; i < n; i++)
{
if(gondolaSeq[i] <= n)
{
pos1 = (i + 1 - gondolaSeq[i] + n) % n;
break;
}
}
int l = 0;
if(gondolaSeq[ I[0] ] > n)
{
replacementSeq[l] = ((I[0] - pos1 + n) % n) + 1;
l++;
}
for(int j = n+1; j < gondolaSeq[ I[0] ]; j++)
{
replacementSeq[l] = j;
l++;
}
for(int i = 1; i < n; i++)
{
if(gondolaSeq[ I[i] ] > n)
{
replacementSeq[l] = ((I[i] - pos1 + n) % n) + 1;
l++;
}
for(int j = max(n+1, gondolaSeq[ I[i-1] ] + 1); j < gondolaSeq[ I[i] ]; j++)
{
replacementSeq[l] = j;
l++;
}
}
return l;
}
int countReplacement(int n, int inputSeq[])
{
return 0;
}
| # | 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... |