# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
953605 | emad234 | Gondola (IOI14_gondola) | C++17 | 0 ms | 0 KiB |
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>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 9;
const ll mxN = 1e6 + 5;
using namespace std;
int gondolaSequence[100001];
int replacementSequence[250001];
int valid(int n, int inputSeq[])
{
vector<bool> vis(250000 + 3);
int st = 0;
int val = 1;
for (int i = 0; i < n; i++)
{
if (vis[inputSeq[i]])
return 0;
vis[inputSeq[i]] = 1;
if (inputSeq[i] <= n)
{
st = i;
val = inputSeq[i];
}
}
int og = st;
while (1)
{
st++;
val++;
if (st >= n)
st = 0;
if (val > n)
val = 1;
if (st == og)
break;
if (inputSeq[st] != val && inputSeq[st] <= n)
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
set<int> s;
int mx = 0;
for (int i = 0; i < n; i++)
mx = max(mx, gondolaSeq[i]);
for (int i = 1; i <= mx; i++)
s.insert(i);
for (int i = 0; i < n; i++)
s.erase(gondolaSeq[i]);
int id = 0;
while(s.size()){
replacementSeq[id] = *s.begin();
s.erase(s.begin());
id++;
}
return id + 1;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
int main()
{
int i, n, tag;
int nr;
assert(scanf("%d", &tag)==1);
assert(scanf("%d", &n)==1);
for(i=0;i< n;i++)
assert( scanf("%d", &gondolaSequence[i]) ==1);
switch (tag){
case 1: case 2: case 3:
printf("%d\n", valid(n, gondolaSequence));
break;
case 4: case 5: case 6:
nr = replacement(n, gondolaSequence, replacementSequence);
printf("%d ", nr);
if (nr > 0)
{
for (i=0; i<nr-1; i++)
printf("%d ", replacementSequence[i]);
printf("%d\n", replacementSequence[nr-1]);
}
else printf("\n");
break;
case 7: case 8: case 9: case 10:
printf("%d\n", countReplacement(n, gondolaSequence));
break;
}
return 0;
}