結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー risujirohrisujiroh
提出日時 2019-12-12 00:10:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,500 ms
コード長 1,110 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 173,012 KB
実行使用メモリ 4,656 KB
最終ジャッジ日時 2023-09-06 13:35:03
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 67 ms
4,404 KB
testcase_12 AC 91 ms
4,504 KB
testcase_13 AC 64 ms
4,380 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 58 ms
4,384 KB
testcase_16 AC 116 ms
4,384 KB
testcase_17 AC 18 ms
4,380 KB
testcase_18 AC 149 ms
4,472 KB
testcase_19 AC 53 ms
4,380 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 4 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 79 ms
4,384 KB
testcase_25 AC 116 ms
4,420 KB
testcase_26 AC 134 ms
4,576 KB
testcase_27 AC 132 ms
4,384 KB
testcase_28 AC 170 ms
4,656 KB
testcase_29 AC 75 ms
4,416 KB
testcase_30 AC 20 ms
4,384 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 124 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<int> b(n + 1);
  for (auto&& e : b) {
    cin >> e;
  }
  vector<int> d(n);
  for (auto&& e : d) {
    cin >> e;
  }
  sort(begin(d), end(d));
  auto chk = [&](int m) {
    vector<int> c(begin(d), begin(d) + m);
    reverse(begin(c), end(c));
    vector< bitset<3001> > dp(m + 1);
    dp[0][0] = true;
    for (int x = 0; x <= m; ++x) {
      for (int y = 0; x + y <= m; ++y) {
        if (not dp[x][y]) {
          continue;
        }
        if (x + y < m and a[x + 1] + b[y] >= c[x + y]) {
          dp[x + 1][y] = true;
        }
        if (x + y < m and a[x] + b[y + 1] >= c[x + y]) {
          dp[x][y + 1] = true;
        }
      }
    }
    for (int x = 0; x <= m; ++x) {
      if (dp[x][m - x]) {
        return true;
      }
    }
    return false;
  };
  int ok = 0, ng = n + 1;
  while (ng - ok > 1) {
    int mid = (ok + ng) / 2;
    (chk(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
}
0