結果

問題 No.949 飲酒プログラミングコンテスト
コンテスト
ユーザー siman
提出日時 2022-03-02 18:44:19
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 121 ms / 2,500 ms
コード長 1,325 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,479 ms
コンパイル使用メモリ 148,864 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2026-03-30 22:20:08
合計ジャッジ時間 7,073 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:23:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   23 |   bool dp[N + 2][N + 2];
      |                  ^~~~~
main.cpp:23:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:5: note: declared here
   17 | int N;
      |     ^
main.cpp:23:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   23 |   bool dp[N + 2][N + 2];
      |           ^~~~~
main.cpp:23:11: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:5: note: declared here
   17 | int N;
      |     ^
2 warnings generated.

ソースコード

diff #
raw source code

#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