結果
問題 | No.949 飲酒プログラミングコンテスト |
ユーザー |
👑 ![]() |
提出日時 | 2019-12-12 00:24:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 714 ms / 2,500 ms |
コード長 | 2,747 bytes |
コンパイル時間 | 1,372 ms |
コンパイル使用メモリ | 126,576 KB |
最終ジャッジ日時 | 2025-01-08 10:54:09 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <algorithm>#include <bitset>#include <cassert>#include <cctype>#include <chrono>#define _USE_MATH_DEFINES#include <cmath>#include <cstring>#include <ctime>#include <deque>#include <functional>#include <iomanip>#include <iostream>#include <iterator>#include <map>#include <numeric>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <tuple>#include <utility>#include <vector>using namespace std;#define FOR(i,m,n) for(int i=(m);i<(n);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()const int INF = 0x3f3f3f3f;const long long LINF = 0x3f3f3f3f3f3f3f3fLL;const double EPS = 1e-8;const int MOD = 1000000007;// const int MOD = 998244353;const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},// dx[] = {0, -1, -1, -1, 0, 1, 1, 1};struct IOSetup {IOSetup() {cin.tie(nullptr);ios_base::sync_with_stdio(false);cout << fixed << setprecision(20);cerr << fixed << setprecision(10);}} iosetup;/*-------------------------------------------------*/int main() {int n; cin >> n;vector<int> a(n + 1), b(n + 1), d(n);REP(i, n + 1) cin >> a[i];REP(i, n + 1) cin >> b[i];REP(i, n) cin >> d[i];sort(ALL(d));vector<vector<int> > dp(n + 1, vector<int>(n + 1, 0)), idx(n + 1, vector<int>(n + 1, INF));idx[0][0] = -1;REP(i, n + 1) REP(j, n + 1) {if (i + 1 <= n) {int pos = n - (upper_bound(ALL(d), a[i + 1] + b[j]) - d.begin());// cout << i << ' ' << j << ' ' << pos << '\n';pos = max(pos, idx[i][j] + 1);if (pos < n) {if (dp[i + 1][j] < dp[i][j] + 1) {dp[i + 1][j] = dp[i][j] + 1;idx[i + 1][j] = pos;} else if (dp[i + 1][j] == dp[i][j] + 1) {idx[i + 1][j] = min(idx[i + 1][j], pos);}}if (dp[i + 1][j] < dp[i][j]) {dp[i + 1][j] = dp[i][j];idx[i + 1][j] = idx[i][j];} else if (dp[i + 1][j] == dp[i][j]) {idx[i + 1][j] = min(idx[i + 1][j], idx[i][j]);}}if (j + 1 <= n) {int pos = n - (upper_bound(ALL(d), a[i] + b[j + 1]) - d.begin());pos = max(pos, idx[i][j] + 1);if (pos < n) {if (dp[i][j + 1] < dp[i][j] + 1) {dp[i][j + 1] = dp[i][j] + 1;idx[i][j + 1] = pos;} else if (dp[i][j + 1] == dp[i][j] + 1) {idx[i][j + 1] = min(idx[i][j + 1], pos);}}if (dp[i][j + 1] < dp[i][j]) {dp[i][j + 1] = dp[i][j];idx[i][j + 1] = idx[i][j];} else if (dp[i][j + 1] == dp[i][j]) {idx[i][j + 1] = min(idx[i][j + 1], idx[i][j]);}}}cout << dp[n][n] << '\n';return 0;}