結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー jupirojupiro
提出日時 2020-02-08 15:26:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 584 ms / 2,500 ms
コード長 1,939 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 120,460 KB
実行使用メモリ 22,008 KB
最終ジャッジ日時 2024-09-25 08:50:07
合計ジャッジ時間 7,354 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll n;
vector<ll> a, b, c;
bool memo[3050][3050];
bool dp[3050][3050];
bool dfs(ll cur1, ll cur2, ll p) {
	if (p < 0) return true;
	if (memo[cur1][cur2]) return dp[cur1][cur2];
	bool flag = false;
	//cout << cur1 << " " << cur2 << " " << p << endl;
	if (cur1 + 1 <= n && a[cur1 + 1] + b[cur2] >= c[p]) flag |= dfs(cur1 + 1, cur2, p - 1);
	if (cur2 + 1 <= n && a[cur1] + b[cur2 + 1] >= c[p]) flag |= dfs(cur1, cur2 + 1, p - 1);
	memo[cur1][cur2] = true;
	return dp[cur1][cur2] = flag;

}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	scanf("%lld", &n);
	a.resize(n + 1); for (ll i = 0; i <= n; i++) scanf("%lld", &a[i]);
	b.resize(n + 1); for (ll i = 0; i <= n; i++) scanf("%lld", &b[i]);
	c.resize(n); for (ll i = 0; i < n; i++) scanf("%lld", &c[i]);;
	sort(c.begin(), c.end());
	ll left = -1;
	ll right = n;
	while (right - left > 1) {
		ll mid = (left + right) >> 1;
		for (ll i = 0; i <= 3000; i++)for (ll j = 0; j <= 3000; j++) memo[i][j] = false, dp[i][j] = false;
		if (dfs(0, 0, mid)) left = mid;
		else right = mid;
	}

	printf("%lld\n", left + 1);
	return 0;
}
0