https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/11/Codeforces-Round-443-Div-2-problem-D-Teams-Formation-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #443 (Div. 2), problem: (D) Teams Formation Solution In C/C++

#include <stdio.h>
struct node
{
__int64 ans,num;
}s[101000];
int main()
{
int n,k,m;
while(~scanf(“%d%d%d”,&n,&k,&m))
{
scanf(“%I64d”,&s[0].num);
s[0].ans=1;
int len=1;
for(int i=1;i<n;i++)
{
int x;
scanf(“%d”,&x);
if(x==s[len-1].num)
{
s[len-1].ans++;
if(s[len-1].ans==k)
{
s[len-1].ans=0;
len–;
}
}
else
{
s[len].num=x;
s[len].ans=1;
len++;
}
}
int l=0,r=len-1;
__int64 sum=0;
while(s[l].num==s[r].num&&r>l)
{
if((s[l].ans+s[r].ans)>=k)sum+=k;
s[l].ans=(s[l].ans+s[r].ans)%k;
s[r].ans=0;
if(s[l].ans!=0)
{
break;
}
l++,r–;
}
if(l==r)
{
if((s[l].ans*m)%k==0)sum=0;
else sum+=((s[l].ans*m)%k);
}
else
{
for(int i=l;i<=r;i++)
{
sum+=(s[i].ans*m);
}
}

printf(“%I64d\n”,sum);
}
return 0;
}

(Visited 5 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: