結果
| 問題 | 
                            No.1060 素敵な宝箱
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-05-22 21:51:11 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 618 bytes | 
| コンパイル時間 | 2,544 ms | 
| コンパイル使用メモリ | 201,900 KB | 
| 最終ジャッジ日時 | 2025-01-10 14:39:29 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int n,m; scanf("%d%d",&n,&m);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:11:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         rep(i,n) rep(j,m) scanf("%d",&a[i][j]);
      |                           ~~~~~^~~~~~~~~~~~~~~
            
            ソースコード
#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;
}