結果

問題 No.1060 素敵な宝箱
ユーザー okok
提出日時 2020-05-22 22:41:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 90,476 KB
実行使用メモリ 13,764 KB
最終ジャッジ日時 2024-04-15 17:47:40
合計ジャッジ時間 4,509 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,764 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

int ans;
int N, M;
vector<vector<int>> A;
vector<vector<int>> X;
vector<int> used;

int rec(int depth = 0){ //cout<<depth<<endl;
	int sum = 0;
	for(int j = 0; j < M; j++){
		sum += (X[0][j] * X[0][j]) - (X[1][j] * X[1][j]);
	}
		
	if(depth == N) {
		
		ans = max(ans, sum);
		
		return sum;
	} else {
		if(depth%2 == 0 && ans < sum) return -INF;
	}
	
	
	int maximum = -INF, minimum = INF;
	
	for(int i = 0; i < N; i++){
		if(used[i]) continue;
		used[i] = true;
		
		// X[depth][i]
		for(int j = 0; j < M; j++){
			X[depth%2][j] += A[i][j];
		}
		
		int temp = rec(depth+1);
		
		maximum = max(temp, maximum);
		minimum = min(temp, minimum);
		
		for(int j = 0; j < M; j++){
			X[depth%2][j] -= A[i][j];
		}
		
		used[i] = false;
	}
	
	if(depth%2 == 0) return maximum;
	return minimum;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	cin>>N>>M;
	
	A.resize(N, vector<int>(M));
	X.resize(2, vector<int>(M));
	used.resize(N);
	
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			cin>>A[i][j];
		}
	}
	
	ans = rec();
	
	cout<<ans<<endl;
	
	return 0;
}
0