Chef and Holi
Chef is celebrating holi with his friends.
They are numbered from 1 to N, where 1 being the chef.
They fill the balloons with colors and start throwing at each other.
In the initial phase, Chef throws a balloon at each of his friends.
Kids continue the game by following the rules mentioned below :
- If even number of balloons are thrown at them in the previous phase, they throw exactly two balloons at each of their friends in the current phase.
- If odd number of balloons are thrown at them in the previous phase, they throw exactly one balloon at each of their friends in the current phase.
Chef is wondering how many balloons are thrown after T phases?
InputFirst line of input contains N and T, number of kids and number of phases.
Next N lines contains a string of 0s and 1s.
The (i, j) character in this NxN matrix is 1 if i and j are friends.
Print number of balloons thrown after T phases.
- 1 ≤ N ≤ 20
- 1 ≤ T ≤ 10^9
Input: 4 2 0010 0010 1100 0000 Output: 7
First phase :
Chef throws 1 balloon at 3.
Second phase :
1 throws 2 balloon at 3.
2 throws 2 balloon at 3.
3 throws 1 balloon at each of 1 and 2.
4 throws nothing.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions