Skip to main content

All Solution Code of CodeChef May Long Challenge 2021

competitve programming solution here...

solution code of Golf problem number-2 of may long challenge codechef

Golf Problem Code: LKDNGOLFSolvedSubmit


Read problem statements in Bengali, Mandarin Chinese, Russian, and Vietnamese as well.

It's a lockdown. You’re bored in your house and are playing golf in the hallway.


The hallway has N+2 tiles numbered from 0 to N+1 from left to right. There is a hole on tile number x. You hit the ball standing on tile 0. When you hit the ball, it bounces at lengths of k, i.e. the tiles covered by it are 0,k,2k,…, and so on until the ball passes tile N+1.


If the ball doesn't enter the hole in the first trial, you try again but this time standing on the tile N+1. When you hit the ball, it bounces at lengths of k, i.e. the tiles covered by it are (N+1),(N+1−k),(N+1−2k),…, and so on until the ball passes tile 0.


Find if the ball will enter the hole, either in its forward journey or backward journey.


Note: The input and output of this problem are large, so prefer using fast input/output methods.


Input

The first line contains an integer T, the number of test cases. Then the test cases follow.

The only line of each test case contains three integers N,x,k.

Output

Output in a single line, the answer, which should be "YES" if the ball enters the hole either in the forward or backward journey and "NO" if not.


You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).


Constraints

1≤T≤105

1≤x,k≤N≤109

Subtasks

Subtask #1 (10 points): N≤102

Subtask #2 (90 points): original constraints


Sample Input

3

5 4 2

5 3 2

5 5 2

Sample Output

YES

NO

NO

Explanation

In each test case, the tiles covered by the ball for N=5 and k=2 are {0,2,4,6} in the forward journey and {6,4,2,0} in the backward journey.


Therefore, the answer for the first test case is "YES" since the ball falls in the position of the hole at tile 4. But the answer for test cases 2 and 3 is "NO" since the ball does not fall in the position of the hole.


Solution Code

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a ,b ,c;
        cin>>a>>b>>c;
        int sm=(a+1)%c;
        if(b%c==0 || b%c==sm)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0 ;
}

Comments

Popular posts from this blog

solution code of Modular Equation problem number-5 of may long challenge codechef

 Modular Equation Problem Code: CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   endl   " \n " int32_t   main () {      ios_base :: sync_with_stdio ( false );     cin. tie ( 0 );      int  t;cin >> t;      while (t -- )     {          int  n, m;cin >> n >> m;          int  count_of_pair  =   0 ;          vector < int >  modular_equation(n + 1 ,  1 );          for ( int  a  =   2 ;a <= n;a ++ )         {              int  x  =  m % a;             count_of_pair  +=  modular_equation [ x ] ;              for ( int  b  =  x;b <= n;b += a)             {                 modular_equation [ b ] ++ ;             }         }         cout << count_of_pair << endl ;     }      return   0 ; }

solution code of Tree House problem number-6 of may long challenge codechef

 Tree House Problem Solution Code: CodeChef Solution Code #pragma   GCC   optimize (" Ofast ", " unroll-loops ") #include   <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   double   long   double using   pii   =   pair < int ,  int >; template  < typename   T > using   Prior   =   std :: priority_queue < T ,  vector < T >,  greater < T >>; #define   X  first #define   Y  second #define   eb  emplace_back #define   ALL ( x )  begin (x),  end (x) #define   RALL ( x )  rbegin (x),  rend (x) #define   fastIO ()  ios_base ::sync_with_stdio, cin. tie ( 0 ) mt19937_64  rng( chrono :: steady_clock :: now (). time_since_epoch (). count ()); inline   int   getRand ( int   L ,  int   R ) {      if  ( L   >   R )          swap ( L ,  R );      return  ( int )(rng()  %  ( uint64_t )( R   -   L   +   1 )  +   L ); } template  < typename   T1 ,  typename   T2 > ostream   &operator <<( ostre

solution code of Tic Tac Toe problem number-4 of may long challenge codechef

 Tic Tac Toe Problem Solution Code:  CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   ll   long   long   int int   main () {      ll  t;     cin >> t;      while (t -- )     {          ll  cx  =   0 , co  = 0 , c_ =   0 ;          char  a[ 3 ][ 3 ];          for ( ll  i = 0 ;i < 3 ;i ++ )         {              for ( ll  j = 0 ;j < 3 ;j ++ )             {                 cin >> a[i][j];                  if (a[i][j] == 'X' )cx ++ ;                  if (a[i][j] == 'O' )co ++ ;                  if (a[i][j] == '_' )c_ ++ ;             }         }          ll  wx  =   0 , wo  =   0 ;          if (a[ 0 ][ 0 ]  ==   'X'   &&  a[ 1 ][ 0 ]  ==   'X'   &&  a[ 2 ][ 0 ]  ==   'X' )wx = 1 ;          if (a[ 0 ][ 1 ]  ==   'X'   &&  a[ 1 ][ 1 ]  ==   'X'   &&  a[ 2 ][ 1 ]  ==   'X' )wx = 1 ;          if (a[ 0 ][ 2 ]  ==   'X'   &