Reslan's blog

By Reslan, history, 8 years ago, In English

Hello everyone

I've trying to solve this problem for a long time but couldn't figure out the solution

since the problem is asking for the minimum number of moves to get to the goal square from statring square

it's solvable with BFS

but the interesting part is how can I represent my state ?

x, y : my position in the grid where x denotes the row and y denotes the column

gridMask : the number of paintings in the grid is exactly 6 , so I'm transferring them to numbers 0, 1, 2, 3, 4, 5, 6,  , at start gridMask is equal to (1«6) - 1 ( since all the painting are in the grid ) , when rolling a blank face of the cube onto a square that had painting , we exclude the corresponding bit to this painting , and move to a new state where this painting was removed from the grid .

cubeMask : as long as the cube is six sided , the state of the cube faces can be represented with a mask to tell us whether the rolled face of the cube is blank or not , model the cube faces as frontFace = 0, backFace = 1, leftFace = 2, rightFace = 3, topFace = 4, bottomFace = 5 , one can easily check whether the rolled face is blank by testing the corresponding bit if(cubeMask&(1«someFace))

till now everything is clear

in the problem statement it was mentioned that when rolling a face of the cube to a square that has no paintings and the face of the cube had painting , the painting transferred from the cube to the grid

so we move to a new state where the corresponding bit of that painting is set on in gridMask and the corresponding bit of the rolled face of the cube is set of in cubeMask

to check if some face of the cube is blank or not already done

but how can I determine for each non-blank face of the cube , the color on that face ?

thanks in advance

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Reslan, history, 8 years ago, In English

Hello codeforces

How to solve this problem

in the tutorial it was mentioned that this problem can be solved using DP

but I'm really confused hot how can I maximize the number of trailing zeroes

thank in advance

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By Reslan, history, 8 years ago, In English

Hello codeforces :D

I was trying to solve this problem

and I got TLE , I tried to solve it using DP.

my approach for this problem , first I find how many 369 are there in the interval [ 1 , B ] , let this value be right

then I find how many 369 are there in the interval [ 1 , A ] , let this value be left

my final answer will be right — left , if A is not 369 number

else it will be : right — left + 1

here is my code

can I do some pre calculations to avoid TLE ?

thank in advance :D

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it

By Reslan, history, 8 years ago, In English

Hello everyone :D I'm given a string s of length n , letters could be uppercase or lowercase. and I need to answer a query of the type : given ( left , right ) ( where left <= right ) count the number of distinct letters in the range [ left , right ] , for example if s = bcAAcbc , n = 7 , query( 0 , 2 ) = 3 , query( 2 , 3 ) = 1, NOTE : by distinct I mean either different letters , or the same letter but the first one is uppercase and the second is lowercase , for instance a and A are distinct , a and b also distinct , A and A are NOT could this problem be solved using segment tree ? thank in advance :D

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

By Reslan, history, 8 years ago, In English

Hello everyone what the idea to solve this problem I know that it may seems pretty easy problem for you , but for me as a beginer in binary search I couldn't even understand the tutorial !! thank in advance :D

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it