Solution of 1796F by hard-coding

Правка en1, от 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

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en8 Английский YocyCraft 2023-03-01 18:04:35 2
en7 Английский YocyCraft 2023-03-01 12:25:09 14
en6 Английский YocyCraft 2023-03-01 12:24:26 285
en5 Английский YocyCraft 2023-03-01 12:11:59 13
en4 Английский YocyCraft 2023-03-01 11:51:48 623
en3 Английский YocyCraft 2023-03-01 11:43:32 49
en2 Английский YocyCraft 2023-03-01 11:42:02 4896
en1 Английский YocyCraft 2023-03-01 11:36:58 1034 Initial revision (published)