結果

問題 No.1912 Get together 2
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-01 21:18:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 773 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 211,408 KB
実行使用メモリ 238,488 KB
最終ジャッジ日時 2024-04-01 21:19:13
合計ジャッジ時間 18,462 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 26 ms
6,676 KB
testcase_09 AC 22 ms
6,676 KB
testcase_10 AC 37 ms
6,676 KB
testcase_11 AC 28 ms
6,676 KB
testcase_12 AC 47 ms
9,984 KB
testcase_13 AC 750 ms
238,488 KB
testcase_14 AC 773 ms
238,488 KB
testcase_15 AC 735 ms
238,488 KB
testcase_16 AC 766 ms
238,488 KB
testcase_17 AC 749 ms
238,488 KB
testcase_18 AC 732 ms
238,488 KB
testcase_19 AC 723 ms
238,488 KB
testcase_20 AC 724 ms
238,488 KB
testcase_21 AC 748 ms
238,488 KB
testcase_22 AC 727 ms
238,488 KB
testcase_23 AC 715 ms
238,488 KB
testcase_24 AC 725 ms
238,488 KB
testcase_25 AC 744 ms
238,488 KB
testcase_26 AC 721 ms
238,488 KB
testcase_27 AC 744 ms
238,488 KB
testcase_28 AC 56 ms
6,676 KB
testcase_29 AC 55 ms
6,676 KB
testcase_30 AC 59 ms
6,676 KB
testcase_31 AC 49 ms
6,676 KB
testcase_32 AC 50 ms
6,676 KB
testcase_33 AC 727 ms
238,488 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 706 ms
238,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int N, M;cin >> N >> M;
	vector<ll> G((1 << M), 0);
	vector<ll> V(N, 0);ll sm = 0;
	for (int i = 0;i < N;i++) {
		cin >> V[i];
		sm += V[i];
	}
	vector<vector<ll>> zeta((1 << M), vector<ll>(M + 1, 0));
	for (int i= 0;i < N;i++) {
		string s;cin >> s;
		int bit = 0;
		for (int j = 0;j < M;j++) if (s[j] == 'x') bit |= (1 << j);
		G[bit] += V[i];
		zeta[bit][0] += V[i];
	}
	for (int i = 0;i < M;i++) for (int bit = 0;bit < (1 << M);bit++) {
		if (bit & (1 << i)) {
			zeta[bit][i + 1] = zeta[bit][i];
		} else {
			zeta[bit][i + 1] =zeta[bit][i] + zeta[bit | (1 << i)][i];
		}
	}
	vector<ll> S((1 << M), 0);
	for (int bit = 0;bit < (1 << M);bit++) S[bit] = sm - zeta[bit][M];
	vector<ll> dp(1 << M, 0);
	vector<vector<int>> bits(M + 1);
	for (int bit = 0;bit < (1 << M);bit++) bits[__builtin_popcount(bit)].push_back(bit);
	for (int k = 1;k <= M;k++) for (auto bit : bits[k]) {
		for (int v = 0;v < M;v++) {
			if (!(bit & (1 << v))) continue;
			ll t = S[bit] - S[bit ^ (1 << v)];
			dp[bit] = max(dp[bit], dp[bit ^ (1 << v)] + (t * t));
		}
	}
	cout << dp.back() << endl;
}
0