Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 – Elimination Round 2), problem: (C) Subordinates Solution in C/C++

Hi Guys , I Just Tried to solve the Subordinates problem , hope you might like it , please share if you’ve any better code .

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
u Z[222222],R[222222],C[222222];
int main()
{
u n,s,i,k,fz=0,fnz=0,x,a=-1u;
scanf(“%u%u”,&n,&s);–s;
for(i=-1;++i<n;)
{
scanf(“%u”,&k);
if(!k&&i!=s)++fz;
else if(i==s&&k)++fnz;
else ++C[k];
}
for(i=0;++i<n;)Z[i]=Z[i-1]+(C[i]==0);
for(i=n;i–;)R[i]=R[i+1]+C[i+1];
for(i=0;++i<n;a=a>x?x:a)
x=fnz+(Z[i]>fz+R[i]?Z[i]:fz+R[i]);
printf(“%u\n”,a>n?0:a);
return 0;
}

Hi Guys , I Just Tried to solve the Subordinates problem , hope you might like it , please share if you’ve any better code .

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
u Z[222222],R[222222],C[222222];
int main()
{
u n,s,i,k,fz=0,fnz=0,x,a=-1u;
scanf(“%u%u”,&n,&s);–s;
for(i=-1;++i<n;)
{
scanf(“%u”,&k);
if(!k&&i!=s)++fz;
else if(i==s&&k)++fnz;
else ++C[k];
}
for(i=0;++i<n;)Z[i]=Z[i-1]+(C[i]==0);
for(i=n;i–;)R[i]=R[i+1]+C[i+1];
for(i=0;++i<n;a=a>x?x:a)
x=fnz+(Z[i]>fz+R[i]?Z[i]:fz+R[i]);
printf(“%u\n”,a>n?0:a);
return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

ROSIE SERENADES THE DON…

Comedian and television personality Rosie O’Donnell wrapped up her week-long stint as guest host on Jimmy Kimmel Live! with an unforgettable, razor-sharp send-off aimed...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!