結果
| 問題 | 
                            No.1060 素敵な宝箱
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hitonanode
                         | 
                    
| 提出日時 | 2020-05-22 22:40:51 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 8 ms / 2,000 ms | 
| コード長 | 1,150 bytes | 
| コンパイル時間 | 2,271 ms | 
| コンパイル使用メモリ | 208,868 KB | 
| 最終ジャッジ日時 | 2025-01-10 14:57:10 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<lint>> A(N, vector<lint>(M));
    cin >> A;
    vector<lint> tot(M);
    REP(i, N) REP(j, M) tot[j] += A[i][j];
    vector<pair<lint, vector<lint>>> vp;
    REP(i, N)
    {
        lint val = 0;
        REP(j, M) val += tot[j] * A[i][j];
        vp.emplace_back(-val, A[i]);
    }
    sort(vp.begin(), vp.end());
    vector<vector<lint>> d(2, vector<lint>(M));
    bool b = false;
    for (auto x : vp)
    {
        REP(i, M) d[b][i] += x.second[i];
        b = !b;
    }
    lint ret = 0;
    REP(i, M) ret += d[0][i] * d[0][i] - d[1][i] * d[1][i];
    cout << ret << '\n';
}
            
            
            
        
            
hitonanode