結果

問題 No.1515 Making Many Multiples
ユーザー nok0nok0
提出日時 2021-05-02 16:07:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 210,268 KB
実行使用メモリ 19,316 KB
最終ジャッジ日時 2023-09-28 06:43:37
合計ジャッジ時間 6,665 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 185 ms
19,164 KB
testcase_03 AC 215 ms
19,128 KB
testcase_04 AC 306 ms
19,084 KB
testcase_05 AC 185 ms
19,316 KB
testcase_06 AC 100 ms
19,084 KB
testcase_07 AC 128 ms
19,092 KB
testcase_08 AC 70 ms
6,888 KB
testcase_09 AC 116 ms
10,844 KB
testcase_10 AC 116 ms
11,416 KB
testcase_11 AC 143 ms
14,264 KB
testcase_12 AC 95 ms
9,944 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 154 ms
15,676 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 181 ms
18,068 KB
testcase_17 AC 28 ms
11,124 KB
testcase_18 AC 21 ms
13,636 KB
testcase_19 AC 6 ms
8,140 KB
testcase_20 AC 30 ms
7,724 KB
testcase_21 AC 99 ms
18,660 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 106 ms
18,556 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 132 ms
18,616 KB
testcase_28 AC 74 ms
18,772 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

#define rep(i, x) for(int i = 0; i < (x); i++)

using T = tuple<int, int, int>;
int n, K, x, y, res;
int main() {
	cin >> n >> K >> x >> y;
	x %= K, y %= K;
	vector a(n, 0);
	vector dp(vector(K, vector(K, -1)));
	vector dp2(vector(K, -1));
	for(auto& v : a) cin >> v, v %= K;

	dp[x][y] = 0;
	dp2[x] = dp2[y] = 0;

	rep(i, n) {
		queue<T> upd;
		rep(j, K) {
			for(int sum = 0; sum <= 2 * K; sum += K) {
				int k = sum - j - a[i];
				if(!(clamp(k, 0, K - 1) == k)) continue;
				auto& now = dp[j][k];
				if(now == -1) continue;
				upd.emplace(j, k, now + 1);
				upd.emplace(a[i], j, now + 1);
				upd.emplace(a[i], k, now + 1);
			}
			upd.emplace(j, a[i], dp2[j]);
		}
		while(!upd.empty()) {
			auto [j, k, val] = upd.front();
			upd.pop();
			chmax(dp[j][k], val);
			chmax(dp[k][j], val);
			chmax(dp2[j], val);
			chmax(dp2[k], val);
		}
	}

	rep(i, K) chmax(res, *max_element(dp[i].begin(), dp[i].end()));

	cout << res << '\n';

	return 0;
}
0