Got AC on codeBlocks but TLE in codeforces for white lines, give hint to optimize this

problem link: https://codeforces.com/problemset/problem/1200/D
code link:
https://ide.codingblocks.com/s/256873

The test cases in coding blocks are weaker. So it is possible that your solution is slower. Try to optimize it and get it AC. Since I am not a Java coder I can’t help you with the optimization. Google karlo and you’ll get some good articles.

Hi Dhruv
I just checked your code and found out that you are using too many loops. The first 5 loops can be combined into a single loop as all of them are working on different matrices and hence are independent of each other.
Also the loop at line 60 is a O(n^3). The hint here is that codeforces has given you 256 megabytes of memory to use. See if you can convert it to O(n^2) based on pre-storing your if-else data clauses.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.