| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 337031 | blue | 곤돌라 (IOI14_gondola) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <iostream>
#include <set>
#include <vector>
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;
}
