結果

問題 No.1615 Double Down
ユーザー qwewe
提出日時 2025-04-24 12:20:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 79,140 KB
最終ジャッジ日時 2025-04-24 12:21:39
合計ジャッジ時間 6,987 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx +=1
    M = int(input[idx]); idx +=1
    K = int(input[idx]); idx +=1
    L = int(input[idx]); idx +=1

    edges = []
    for _ in range(L):
        X = int(input[idx])-1; idx +=1  # 0-based
        Y = int(input[idx])-1; idx +=1
        Z = int(input[idx]); idx +=1
        edges.append((-Z, -(X + Y), X, Y))  # Sort by -Z (ascending Z), then by -(X+Y) (ascending X+Y)

    # Sort the edges in the required order:
    # First by Z descending, then by (X+Y) descending
    edges.sort()

    used_buyers = [False] * N
    used_items = [False] * M
    total = 0

    for e in edges:
        Z_neg, sum_neg, X, Y = e
        Z = -Z_neg
        if not used_buyers[X] and not used_items[Y]:
            used_buyers[X] = True
            used_items[Y] = True
            total += (1 << Z)

    print(total)

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