結果

問題 No.1060 素敵な宝箱
ユーザー minatominato
提出日時 2020-05-23 00:20:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 3,540 ms
コンパイル使用メモリ 238,276 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 20:06:00
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<vector<ll>> A(N, vector<ll>(M));
    rep(i,N) rep(j,M) cin >> A[i][j];

    vector<ll> S(M);
    rep(i,N) rep(j,M) S[j] += A[i][j];
    vector<ll> B(N);
    rep(i,N) rep(j,M) B[i] += S[j]*A[i][j];

    vector<int> idx(N);
    iota(all(idx),0);
    sort(all(idx),[&](int i, int j){return B[i] > B[j];});
    vector<ll> P(M),Q(M);
    rep(i,N) {
        rep(j,M) {
            (i&1 ? Q[j] : P[j]) += A[idx[i]][j];
        }
    }
    ll ans = 0;
    rep(i,M) ans += P[i]*P[i] - Q[i]*Q[i];
    cout << ans << ln;
}
0