結果

問題 No.1060 素敵な宝箱
ユーザー beetbeet
提出日時 2020-05-22 21:57:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,813 bytes
コンパイル時間 2,700 ms
コンパイル使用メモリ 214,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-28 07:25:01
合計ジャッジ時間 3,825 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


template<typename ...Ts>
decltype(auto) zip(vector<Ts>... args){
  vector<decltype(make_tuple(args[0]...))> res;
  Int n=min({args.size()...});
  res.reserve(n);
  for(Int i=0;i<n;i++) res.emplace_back(args[i]...);
  return res;
}


vector<Int> identity(Int n){
  vector<Int> ord(n);
  iota(ord.begin(),ord.end(),0);
  return ord;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  cin>>n>>m;
  auto A=make_v<Int>(n,m);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<m;j++)
      cin>>A[i][j];

  vector<Int> sum(m);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<m;j++)
      sum[j]+=A[i][j];

  vector<Int> sc(n,0);
  for(Int i=0;i<n;i++){
    for(Int j=0;j<m;j++)
      sc[i]+=A[i][j]*sum[j];
  }

  auto zs=zip(sc,identity(n));
  sort(zs.rbegin(),zs.rend());

  auto C=make_v<Int>(2,m);
  fill_v<Int>(C,0);

  Int pos=0;
  for(auto [_, i]:zs){
    for(Int j=0;j<m;j++)
      C[pos][j]+=A[i][j];
    pos^=1;
  }

  Int ans=0;
  for(Int j=0;j<m;j++)
    ans+=C[0][j]*C[0][j]-C[1][j]*C[1][j];
  cout<<ans<<endl;
  return 0;
}
0