結果

問題 No.2423 Merge Stones
ユーザー startcppstartcpp
提出日時 2023-08-12 13:50:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,154 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 65,320 KB
実行使用メモリ 6,764 KB
最終ジャッジ日時 2023-08-12 13:53:31
合計ジャッジ時間 20,842 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 315 ms
6,660 KB
testcase_12 AC 149 ms
6,548 KB
testcase_13 AC 316 ms
6,736 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 284 ms
6,472 KB
testcase_17 AC 194 ms
6,528 KB
testcase_18 AC 282 ms
6,488 KB
testcase_19 AC 148 ms
6,548 KB
testcase_20 WA -
testcase_21 AC 323 ms
6,460 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 172 ms
6,584 KB
testcase_25 AC 171 ms
6,704 KB
testcase_26 AC 168 ms
6,472 KB
testcase_27 WA -
testcase_28 AC 331 ms
6,664 KB
testcase_29 WA -
testcase_30 AC 209 ms
6,492 KB
testcase_31 AC 203 ms
6,484 KB
testcase_32 AC 328 ms
6,704 KB
testcase_33 AC 169 ms
6,488 KB
testcase_34 WA -
testcase_35 AC 209 ms
6,524 KB
testcase_36 AC 205 ms
6,536 KB
testcase_37 AC 168 ms
6,592 KB
testcase_38 AC 177 ms
6,528 KB
testcase_39 WA -
testcase_40 AC 313 ms
6,736 KB
testcase_41 AC 235 ms
6,488 KB
testcase_42 AC 322 ms
6,552 KB
testcase_43 AC 149 ms
6,484 KB
testcase_44 AC 318 ms
6,484 KB
testcase_45 AC 171 ms
6,636 KB
testcase_46 AC 244 ms
6,536 KB
testcase_47 WA -
testcase_48 AC 177 ms
6,604 KB
testcase_49 AC 142 ms
6,524 KB
testcase_50 AC 146 ms
6,556 KB
testcase_51 AC 292 ms
6,484 KB
testcase_52 AC 285 ms
6,464 KB
testcase_53 AC 332 ms
6,484 KB
testcase_54 AC 283 ms
6,744 KB
testcase_55 AC 332 ms
6,468 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 354 ms
6,460 KB
testcase_62 AC 322 ms
6,528 KB
testcase_63 AC 322 ms
6,728 KB
testcase_64 AC 346 ms
6,604 KB
testcase_65 AC 324 ms
6,740 KB
testcase_66 AC 333 ms
6,528 KB
testcase_67 AC 325 ms
6,644 KB
testcase_68 AC 356 ms
6,528 KB
testcase_69 AC 324 ms
6,552 KB
testcase_70 AC 355 ms
6,488 KB
testcase_71 AC 345 ms
6,460 KB
testcase_72 AC 318 ms
6,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//bitで作れる色の集合を持つと間に合いそう
#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, K;
int a[600], ra[601];
int c[600];
int dp[601][601];
bool memo[601][601];

//[l, r) -> return: x (ibit目が1なら色i(>=0)にできる, 0なら色i(>=0)にできない)
int dfs(int l, int r) {
	if (r - l == 1) { return (1LL << c[l]); }
	if (memo[l][r]) { return dp[l][r]; }
	
	int ret = 0;
	for (int i = l + 1; i < r; i++) {
		int res1 = dfs(l, i);
		int res2 = dfs(i, r);
		
		int res = 0;
		for (int j = 0; j <= K; j++) {
			res |= res1 & (res2 << j);
		}
		for (int j = 0; j <= K; j++) {
			res |= res1 & (res2 >> j);
		}
		ret |= res;
	}
	memo[l][r] = true;
	return dp[l][r] = ret;
}

signed main() {
	int i, j;

	cin >> n >> K;
	rep(i, n) cin >> a[i];
	rep(i, n) a[n + i] = a[i];
	rep(i, 2 * n) ra[i + 1] = ra[i] + a[i];
	rep(i, n) { cin >> c[i]; c[i]--; }
	rep(i, n) c[n + i] = c[i];

	int ans = 0;
	rep(i, n) {
		for (j = 1; j <= n; j++) {
			int res = dfs(i, i + j);
			if (res > 0) {
				ans = max(ans, ra[i + j] - ra[i]);
			}
		}
	}

	cout << ans << endl;
	return 0;
}
0