Solution of 1796F by hard-coding

Revision en1, by YocyCraft, 2023-03-01 11:36:58

Problem link: 1796F - Strange Triples

Let p = number of digits of n, q = number of digits of b, we have n=a*b*(10^p-1)/(a*10^q-b), by checking every pair of possible (a, b, p) we have a O(A*B*log(N)) solution, but it will get TLE. However, by let A, B, N be their maximum value, we can see there are only 172104 possible valid tuples can be the answer, so we could solve the problem by hard-coding-- however, each pair of (a,b) will add about 10-20 bytes to the size of code, and we need 2-3MB to store all pairs, which exceed the limit of 64KB. By printing all valid tuples, we can see that for almost all pairs of (a,b), the value of a/b is some integer power of 10, and for other pairs, there are only 6143 different possible values of b. Therefore, we can hardcode these values (for 34 KB), and for b which is not hardcoded, we can only check for a=10^t*b (for every pair of (b, p) there are only 5 possible values of a), then we can solve the problem in 2000ms.

My submission: 195421691

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English YocyCraft 2023-03-01 18:04:35 2
en7 English YocyCraft 2023-03-01 12:25:09 14
en6 English YocyCraft 2023-03-01 12:24:26 285
en5 English YocyCraft 2023-03-01 12:11:59 13
en4 English YocyCraft 2023-03-01 11:51:48 623
en3 English YocyCraft 2023-03-01 11:43:32 49
en2 English YocyCraft 2023-03-01 11:42:02 4896
en1 English YocyCraft 2023-03-01 11:36:58 1034 Initial revision (published)