Problem solution · Python

ABC361 B — Intersection of Cuboids

ABC361 B — Intersection of Cuboids: 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
28 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 ABC361 B — Intersection of Cuboids, 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

  • 28 lines of Python from the credited upstream file abc361_b.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 codeABC361 B — Intersection of Cuboids · PythonPython
Use this to learn the idea, then write your own version.
# -*- coding: utf-8 -*-  def main():    import sys     input = sys.stdin.readline     # 1次元の区間の問題と言い換え、区間が重ならないと体積が正にならない    # 各軸で条件を満たしているか判定    x1, y1, z1, x2, y2, z2 = map(int, input().split())    x3, y3, z3, x4, y4, z4 = map(int, input().split())     def f(l1, r1, l2, r2):        if r1 <= l2 or r2 <= l1:            return False        else:            return True     if f(x1, x2, x3, x4) and f(y1, y2, y3, y4) and f(z1, z2, z3, z4):        print("Yes")    else:        print("No")  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 ↗