| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1318846 | afric | 곤돌라 (IOI14_gondola) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
//#include "gondola.h"
using namespace std;
int valid(int n, int inputSeq[])
{
unordered_set<int> used;
int current = -1;
for (int i = 0; i < n; i++)
{
if (current==-1 && inputSeq[i] <= n)
{
current = inputSeq[i];
continue;
}
if (inputSeq[i] > n)
{
if (used.find(inputSeq[i])!=used.end())
{
return 0;
}
used.insert(inputSeq[i]);
}
if (inputSeq[i] <= n)
{
if (current==n && inputSeq[i] != 1)
{
return 0;
}
if (current!=n&&inputSeq[i] != current+1)
{
return 0;
}
current = inputSeq[i];
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int l =0;
priority_queue<pair<int, int>,vector<pair<int,int>>, greater<pair<int,int>>> r;
vector<int> original(n,-1);
for (int i = 0; i < n; i++)
{
if (gondolaSeq[i] <= n)
{
int c = gondolaSeq[i];
for (int x = i; x < n; x++)
{
original[x] = c;
if (c == n)
{
c = 1;
}
else {
c++;
}
}
c = gondolaSeq[i];
for (int x = (i-1); x >= 0; x--)
{
original[x]=c-1;
if (c==1)
{
c = 5;
}
else{
c--;
}
}
break;
}
if (i==(n-1)&&original[0]==-1)
{
for (int i = 0; i < n; i++)
{
original[i]=i+1;
}
}
}
for (int i = 0; i < n; i++)
{
if (gondolaSeq[i] > n)
{
r.push({gondolaSeq[i],original[i]});
}
}
int next = n+1;
int arr_index = 0;
while (!r.empty())
{
int b = r.top().first;
int o = r.top().second;
r.pop();
replacementSeq[arr_index]=o;
l++;
next++;
arr_index++;
while (b>=next)
{
replacementSeq[arr_index] = next-1;
l++;
next++;
arr_index++;
}
}
/*for (int i = 0; i < l; i++)
{
cout << replacementSeq[i] << endl;
}*/
return l;
}
int countReplacement(int n, int inputSeq[])
{
return 0;
}
/*int main()
{
int s[5] = {8,5,1,2,9};
int r[5];
replacement(5,s,r);
}*/
