https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/08/Codeforces-Round-421-Div-2-problem-C-Mister-B-and-Boring-Game-Solution-In-JAVA.png?fit=640%2C360

Codeforces Round #421 (Div. 2), problem: (C) Mister B and Boring Game Solution In JAVA

import java.util.Scanner;

public class C {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);

int a=in.nextInt();
int b=in.nextInt();
int l=in.nextInt();
int r=in.nextInt();

System.out.println(fun(a,b,l,r));

}

static int fun(int a,int b,int l,int r){
if ((r-l+1)>2*(a+b))
if (a<=b)
return a+1;
else
return (2*a-b);

int[] flag = new int[3*(a+b)+1];

int temp=0;
for (int i=1;i<=a;i++){
flag[i]=i;
temp=i;
}

for (int i=a+1;i<=a+b;i++){
flag[i]=temp;
}

for (int i=a+b+1;i<=a+b+a;i++){
int tc=1;
while (in(flag,tc,a+b-a+1,i-1))
tc++;
flag[i]=tc;
temp=flag[i];
}
for (int i=a+b+a+1;i<=a+b+a+b;i++){
flag[i]=temp;
}
for (int i=2*(a+b)+1;i<=3*(a+b);i++){
flag[i]=flag[i-(a+b)];
}

int[] flagc = new int[25];
int templ = l % (a+b);
if (templ==0) templ+=a+b;
int tempr = r – l + templ;
if (tempr<templ) tempr+=a+b;
for (int i=templ;i<=tempr;i++){
flagc[flag[i]]=1;
}

int res=0;
for (int i=1;i<=24;i++)
res+=flagc[i];

return res;

}

static boolean in(int[] a,int b,int l,int r){
for (int i=l;i<=r;i++){
if (a[i]==b)
return true;
}
return false;
}

}

(Visited 155 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: