結果

問題 No.1912 Get together 2
ユーザー kwm_tkwm_t
提出日時 2022-04-23 18:12:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,607 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 203,672 KB
実行使用メモリ 28,660 KB
最終ジャッジ日時 2023-09-07 11:10:12
合計ジャッジ時間 7,039 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 11 ms
4,692 KB
testcase_09 AC 9 ms
4,436 KB
testcase_10 AC 14 ms
5,168 KB
testcase_11 AC 11 ms
4,616 KB
testcase_12 AC 17 ms
5,416 KB
testcase_13 AC 182 ms
28,548 KB
testcase_14 AC 179 ms
28,660 KB
testcase_15 AC 181 ms
28,564 KB
testcase_16 AC 184 ms
28,500 KB
testcase_17 AC 179 ms
28,428 KB
testcase_18 AC 177 ms
28,500 KB
testcase_19 AC 173 ms
28,488 KB
testcase_20 AC 171 ms
28,416 KB
testcase_21 AC 170 ms
28,492 KB
testcase_22 AC 169 ms
28,428 KB
testcase_23 AC 165 ms
28,488 KB
testcase_24 AC 165 ms
28,472 KB
testcase_25 AC 164 ms
28,496 KB
testcase_26 AC 166 ms
28,492 KB
testcase_27 AC 164 ms
28,516 KB
testcase_28 AC 23 ms
7,456 KB
testcase_29 AC 23 ms
7,300 KB
testcase_30 AC 25 ms
7,296 KB
testcase_31 AC 21 ms
7,208 KB
testcase_32 AC 22 ms
7,260 KB
testcase_33 AC 157 ms
28,496 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 156 ms
28,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector<long long>a(n);
	rep(i, n)cin >> a[i];
	vector<string>s(n);
	vector<int>ok(n, 0);
	rep(i, n) {
		cin >> s[i];
		rep(j, m) {
			if ('o' == s[i][j])ok[i] |= 1 << j;
		}
	}
	vector<long long>zeta(1 << m);
	rep(i, n)zeta[ok[i]] += a[i];
	rep(j, m) {
		rep(i, 1 << m) {
			if (1 & (i >> j)) {
				zeta[i] += zeta[i & ~(1 << j)];
				//zeta[i] += zeta[i ^ (1 << j)];
			}
		}
	}
	vector<long long>dp(1 << m, -LINF);
	dp[0] = 0;
	int bit = (1 << m) - 1;
	rep(i, 1 << m) {
		rep(j, m) {
			if (1 & (i >> j))continue;
			int ni = i + (1 << j);
			long long val = zeta[bit ^i] - zeta[bit - ni];
			chmax(dp[i ^ (1 << j)], dp[i] + val * val);
		}
	}
	cout << dp[bit] << endl;
	return 0;
}
0