Robots and Energy
Practice
0 (0 votes)
Dynamic programming
Linear algebra
Hard
Matrix exponentiation
Algorithms
Mathematics
Open
Approved
Problem
45% Success 188 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

There is a grid of n rows and m columns each cell containing a robot. Rows are numbered 0 to n-1 and columns 0 to m-1. Every robot has some initial energy associated with it which is equal to the number of distinct palindromes in its name. Some robots are connected with special connectors. Every morning these connectors generate some amount of energy and distribute it among the robots which are connected via this connector. This is how it actually works- Let two robots R1 with energy e1 and R2 with energy e2 are connected to each other, then the connector will generate energy e2 for robot R1 and energy e1 for robot R2 i.e final energy of robots R1 and R2 is e1+e2 both. On second day they both have energy 2*(e1+e2), as on 2nd day connector will use energies from the previous day not the initial energies. Your task is to calculate the final energy (modulo 1000000007) of each robot after D days. Two Robots can be connected to each other with multiple connectors.

INPUT -

First line contains two integers (n,m) ,size of grid. Next n lines containing m space separated words(names of each robots). Then one integer C(number of connectors) Next C lines contains four integers(x1,y1,x2,y2) each i.e. robot at (x1,y1) is connected with robot at(x2,y2) 0 <= x1,x2 < n 0 <= y1,y2 < m Last line contains one integer D.

OUTPUT-

n lines each containing m space separated integers i.e. final energy of each robot after D days modulo (10^9+7).

Constraints-

1 <= n,m <= 10

0 <= C <= 100

0 < D <= 1000000000

Robot names contains only lowercase (a-z) characters.

1<= length of each robot name <= 10

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
4 votes
Tags:
Graph TheoryLinear AlgebraHardMatrix ExponentiationAlgorithmsRecursionMathematicsOpenApproved
Points:50
2 votes
Tags:
Linear AlgebraHardApprovedMathematicsOpenMatrix Exponentiation
Points:50
Tags:
Dynamic ProgrammingLinear AlgebraHardApprovedMathematicsOpenMatrix Exponentiation