You are not logged in. Please login at www.codechef.com to post your questions!

×

Codeforces k-Tree

Problem: http://codeforces.com/problemset/problem/431/C

Solution: http://www.hastebin.com/qugasuduji.vala

I am unable to figure out why the above code (same logic as editorial) is leading to WA in test case 7. Could someone please help me identify where I am going wrong? I am guessing it's something to do with the mod, but not too sure.

asked 16 Sep '15, 17:21

sandy999's gravatar image

2★sandy999
39111638
accept rate: 10%


You need to change the 'int' dp[104][2] to 'long long' dp[104][2]. This is because the temporary result stored in dp[i][k] is of data type int which overflows and wraps around to give negative results and hence wrong answer.

Accepted solution

link

answered 17 Sep '15, 07:13

devilhector's gravatar image

2★devilhector
384
accept rate: 11%

edited 17 Sep '15, 07:13

Thanks @devilhector, I was making this mistake in another problem as well. Finally understood why the WA.

(17 Sep '15, 11:11) sandy9992★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,214
×1,070
×688

question asked: 16 Sep '15, 17:21

question was seen: 3,519 times

last updated: 17 Sep '15, 11:11