結果
| 問題 | No.1060 素敵な宝箱 |
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-05-22 21:57:05 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,813 bytes |
| 記録 | |
| コンパイル時間 | 2,568 ms |
| コンパイル使用メモリ | 221,792 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-10 06:31:40 |
| 合計ジャッジ時間 | 2,995 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#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;
}
beet