結果

問題 No.1060 素敵な宝箱
ユーザー chocopuu
提出日時 2020-05-22 22:09:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,848 bytes
コンパイル時間 3,876 ms
コンパイル使用メモリ 198,780 KB
最終ジャッジ日時 2025-01-10 14:47:20
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

struct UF{
	vector<int>par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		sz[x]+=sz[y];
		par[y]=x;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

void solve(){
	int N,M;
	cin >> N >> M;
	vector<vector<int>>c(N,vector<int>(M));
	REP(i,N){
		REP(j,M){
			cin >> c[i][j];
		}
	}
	vector<int>a(M),b(M);
	vector<int>used(N);
	REP(i,N){
		int ma = -INF,idx = -1;
		REP(j,N){
			if(used[j])continue;
			auto next = a;
			REP(k,M){
				next[k] += c[j][k];
			}
			int sum = 0;
			REP(k,M){
				sum += next[k] * next[k];
			}
			if(CHMAX(ma,sum)){
				idx = j;
			}
		}
		if(i % 2){
			REP(j,M)b[j] += c[idx][j];
		}else{
			REP(j,M)a[j] += c[idx][j];
		}
		used[idx] = 1;
	}
	int ans = 0;
	REP(i,M)ans += a[i] * a[i] - b[i] * b[i];
	out(ans);
}

signed main(){
	IOS();
	int Q = 1;
	//cin >> Q;
	while(Q--)solve();
}
0