結果

問題 No.1074 増殖
ユーザー qwewe
提出日時 2025-05-14 12:54:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,574 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 95,996 KB
最終ジャッジ日時 2025-05-14 12:55:33
合計ジャッジ時間 2,254 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    
    L = None
    R = None
    B = None
    T = None
    current_area = 0
    
    for _ in range(N):
        xa = int(input[idx])
        ya = int(input[idx+1])
        xb = int(input[idx+2])
        yb = int(input[idx+3])
        idx +=4
        
        l, r = xa, xb
        b, t = ya, yb
        
        new_area = (r - l) * (t - b)
        
        if L is None:
            # First rectangle
            added = new_area
            L, R, B, T = l, r, b, t
            current_area = added
        else:
            # Calculate overlap with the current union's bounding box
            overlap_l = max(L, l)
            overlap_r = min(R, r)
            overlap_b = max(B, b)
            overlap_t = min(T, t)
            
            if overlap_l < overlap_r and overlap_b < overlap_t:
                overlap_area = (overlap_r - overlap_l) * (overlap_t - overlap_b)
            else:
                overlap_area = 0
            
            # Check if new rectangle fully contains the current union's bounding box
            if l <= L and r >= R and b <= B and t >= T:
                overlap_area = current_area
            
            added = new_area - overlap_area
            
            # Update the bounding box
            L = min(L, l)
            R = max(R, r)
            B = min(B, b)
            T = max(T, t)
            
            current_area += added
        
        print(added)
        
if __name__ == '__main__':
    main()
0