結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー shobonvipshobonvip
提出日時 2023-08-12 12:50:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 2,433 ms
コンパイル使用メモリ 214,384 KB
実行使用メモリ 47,468 KB
最終ジャッジ日時 2024-04-30 11:15:01
合計ジャッジ時間 3,286 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 59 ms
47,468 KB
testcase_11 AC 58 ms
47,344 KB
testcase_12 AC 56 ms
47,360 KB
testcase_13 AC 58 ms
47,340 KB
testcase_14 AC 56 ms
47,340 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 6 ms
6,944 KB
testcase_21 AC 6 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	int n, h, x; cin >> n >> h >> x;
	
	set<int> g;
	int G; cin >> G;
	for (int i=0; i<G; i++){
		int a; cin >> a;
		g.insert(a);
	}
	
	set<int> b;
	int B; cin >> B;
	for (int i=0; i<B; i++){
		int a; cin >> a;
		b.insert(a);
	}

	set<int> newb;
	newb.insert(0);
	newb.insert(n);
	for (int a: b){
		for (int i=a-x; i<=a+x; i++){
			if (0 <= i && i <= n){
				newb.insert(i);			
			}
		}
	}

	int ans_base = 0;

	for (int a: g){
		if (newb.find(a) == newb.end()){
			ans_base++;
		}
	}

	int m = newb.size();
	vector<int> score(m);
	int piv = 0;
	for (int a: newb){
		if (b.find(a) != b.end()){
			score[piv]--;
		}
		if (g.find(a) != g.end()){
			score[piv]++;
		}
		piv++;
	}

	int r = min(B, h);
	vector<vector<int>> dp(m, vector<int>(r+1, -1e9));
	dp[0][0] = 0;
	for (int i=1; i<m; i++){
		for (int j=0; j<r+1; j++){
			dp[i][j] = max(dp[i][j], dp[i-1][j] + score[i]);
			if (j >= 1 && i-x >= 0){
				dp[i][j] = max(dp[i][j], dp[i-x][j-1] + score[i]);
			}
		}
	}

	int ans = -1e9;
	for (int i=0; i<r+1; i++){
		ans = max(ans, dp[m-1][i]);
	}
	
	cout << ans + ans_base << '\n';
}

0