yoshi_likes_e5's blog

By yoshi_likes_e5, history, 2 hours ago, In English

I have this code here: https://codeforces.me/contest/444/submission/310588587. It is really weird that:

  • On custom invocation, it sometimes output 6, then after that it just do -1

  • The res[id][i] value never seems to be written to the correct value (2), even though I have checked for overflow and the value is correct

  • On my machine, it output 2 as normal.

  • Putting res as a global variable fixes the above.

Can anyone explains why this happen, is it a bug in my code or a bug on Codeforces?

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
66 minutes ago, # |
  Vote: I like it +4 Vote: I do not like it

You're using GCC-extension Variable Length Array, which is not standard C++. You need to initialize it with braces:

int a[n] int a[n]{0}
vector<int> v[n] vector<int> v[n]{vector<int>()}

Fixed code: 310833679