結果

問題 No.1060 素敵な宝箱
ユーザー i_am_nicolen_22i_am_nicolen_22
提出日時 2020-05-23 02:15:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,593 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 171,264 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 23:22:27
合計ジャッジ時間 2,778 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 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 3 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 7 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 8 ms
5,376 KB
testcase_19 AC 7 ms
5,376 KB
testcase_20 AC 13 ms
5,376 KB
testcase_21 AC 12 ms
5,376 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 19 ms
5,376 KB
testcase_25 AC 19 ms
5,376 KB
testcase_26 AC 19 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int suma[310];
int a[310][310];
int sente[310];
int gote[310];
signed main()
{
    /*a*a - (sum_a -a)*(sum_a - a) + ...
    -sum_a^2 + 2 *sum_a(4)*a
    -sum_b^2 + 2 *sum_b(3)*b
                    (2)*c
    -...
    -
    suma*a +sumb*b+sumc*c...の順に貪欲*/
    int n, m;
    cin >> n >> m;
    REP(i,n)
    {
        REP(j,m){
            cin >> a[i][j];
            suma[j] += a[i][j];
        }
    }
    vector<pair<int,int>> v(n);
    REP(i,n){
        v[i].first = 0;
        v[i].second = i;
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            v[i].first += suma[j] * a[i][j];
        }
    }
    sort(ALL(v));
    reverse(ALL(v));
    vector<bool> b(n, false);
    
    for (int i = 0; i < n; i++)
    {
        int x = v[i].second;
        if (i % 2 == 0)
        {
            REP(j,m){
                sente[j] += a[x][j];
            }
        }
        else{
            REP(j,m){
                gote[j] += a[x][j];
            }
        }
    }
    int s = 0, g = 0;
    for (int i = 0; i < m; i++)
    {
        s += sente[i] * sente[i];
        g += gote[i] * gote[i];
    }
    cout << s - g << endl;

    return 0;
}
0