abhaysp's blog

By abhaysp, history, 14 months ago, In English

Hi,

I'm trying out problem 189A (https://codeforces.me/problemset/problem/189/A). I wrote simple DP (memoization) solution. Upon submission it's giving WA for test case 7


Input 10 3 4 5 Output 275861439 Answer 3 Checker Log wrong answer 1st words differ - expected: '3', found: '275861439'

Here's my latest submission for the code (the one giving WA): https://codeforces.me/problemset/submission/189/221916967

When I run my code locally with the same failing test case, I get the correct answer. It happened one time before with test case 1 also. Locally, I got correct result, but on submission, it failed. Upon resubmitting with slight change in code (added reference operator '&' in parameter of recursive function, didn't changed the logic), the test case passed and now failing at test case 7.

Pls help in understanding why is this happening, so that I can avoid the mistake (if any) moving further.

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
14 months ago, # |
  Vote: I like it +16 Vote: I do not like it

https://codeforces.me/contest/189/submission/221947880

array<int, 3> sums is actually UB, because this array can contain any numbers. array<int, 3> sums{} calls a default constructor for std::array, making it zeroed.