結果

問題 No.1060 素敵な宝箱
コンテスト
ユーザー fura
提出日時 2020-05-22 21:51:11
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 618 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,419 ms
コンパイル使用メモリ 220,496 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-10 06:26:47
合計ジャッジ時間 2,633 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<vector<int>> a(n,vector<int>(m));
	rep(i,n) rep(j,m) scanf("%d",&a[i][j]);

	vector<lint> num(m),score(n);
	rep(i,n) rep(j,m) num[j]+=a[i][j];
	rep(i,n) rep(j,m) score[i]+=num[j]*a[i][j];

	vector<int> ord(n);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin(),ord.end(),[&](int i1,int i2){
		return score[i1]>score[i2];
	});

	lint ans=0;
	rep(i,n){
		if(i%2==0) ans+=score[ord[i]];
		else       ans-=score[ord[i]];
	}
	printf("%lld\n",ans);

	return 0;
}
0