結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2019-12-19 11:14:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,500 ms
コード長 1,569 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 167,764 KB
実行使用メモリ 102,008 KB
最終ジャッジ日時 2023-09-21 06:37:22
合計ジャッジ時間 8,041 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
40,240 KB
testcase_01 AC 12 ms
40,180 KB
testcase_02 AC 11 ms
40,168 KB
testcase_03 AC 11 ms
40,276 KB
testcase_04 AC 12 ms
40,220 KB
testcase_05 AC 12 ms
40,288 KB
testcase_06 AC 12 ms
40,332 KB
testcase_07 AC 12 ms
40,920 KB
testcase_08 AC 16 ms
42,628 KB
testcase_09 AC 13 ms
41,088 KB
testcase_10 AC 15 ms
41,580 KB
testcase_11 AC 302 ms
90,296 KB
testcase_12 AC 316 ms
91,456 KB
testcase_13 AC 276 ms
87,216 KB
testcase_14 AC 49 ms
51,168 KB
testcase_15 AC 195 ms
77,352 KB
testcase_16 AC 350 ms
94,036 KB
testcase_17 AC 61 ms
53,636 KB
testcase_18 AC 418 ms
100,448 KB
testcase_19 AC 210 ms
81,172 KB
testcase_20 AC 56 ms
53,580 KB
testcase_21 AC 26 ms
45,852 KB
testcase_22 AC 38 ms
50,132 KB
testcase_23 AC 15 ms
41,668 KB
testcase_24 AC 235 ms
82,544 KB
testcase_25 AC 429 ms
101,416 KB
testcase_26 AC 436 ms
101,884 KB
testcase_27 AC 385 ms
97,212 KB
testcase_28 AC 441 ms
102,008 KB
testcase_29 AC 300 ms
90,936 KB
testcase_30 AC 172 ms
80,512 KB
testcase_31 AC 126 ms
75,004 KB
testcase_32 AC 396 ms
98,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX = 3010;

int dp[MAX][MAX];
int solve[MAX][MAX];
int ans[MAX][MAX];
int main() {
	int n; cin >> n;
	int a[n + 1];
	for(int i = 0; i <= n; ++i) cin >> a[i];
	int b[n + 1];
	for(int i = 0; i <= n; ++i) cin >> b[i];
	int d[n];
	for(int i = 0; i < n; ++i) cin >> d[i];
	sort(d, d + n);
	reverse(d, d + n);
	dp[0][0] = a[0] + b[0];
	for(int i = 0; i < MAX; ++i) {
		for(int j = 0; j < MAX; ++j) {
			solve[i][j] = n;
		}
	}
	solve[0][0] = -1;
	ans[0][0] = 0;
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= n; ++j) {
			if(i == 0 and j == 0) continue;
			if(i - 1 >= 0) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j] - a[i - 1] + a[i]);
				int ng = solve[i - 1][j], ok = n;
				while(abs(ok - ng) > 1) {
					int mid = (ok + ng) / 2;
					if(d[mid] <= dp[i][j]) {
						ok = mid;
					} else {
						ng = mid;
					}
				}
				solve[i][j] = min(solve[i][j], ok);
				if(solve[i][j] != n) {
					ans[i][j] = max(ans[i][j], ans[i - 1][j] + 1);
				}
			}
			if(j - 1 >= 0) {
				dp[i][j] = max(dp[i][j], dp[i][j - 1] - b[j - 1] + b[j]);
				int ng = solve[i][j - 1], ok = n;
				while(abs(ok - ng) > 1) {
					int mid = (ok + ng) / 2;
					if(d[mid] <= dp[i][j]) {
						ok = mid;
					} else {
						ng = mid;
					}
				}
				solve[i][j] = min(solve[i][j], ok);
				if(solve[i][j] != n) {
					ans[i][j] = max(ans[i][j], ans[i][j - 1] + 1);
				}
			}
		}
	}
	int anss = 0;
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= n; ++j) {
			anss = max(anss, ans[i][j]);
		}
	}
	cout << anss << '\n';
	return 0;
}
0