結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー tnakao0123tnakao0123
提出日時 2019-12-14 18:56:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,817 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 87,440 KB
実行使用メモリ 74,192 KB
最終ジャッジ日時 2023-09-10 12:00:54
合計ジャッジ時間 4,153 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 70 ms
52,360 KB
testcase_16 AC 125 ms
71,044 KB
testcase_17 AC 20 ms
27,376 KB
testcase_18 AC 142 ms
73,144 KB
testcase_19 AC 83 ms
65,076 KB
testcase_20 AC 21 ms
31,200 KB
testcase_21 AC 9 ms
20,784 KB
testcase_22 AC 14 ms
29,104 KB
testcase_23 AC 4 ms
10,200 KB
testcase_24 AC 80 ms
54,552 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 137 ms
73,896 KB
testcase_28 AC 150 ms
73,896 KB
testcase_29 WA -
testcase_30 AC 68 ms
73,896 KB
testcase_31 AC 41 ms
73,876 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 949.cc:  No.949 飲酒プログラミングコンテスト - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 3000;

/* typedef */

struct Elm {
  int d, i;
  Elm() {}
  Elm(int _d, int _i): d(_d), i(_i) {}

  bool operator<(const Elm &e) const {
    return d < e.d || (d == e.d && i > e.i);
  }
};

/* global variables */

int as[MAX_N + 1], bs[MAX_N + 1], ds[MAX_N];
Elm dp[MAX_N + 1][MAX_N + 1];

/* subroutines */

template <typename T>
inline void setmax(T &a, T b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i <= n; i++) scanf("%d", as + i);
  for (int i = 0; i <= n; i++) scanf("%d", bs + i);
  for (int i = 0; i < n; i++) scanf("%d", ds + i);
  sort(ds, ds + n);

  for (int i = 0; i <= n; i++) fill(dp[i], dp[i] + n + 1, Elm(0, n));

  for (int i = 0; i < n; i++)
    for (int j = 0; i + j < n; j++) {
      Elm &dp0 = dp[i][j];

      if (dp0.i > 0) {
	int ki = upper_bound(ds, ds + dp0.i, as[i + 1] + bs[j]) - ds - 1;
	setmax<Elm>(dp[i + 1][j],
		    (ki < dp0.i) ? Elm(dp0.d + (ki >= 0 ? 1 : 0), ki) : dp0);

	int kj = upper_bound(ds, ds + dp0.i, as[i] + bs[j + 1]) - ds - 1;
	setmax<Elm>(dp[i][j + 1],
		    (kj < dp0.i) ? Elm(dp0.d + (kj >= 0 ? 1 : 0), kj) : dp0);
      }
      else {
	setmax<Elm>(dp[i + 1][j], dp0);
	setmax<Elm>(dp[i][j + 1], dp0);
      }
    }

  int maxd = 0;
  for (int i = 0; i <= n; i++) setmax<int>(maxd, dp[i][n - i].d);

  printf("%d\n", maxd);
  return 0;
}
0