結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー misora192misora192
提出日時 2020-05-09 14:49:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,500 ms
コード長 1,282 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 170,496 KB
実行使用メモリ 12,232 KB
最終ジャッジ日時 2023-09-19 06:37:11
合計ジャッジ時間 4,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 49 ms
9,484 KB
testcase_12 AC 55 ms
9,760 KB
testcase_13 AC 46 ms
8,844 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 31 ms
6,680 KB
testcase_16 AC 62 ms
9,640 KB
testcase_17 AC 10 ms
4,648 KB
testcase_18 AC 85 ms
11,736 KB
testcase_19 AC 30 ms
7,152 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 41 ms
8,100 KB
testcase_25 AC 78 ms
12,208 KB
testcase_26 AC 84 ms
12,232 KB
testcase_27 AC 72 ms
11,148 KB
testcase_28 AC 90 ms
12,204 KB
testcase_29 AC 44 ms
8,416 KB
testcase_30 AC 15 ms
5,796 KB
testcase_31 AC 6 ms
5,856 KB
testcase_32 AC 71 ms
11,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int n;
vector<int> a, b, d;

bool cond(int k){
	if(k == 0) return true;

	bool dp[k+1][k+1];
	rep(i, k + 1) rep(j, k + 1) dp[i][j] = false;
	dp[0][0] = true;

	rep(i, k) {
		dp[i+1][0] = dp[i][0] && (d[k-i-1] <= a[i+1] + b[0]);
		rep(j, i) dp[i+1][j+1] = (dp[i][j] || dp[i][j+1]) && (d[k-i-1] <= a[i-j] + b[j+1]);
		dp[i+1][i+1] = dp[i][i] && (d[k-i-1] <= a[0] + b[i+1]);
	}

	rep(i, k + 1) if(dp[k][i]) return true;
	return false;
}

// condを満たす最大のxを求める(upper_bound)
// 全てのxが条件を満たさない場合は-1を返す(-1はとりえない値)
int upper_bound_cond(){
	int lb = -1, ub = n+1;

	while(ub - lb > 1){
		int mid = (lb + ub) / 2;

		bool ok = cond(mid);
		// cout << mid << "," << ok << "\n";
		if(ok) lb = mid;   // Answer is in [mid, ub)
		else ub = mid;            // Answer is in [lb, mid)
	}

	// now lb + 1 = ub
	return lb;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;

	a.resize(n + 1);
	b.resize(n + 1);
	d.resize(n);
	rep(i, n + 1) cin >> a[i];
	rep(i, n + 1) cin >> b[i];
	rep(i, n) cin >> d[i];

	sort(d.begin(), d.end());
	cout << upper_bound_cond() << endl;
}
0