結果

問題 No.1060 素敵な宝箱
ユーザー scol_kpscol_kp
提出日時 2020-05-22 23:06:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,464 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 206,304 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-28 09:25:02
合計ジャッジ時間 3,334 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 9 ms
4,380 KB
testcase_26 AC 8 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, M;
    cin >> N >> M;
    vector<Vl> A(N, Vl(M));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    Vl ds(M);
    for (ll j = 0; j < M; j++) {
        for (ll i = 0; i < N; i++) {
            ds[j] += A[i][j];
        }
    }

    Vl es(N);
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < M; j++) {
            es[i] += A[i][j] * ds[j];
        }
    }
    sort(es.begin(), es.end(), greater<ll>());

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (i & 1) {
            ans -= es[i];
        }
        else {
            ans += es[i];
        }
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}
0