I would be grateful, if anyone could
point out why the below solution TLEd?
give hints to improve the code running time?
Logic explanation in plain english:
Create a dictionary of string, int.
the key stores the patterns of len 19 for each number w.r.t to parity of each digit e.g ( 00000000101010111011 )
the count of pattern is incremented, decremented accordingly.
Ans is just a dictionary lookup for given pattern
Contest 371 DIV2 Problem C : http://codeforces.net/contest/714/problem/C
Try to submit using PyPy2.
Also, you can store the "strings" as bitmasks, so you can use a list of size 2^18 instead of a dictionary.
There were some flaws in my implementation w.r.t to python code ... Fixing those , now give Accepted . More details about changes here http://stackoverflow.com/questions/39478201/how-to-improve-python-dict-performance