結果

問題 No.1060 素敵な宝箱
ユーザー betrue12betrue12
提出日時 2020-05-22 22:05:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 202,580 KB
最終ジャッジ日時 2025-01-10 14:44:44
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M));
    vector<int64_t> S(M);
    for(int i=0; i<N; i++) for(int j=0; j<M; j++){
        cin >> A[i][j];
        S[j] += A[i][j];
    }
    vector<int64_t> V(N);
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) V[i] += 2*A[i][j]*S[j];
    sort(V.rbegin(), V.rend());
    int64_t ans = 0;
    for(int i=0; i<N; i+=2) ans += V[i];
    for(auto s : S) ans -= s*s;
    cout << ans << endl;
    return 0;
}
0