solution for problem 440 C

Revision en1, by newbie_forever_at_cp, 2017-11-13 20:16:03

hi every one. im having a doubt in codeforces problem 440 C. here is the link http://codeforces.me/problemset/problem/440/C. My approach was

A number x can be represented by having the number with only ones which is less than the given number. for eg if number is 40 one approach is taking 11.

Another is having the number with only ones which is greater than the given number. i.e. 111 for 40 then take absolute difference between the number and the given number i.e abs(11 – 40) = 29 and abs(111 – 40) which is 71.

Now call the function again for the new n. in this case fun(29) and fun(49).

Now added with the number of ones take the min of these two i.e min(fun(29) + 2, fun(71) + 3). that is the answer. Also if we can represent the number with the ones alone. for eg 11 then return 2 just. i.e without computing min(fun(11-11) + 2, fun(111- 11) + 3);

But i got wrong answer in test 14. the input is 81924761239462. and the expected output is 321. And my output is 395. Can you please tell me what is wrong.

here is the link: http://ide.geeksforgeeks.org/kRLASR. THanks in advance

Tags dfs and similar, divide and conquer

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English newbie_forever_at_cp 2017-11-13 20:16:03 1149 Initial revision (published)