結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー simansiman
提出日時 2022-03-02 18:44:19
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,500 ms
コード長 1,325 bytes
コンパイル時間 6,590 ms
コンパイル使用メモリ 108,068 KB
実行使用メモリ 12,372 KB
最終ジャッジ日時 2023-09-23 10:42:14
合計ジャッジ時間 12,971 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 96 ms
9,756 KB
testcase_12 AC 104 ms
9,892 KB
testcase_13 AC 85 ms
9,132 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 55 ms
7,804 KB
testcase_16 AC 146 ms
11,516 KB
testcase_17 AC 15 ms
4,552 KB
testcase_18 AC 218 ms
11,960 KB
testcase_19 AC 56 ms
9,768 KB
testcase_20 AC 12 ms
4,808 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 6 ms
4,688 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 70 ms
8,160 KB
testcase_25 AC 219 ms
12,356 KB
testcase_26 AC 228 ms
12,232 KB
testcase_27 AC 192 ms
12,372 KB
testcase_28 AC 232 ms
12,232 KB
testcase_29 AC 88 ms
12,240 KB
testcase_30 AC 34 ms
12,364 KB
testcase_31 AC 17 ms
12,360 KB
testcase_32 AC 181 ms
12,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 3010;
int N;
int A[MAX_N];
int B[MAX_N];
vector<int> D;

bool f(int x) {
  bool dp[N + 2][N + 2];
  memset(dp, false, sizeof(dp));
  dp[0][0] = true;

  for (int i = 0; i < x; ++i) {
    int d = N - x + i;

    for (int a = 0; a <= i; ++a) {
      int b = i - a;
      if (not dp[a][b]) continue;

      int na = a + 1;
      int nb = b + 1;

      if (D[d] <= A[na] + B[b]) {
        dp[na][b] = true;
      }
      if (D[d] <= A[a] + B[nb]) {
        dp[a][nb] = true;
      }
    }
  }

  for (int a = 0; a <= x; ++a) {
    int b = x - a;
    if (dp[a][b]) return true;
  }

  return false;
}

int main() {
  cin >> N;

  for (int i = 0; i < N + 1; ++i) {
    cin >> A[i];
  }

  for (int i = 0; i < N + 1; ++i) {
    cin >> B[i];
  }

  D.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }

  sort(D.begin(), D.end());
  reverse(D.begin(), D.end());
  int ok = 0;
  int ng = N + 1;

  while (abs(ok - ng) >= 2) {
    int x = (ok + ng) / 2;

    if (f(x)) {
      ok = x;
    } else {
      ng = x;
    }
  }

  cout << ok << endl;

  return 0;
}
0