| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 780882 | vjudge1 | 곤돌라 (IOI14_gondola) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include "gondola.h"
#define MAX 250000
using namespace std;
int mark[MAX + 10];
vector <pair <int, int>> v;
int valid(int n, int inputSeq[])
{
int posOrig = -1;
for (int i = 0; i < n; i++)
{
if (mark[inputSeq[i]] == 1)
return 0;
if (inputSeq[i] <= n)
posOrig = i;
mark[inputSeq[i]] = 1;
}
if (posOrig == -1)
return 1;
int pos = posOrig;
for (int i = 1; i <= n; i++)
{
if (inputSeq[pos] <= n && (inputSeq[pos] - inputSeq[posOrig] + n) % n != (pos - posOrig + n) % n)
return 0;
pos = (pos + 1) % n;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int posOrig = -1;
for (int i = 0; i < n; i++)
if (gondolaSeq[i] <= n)
posOrig = i;
if (posOrig == -1)
for (int i = 0; i < n; i++)
v.push_back({gondolaSeq[i], i + 1});
else
{
int pos = posOrig;
int ind = gondolaSeq[posOrig];
for (int i = 1; i <= n; i++)
{
if (gondolaSeq[pos] > n)
v.push_back({gondolaSeq[pos], ind});
pos = (pos + 1) % n;
if (ind == n - 1)
ind = (ind + 1) % n + n;
else
ind = (ind + 1) % n;
}
}
sort(v.begin(), v.end());
int l = 0, nn = n + 1;
for (auto it : v)
{
replacementSeq[l] = it.second;
l++;
nn++;
while (nn <= it.first)
{
replacementSeq[l] = nn - 1;
l++;
nn++;
}
}
return l;
}
