結果

問題 No.1060 素敵な宝箱
ユーザー sapphire__15sapphire__15
提出日時 2022-08-08 04:19:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,091 bytes
コンパイル時間 6,067 ms
コンパイル使用メモリ 214,056 KB
実行使用メモリ 4,392 KB
最終ジャッジ日時 2023-10-17 22:36:11
合計ジャッジ時間 4,784 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define rep(i,n) for(int i = 0; i < int(n); i++)
#define per(i,n) for(int i = (n) - 1; 0 <= i; i--)
#define rep2(i,l,r) for(int i = (l); i < int(r); i++)
#define per2(i,l,r) for(int i = (r) - 1; int(l) <= i; i--)
#define MM << " " <<
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()

template <typename T>
void print(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (v.empty()) cout << '\n';
}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}

template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

// const ll MOD = 1'000'000'007;
const ll MOD = 998'244'353;

///////////////////////////////////////////////////////////////

template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using maxheap = priority_queue<T>;

template <typename T>
int lb(const vector<T> &v, T x) {
    return lower_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
int ub(const vector<T> &v, T x) {
    return upper_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
void rearrange(vector<T> &v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

int main() {
    int n, m; cin >> n >> m;
    vector<vector<ll>> da(n, vector<ll>(m));
    rep(i,n) rep(j,m) cin >> da[i][j];
    vector<ll> su(m);
    rep(i,n) rep(j,m) su[j] += da[i][j];
    vector<pll> kk(n);
    rep(i,n) {
        rep(j,m) kk[i].first += da[i][j] * su[j];
        kk[i].second = i;
    }
    sort(rall(kk));
    vector<ll> a(m), b(m);
    rep(i,n) {
        if(i&1) rep(j,m) b[j] += da[kk[i].second][j];
        else rep(j,m) a[j] += da[kk[i].second][j];
    }
    ll ans = 0;
    rep(i,m) ans += a[i] * a[i] - b[i] * b[i];
    cout << ans << endl;
}
0