結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー cho435cho435
提出日時 2023-08-23 20:50:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 571 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 4,850 ms
コンパイル使用メモリ 272,912 KB
実行使用メモリ 60,480 KB
最終ジャッジ日時 2023-08-23 20:50:36
合計ジャッジ時間 9,534 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 546 ms
60,300 KB
testcase_11 AC 556 ms
60,336 KB
testcase_12 AC 545 ms
60,444 KB
testcase_13 AC 571 ms
60,480 KB
testcase_14 AC 546 ms
60,344 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 8 ms
4,596 KB
testcase_21 AC 8 ms
4,780 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int n,h,x;
	cin>>n>>h>>x;
	vector<pair<int,int>> eve;
	set<int> stl={0};
	int g;
	cin>>g;
	rep(i,g){
		int a;
		cin>>a;
		eve.push_back({a,1});
		stl.insert(a);
	}
	int b;
	cin>>b;
	rep(i,b){
		int a;
		cin>>a;
		eve.push_back({a,-1});
		stl.insert(a);
	}
	int m=eve.size();
	rep(i,m){
		for(int df=max(-eve.at(i).first,-x);df<=min(n-eve.at(i).first,x);df++){
			if(!stl.count(eve.at(i).first+df)){
				eve.push_back({eve.at(i).first+df,0});
				stl.insert(eve.at(i).first+df);
			}
		}
	}
	sort(eve.begin(),eve.end());
	m=eve.size();
	if(h>b)	h=b;
	vector<vector<int>> dp(m+1,vector<int>(h+1,-1e9));
	dp.at(0).at(0)=0;
	int bf=0;
	rep(i,m){
		rep(j,h+1){
			if(dp.at(i).at(j)!=-1e9) dp.at(i+1).at(j)=max(dp.at(i+1).at(j),dp.at(i).at(j)+eve.at(i).second);
			if(j<h){
				for(int k=max(0,i-10);k<=i;k++){
					int r=eve.at(k).first;
					int l=(k==0?0:eve.at(k-1).first);
					if(l+x<=eve.at(i).first&&r+x>bf+1&&dp.at(k).at(j)!=-1e9){
						dp.at(i+1).at(j+1)=max(dp.at(i+1).at(j+1),dp.at(k).at(j)+eve.at(i).second);
					}
				}
			}
		}
		bf=eve.at(i).first;
	}
	int ans=-1e9;
	rep(j,h+1){
		ans=max(ans,dp.at(m).at(j));
	}
	cout<<ans<<endl;
}
0