結果

問題 No.1515 Making Many Multiples
ユーザー nok0nok0
提出日時 2021-04-30 10:41:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 655 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 210,260 KB
実行使用メモリ 14,944 KB
最終ジャッジ日時 2023-09-25 11:16:40
合計ジャッジ時間 7,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
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 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void chmax(int& x, const int y) {
	x = max(x, y);
}

int n, k, x, y, res;
int main() {
	cin >> n >> k >> x >> y;
	x %= k, y %= k;
	vector a(n, 0);
	for(auto& v : a) cin >> v, v %= k;
	map<pair<int, int>, int> dp;

	dp[{x, y}] = 0;
	for(const auto& v : a) {
		map<pair<int, int>, int> ndp;
		for(const auto& [key, val] : dp) {
			const auto [z, w] = key;
			int nxt = val + (v + z + w == 0 or v + z + w == k or v + z + w == 2 * k);
			chmax(ndp[{v, w}], nxt);
			chmax(ndp[{v, z}], nxt);
			chmax(ndp[{z, w}], nxt);
		}
		dp = ndp;
	}
	for(const auto& [key, val] : dp) chmax(res, val);
	cout << res << '\n';
}
0