nowerzt's blog

By nowerzt, 11 years ago, In English

Hi guys,

I got runtime error for this submission 6661686. I use gnu++ 0x, compiled no warnings, and ran correct answer for test case "ABACABA" on my machine. But sadly, I get runtime error when submit. This is my first post, and appreciate a lot for your kindly reply. Thanks.

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

| Write comment?
»
11 years ago, # |
Rev. 2   Vote: I like it -6 Vote: I do not like it

Main must return 0. If return code is not zero checker mark it as Runtime error.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it +27 Vote: I do not like it

    Wrong, if main does not return any value, it's defaulted to zero, which is required by C++ standard and do not cause RTE. Note that it holds for main only and not true for another functions.

»
11 years ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

Most runtime errors are caused by
(1)Illegally accessing memory (array out of bound, using wild pointers, etc)
(2)Stack overflow (Recursions go too deep, allocating a very large array on stack, etc)
(3)Arithmetic error (Divide/modulo by zero, etc)

If your code runs correctly on your machine, runtime error is most likely caused by (1).

»
11 years ago, # |
  Vote: I like it +1 Vote: I do not like it
for(int i=N-1;i>=0;i--) {
	if(check(sa[i], sa[i+1])) dp[i]=dp[i+1]+1;
}

Array index out of bounds. Use valgrind or its windows analog if you want to catch this type of errors:

$g++ -std=c++11 -g 432D.cpp && valgrind ./a.out
>ABACABA
...
==24258== Invalid read of size 4
==24258==    at 0x401EE7: SuffixArray::operator[](int) (432D.cpp:60)
==24258==    by 0x4017E8: main (432D.cpp:125)
...