NOJ common errors and solutions

Based on my current experience and the problems encountered by my classmates, this article summarizes the errors often encountered in NOJ questions and their corresponding solutions.

If you encounter different error prompts, you can quickly troubleshoot them one by one according to the number sequence.

WA

  1. Output format error: Carefully check the output format required by the sample to see if there is more or less output; the more output content should be OE, but currently it will be prompted as WA.
  2. Algorithm errors: Find some samples for testing; mainly because the algorithm fails to achieve the goal of solving the problem, but also includes input reading errors (the problem input format cannot be read correctly, and the input range is not considered), variables that need to be initialized are not initialized, input or The output format characters do not match, the type is wrong, etc.
  3. Extreme values ​​are not considered: test possible extreme values, such as division by 0 modulo 0 operation, some special values ​​that may cause the algorithm to fail, etc.
  4. Out-of-bounds: After the above errors are eliminated, if the input range is not given in the question, and it is correct even for smaller samples, it is considered that the variable is out-of-bounds.

THIS

  1. Syntax error (You may need a good IDE): CB will not report many grammatical errors.
  2. Header files are missing: check the called library functions and macros.
  3. Non-standard usage: such as introducing non-standard libraries. (I saw a classmate’s code actually use windows.h)
  4. Stack overflow: If the recursion is too deep, a large array is opened in the function; normally it should be ME, but currently some prompts are CE.
  5. Infinite loop: debugging loop structure; normally it should be TE, but currently some prompts are CE.
  6. Memory leak: incorrect use of pointers.
  7. Calling restricted functions: For example, srand(time(NULL)) is not used when rand() is called repeatedly, which is very rare.

RE

  1. Accessing illegal memory: such as array out of bounds, calling wild pointer, accessing system reserved memory, etc.
  2. Stack Overflow: Same as before; normally it should be ME, but currently some prompts are RE.
  3. Memory leak: Same as above.
  4. Infinite loop: Same as before; normally it should be TE, but currently some prompts are RE.
  5. Modulo 0 or division by 0: currently the prompt is WA.

THE

  1. infinite loop
  2. The algorithm needs to be optimized: estimate the time complexity of the algorithm. Usually the OJ time judgment standard is as follows (take 1000ms as an example):
  • O(\log n) Will not time out
  • O(n), n\leq 10^8
  • O(n\log n), n \leq 10^6
  • O(n^{1.5}), n\leq 10^5
  • O(n^2), n\leq 5\times 10^3
  • O(n^3), n\leq 300
  • O(2^n), n\leq 25
  • O(3^n), n\leq 15
  • O(n!), n\leq 10

Guess you like

Origin blog.csdn.net/annesede/article/details/133838416