4

Task 296 Tree Value

 1 year ago
source link: https://www.codeabbey.com/index/forum_topic/d0b794f0d2d84eb2b52dd0b1c579ae7e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Task 296 Tree Value

Back to General discussions forum

ecolog_veteran     2023-08-08 19:38:05
User avatar

Don't know if it is allowed to ask for a hint, but I am stuck with this problem. Test data from example gives the right answer, but test data for which I need to find the answer gives a wrong one. I've tried using 1024-bit integer (from boost), taking modulo of all node values, but nothing has worked. My algorithm is straightforward -- it recursively traverses through all nodes calculating their values, and I can't understand what I am getting wrong here. Any advice will be appreciated.

Rodion (admin)     2023-08-08 21:41:02
User avatar

Don't know if it is allowed to ask for a hint

I believe it's quite ok, just the matter whether someone could and want provide a hint :)

My algorithm is straightforward

generally problems created by Clive (aka CSFPython) may need some cunning, also they (unless I have forgotten something) never require using long arithmetics :)

take this for the first hint as I see with some surprise I solved it myself after some struggle, but can't remember the idea at once.

Code provided by Clive for data generator in this problem works in Python (which is 10-20 times slower compared to natively compiled C/C++) and seemingly does the trick in about a second.

Please login and solve 5 problems to be able to post at forum

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK