結果
問題 | No.949 飲酒プログラミングコンテスト |
ユーザー | aajisaka |
提出日時 | 2019-12-12 01:43:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 220 ms / 2,500 ms |
コード長 | 2,579 bytes |
コンパイル時間 | 2,038 ms |
コンパイル使用メモリ | 182,804 KB |
実行使用メモリ | 39,936 KB |
最終ジャッジ日時 | 2024-06-24 08:15:08 |
合計ジャッジ時間 | 4,858 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include<bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair<ll, ll>; constexpr double PI = 3.14159265358979323846; mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count()); class Insyuprogrammingcontest { public: int n; vector<int> d; bool calc(int k, vector<vector<int>>& dp, vector<vector<bool>>& check) { if (k==0) return true; check[0][0] = true; for(int i=0; i<=k; i++) { for(int j=0; i+j<=k; j++) { if (i==0 && j==0) continue; int p = i+j; bool flag = false; if (i>0 && check[i-1][j]) flag = true; if (j>0 && check[i][j-1]) flag = true; if (flag && dp[i][j] >= d[n-k+p-1]) { check[i][j] = true; debug(i, j, k); if (i+j==k) return true; } else { check[i][j] = false; } } } return false; } void solve(istream& cin, ostream& cout) { SPEED; cin >> n; vector<int> a(n+1), b(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.rbegin(), d.rend()); vector<vector<int>> dp(n+1, vector<int>(n+1)); vector<vector<bool>> check(n+1, vector<bool>(n+1)); rep(i, n+1) { rep(j, n+1) { dp[i][j] = a[i] + b[j]; } } int mi = 0; int ma = n+1; while(mi+1 < ma) { int k = (mi+ma)/2; if (calc(k, dp, check)) { mi = k; } else { ma = k; } } cout << mi << endl; } }; signed main() { Insyuprogrammingcontest solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }