Problem solution · Python

ABC184 C — Super Ryuma

ABC184 C — Super Ryuma: a Python solution using direct simulation. Learn the idea, check the complexity, and read the full code, with credit to KATO-Hiro AtCoder Solutions.

Technique
Direct simulation
Source
KATO-Hiro AtCoder Solutions
Length
50 lines
Start with the idea.

Try the problem first. If you get stuck, read the approach below, then write your own solution. The full code is at the bottom.

Approach

Direct simulation

For ABC184 C — Super Ryuma, the implementation follows the problem’s operations directly while maintaining only the state needed for the next decision.

  1. Translate each rule into one explicit state update.
  2. Maintain the invariant after every processed item.
  3. Return the accumulated state once all relevant input has been handled.

Code notes

  • 50 lines of Python from the credited upstream file abc184_c.py.
  • The implementation visibly relies on ordered lookup.
  • No explicit loop blocks detected.

Complexity

Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.

Check the problem constraints before deciding whether this complexity will pass.

Source

Code and credit

This code comes from KATO-Hiro AtCoder Solutions by KATO-Hiro and is used under the CC0-1.0 licence.

Full codeABC184 C — Super Ryuma · PythonPython
Use this to learn the idea, then write your own version.
# -*- coding: utf-8 -*-  def solve(x, y):    # 手数0: 同一の点    if x == 0 and y == 0:        return 0     # 手数1: 問題文の定義    if (x + y) == 0:        return 1    if (x - y) == 0:        return 1    if abs(x) + abs(y) <= 3:        return 1     # 手数2: 場合分け    # 操作ABのパターン: パリティが一致するかどうか    if (x + y) % 2 == 0:        return 2    # 操作CCのパターン: マンハッタン距離が6以下    if abs(x) + abs(y) <= 6:        return 2    # 操作AC、BCのパターン    if abs(x + y) <= 3:        return 2    if abs(x - y) <= 3:        return 2     # それ以外は、手数3    return 3  def main():    import sys     input = sys.stdin.readline     x1, y1 = map(int, input().split())    x2, y2 = map(int, input().split())     x = x2 - x1    y = y2 - y1     print(solve(x, y))  if __name__ == "__main__":    main() 

Did this explanation save you time? I'm a Grade 11 student building this free library to make difficult algorithms easier to understand.

Buy me a coffee ↗