結果

問題 No.2261 Coffee
ユーザー lam6er
提出日時 2025-03-20 18:55:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 1,821 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 147,560 KB
最終ジャッジ日時 2025-03-20 18:57:12
合計ジャッジ時間 14,275 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    points = []
    for _ in range(N):
        A = list(map(int, input[idx:idx + 5]))
        idx += 5
        points.append(A)
    
    # Generate coefficients for each mask
    coeffs = []
    for m in range(32):
        cm = []
        for k in range(5):
            if (m >> k) & 1:
                cm.append(1)
            else:
                cm.append(-1)
        coeffs.append(cm)
    
    # Precompute max and min for each mask
    max_vals = [-float('inf')] * 32
    min_vals = [float('inf')] * 32
    for m in range(32):
        cm = coeffs[m]
        current_max = -float('inf')
        current_min = float('inf')
        for p in points:
            feature = (p[0] * cm[0] +
                       p[1] * cm[1] +
                       p[2] * cm[2] +
                       p[3] * cm[3] +
                       p[4] * cm[4])
            if feature > current_max:
                current_max = feature
            if feature < current_min:
                current_min = feature
        max_vals[m] = current_max
        min_vals[m] = current_min
    
    # Compute result for each point
    results = []
    for p in points:
        max_dist = 0
        for m in range(32):
            cm = coeffs[m]
            feature = (p[0] * cm[0] +
                       p[1] * cm[1] +
                       p[2] * cm[2] +
                       p[3] * cm[3] +
                       p[4] * cm[4])
            candidate = max(max_vals[m] - feature, feature - min_vals[m])
            if candidate > max_dist:
                max_dist = candidate
        results.append(max_dist)
    
    # Output results
    sys.stdout.write("\n".join(map(str, results)) + "\n")

if __name__ == "__main__":
    main()
0