Блог пользователя nowerzt

Автор nowerzt, 10 лет назад, По-английски

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.

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится -6 Проголосовать: не нравится

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

  • »
    »
    10 лет назад, # ^ |
      Проголосовать: нравится +27 Проголосовать: не нравится

    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.

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

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).

»
10 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится
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)
...