結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー MayimgMayimg
提出日時 2020-07-24 05:33:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 400 ms / 2,500 ms
コード長 1,377 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 207,948 KB
実行使用メモリ 108,940 KB
最終ジャッジ日時 2023-09-06 14:06:26
合計ジャッジ時間 8,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 270 ms
77,932 KB
testcase_12 AC 281 ms
79,400 KB
testcase_13 AC 248 ms
70,024 KB
testcase_14 AC 34 ms
12,216 KB
testcase_15 AC 163 ms
54,456 KB
testcase_16 AC 296 ms
99,064 KB
testcase_17 AC 51 ms
15,108 KB
testcase_18 AC 380 ms
103,920 KB
testcase_19 AC 203 ms
78,520 KB
testcase_20 AC 42 ms
18,616 KB
testcase_21 AC 14 ms
9,564 KB
testcase_22 AC 30 ms
16,736 KB
testcase_23 AC 4 ms
4,428 KB
testcase_24 AC 217 ms
58,280 KB
testcase_25 AC 350 ms
108,920 KB
testcase_26 AC 343 ms
108,920 KB
testcase_27 AC 290 ms
108,884 KB
testcase_28 AC 400 ms
108,840 KB
testcase_29 AC 285 ms
108,940 KB
testcase_30 AC 231 ms
108,904 KB
testcase_31 AC 201 ms
108,832 KB
testcase_32 AC 323 ms
108,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1), b(n + 1);
  for (auto& x : a) cin >> x;
  for (auto& x : b) cin >> x;
  vector<vector<int>> val(n + 1, vector<int>(n + 1));
  for (int i = 0; i < n + 1; i++) for (int j = 0; j < n + 1; j++) val[i][j] = a[i] + b[j];
  vector<int> d(n);
  for (auto& x : d) cin >> x;
  sort(d.begin(), d.end());
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, -(1 << 30)));
  dp[0][0] = n;
  for (int i = 0; i < n + 1; i++) for (int j = 0; j < n + 1; j++) {
    if (i == 0 && j == 0) continue;
    int idx = upper_bound(d.begin(), d.end(), val[i][j]) - d.begin();
    idx--;
    if (i > 0) dp[i][j] = max(dp[i][j], min(idx, dp[i - 1][j] - 1));
    if (j > 0) dp[i][j] = max(dp[i][j], min(idx, dp[i][j - 1] - 1));
  }
  vector<vector<int>> cnt(n + 1, vector<int>(n + 1));
  cnt[0][0] = 0;
  for (int i = 0; i < n + 1; i++) for (int j = 0; j < n + 1; j++) {
    if (i > 0 && dp[i][j] >= 0 && dp[i][j] < dp[i - 1][j]) cnt[i][j] = max(cnt[i][j], cnt[i - 1][j] + 1);
    if (j > 0 && dp[i][j] >= 0 && dp[i][j] < dp[i][j - 1]) cnt[i][j] = max(cnt[i][j], cnt[i][j - 1] + 1);
  }
  int ans = 0;
  for (int i = 0; i < n + 1; i++) for (int j = 0; j < n + 1; j++) ans = max(ans, cnt[i][j]);
  cout << ans << endl;
  return 0;
}
0