結果

問題 No.1912 Get together 2
ユーザー gew1fw
提出日時 2025-06-12 15:36:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,016 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 182,356 KB
最終ジャッジ日時 2025-06-12 15:37:39
合計ジャッジ時間 24,207 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 29 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    M = int(input[idx])
    idx +=1
    V = list(map(int, input[idx:idx+N]))
    idx += N
    S = []
    for _ in range(N):
        S.append(input[idx])
        idx +=1
    
    boxes = []
    for j in range(M):
        allowed = []
        for i in range(N):
            if S[i][j] == 'o':
                allowed.append((V[i], i))
        allowed.sort(reverse=True, key=lambda x: x[0])
        total = sum(v for v, i in allowed)
        boxes.append((-total, allowed, j))
    
    boxes.sort()
    boxes = [ (allowed, j) for (total, allowed, j) in boxes ]
    
    assigned = [False] * N
    sum_squares = 0
    
    for allowed, j in boxes:
        current_sum = 0
        for v, i in allowed:
            if not assigned[i]:
                current_sum += v
                assigned[i] = True
        sum_squares += current_sum ** 2
    
    print(sum_squares)

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