結果

問題 No.2095 High Rise
ユーザー lam6er
提出日時 2025-03-31 17:37:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 751 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 86,512 KB
最終ジャッジ日時 2025-03-31 17:38:03
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
if n == 1:
    print(0)
else:
    a = [list(map(int, input().split())) for _ in range(n)]
    
    # Calculate the minimum cost of fully demolishing a single column
    full_column_min = float('inf')
    for j in range(m):
        total = sum(a[i][j] for i in range(n))
        if total < full_column_min:
            full_column_min = total
    
    # Calculate the sum of minimum costs for each consecutive floor pair
    total_pair = 0
    for i in range(n - 1):
        min_pair = float('inf')
        for j in range(m):
            current = a[i][j] + a[i + 1][j]
            if current < min_pair:
                min_pair = current
        total_pair += min_pair
    
    print(min(full_column_min, total_pair))
0