https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/09/Codeforces-Round-436-Div-2-problem-D-Make-a-Permutation-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #436 (Div. 2), problem: (D) Make a Permutation! Solution In C/C++

#include<stdio.h>
int a[200005], b[200005], sum[200005], flag[200005];
int main(void)
{
int n, i, p, k;
scanf(“%d”, &n);
for(i=1;i<=n;i++)
{
scanf(“%d”, &a[i]);
sum[a[i]]++;
}
k = 0;
for(i=1;i<=n;i++)
{
if(sum[i]==0)
b[++k] = i;
}
printf(“%d\n”, k);
p = 1;
for(i=1;i<=n;i++)
{
if(sum[a[i]]==1)
continue;
if(b[p]<a[i] || flag[a[i]]==1)
{
sum[a[i]]–;
a[i] = b[p];
sum[b[p]]++;
p++;
}
else
flag[a[i]] = 1;
}
for(i=1;i<=n;i++)
printf(“%d “, a[i]);
printf(“\n”);
return 0;
}

(Visited 28 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: