結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー Mayimg
提出日時 2020-07-24 05:33:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 461 ms / 2,500 ms
コード長 1,377 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 204,836 KB
最終ジャッジ日時 2025-01-12 04:53:27
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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