https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/01/Codeforces-Round-388-Div-2-problem-C-Voting-Solution-in-CC1.png?fit=640%2C360

Codeforces Round #388 (Div. 2), problem: (C) Voting Solution in C/C++

Codeforces Round #388 (Div. 2), problem: (C) Voting Solution in C/C++

 

#include<stdio.h>
typedef unsigned u;
char S[222222],D[222222];
int main()
{
	u l,i,ds,rs,dq,rq;
	ds=rs=dq=rq=0;
	scanf("%u%s",&l,S);
	for(i=-1;++i<l😉
	{
		if(S[i]=='D')++ds;
		if(S[i]=='R')++rs;
	}
	for(;ds&&rs😉
	{
		for(i=-1;++i<l😉if(!D[i])
		{
			if(S[i]=='D')
			{
				if(dq){--dq;--ds;D[i]=1;continue;}
				++rq;
			}
			if(S[i]=='R')
			{
				if(rq){--rq;--rs;D[i]=1;continue;}
				++dq;
			}
		}
	}
	if(ds)putchar('D');
	if(rs)putchar('R');
	return 0;
}
(Visited 106 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: