結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー aajisakaaajisaka
提出日時 2019-12-12 01:43:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,500 ms
コード長 2,579 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 180,032 KB
実行使用メモリ 39,944 KB
最終ジャッジ日時 2023-09-06 13:42:06
合計ジャッジ時間 4,895 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 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
28,912 KB
testcase_12 AC 61 ms
29,496 KB
testcase_13 AC 93 ms
26,412 KB
testcase_14 AC 12 ms
6,400 KB
testcase_15 AC 63 ms
20,908 KB
testcase_16 AC 129 ms
36,432 KB
testcase_17 AC 6 ms
7,376 KB
testcase_18 AC 57 ms
37,964 KB
testcase_19 AC 79 ms
29,308 KB
testcase_20 AC 16 ms
8,632 KB
testcase_21 AC 6 ms
5,432 KB
testcase_22 AC 9 ms
7,876 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 32 ms
22,048 KB
testcase_25 AC 164 ms
39,796 KB
testcase_26 AC 102 ms
39,736 KB
testcase_27 AC 183 ms
39,944 KB
testcase_28 AC 38 ms
39,672 KB
testcase_29 AC 112 ms
39,752 KB
testcase_30 AC 53 ms
39,656 KB
testcase_31 AC 43 ms
39,768 KB
testcase_32 AC 149 ms
39,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * 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;
}
0