結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー 👑 emthrmemthrm
提出日時 2019-12-12 00:24:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 717 ms / 2,500 ms
コード長 2,747 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 129,100 KB
実行使用メモリ 73,996 KB
最終ジャッジ日時 2023-09-06 13:37:07
合計ジャッジ時間 9,330 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 387 ms
52,892 KB
testcase_12 AC 387 ms
53,944 KB
testcase_13 AC 333 ms
47,616 KB
testcase_14 AC 45 ms
9,120 KB
testcase_15 AC 207 ms
37,436 KB
testcase_16 AC 377 ms
67,240 KB
testcase_17 AC 73 ms
11,272 KB
testcase_18 AC 616 ms
70,444 KB
testcase_19 AC 292 ms
53,536 KB
testcase_20 AC 57 ms
13,320 KB
testcase_21 AC 18 ms
7,616 KB
testcase_22 AC 36 ms
12,028 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 347 ms
39,812 KB
testcase_25 AC 540 ms
73,736 KB
testcase_26 AC 519 ms
73,788 KB
testcase_27 AC 448 ms
73,844 KB
testcase_28 AC 717 ms
73,780 KB
testcase_29 AC 432 ms
73,784 KB
testcase_30 AC 293 ms
73,996 KB
testcase_31 AC 264 ms
73,780 KB
testcase_32 AC 467 ms
73,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<int> a(n + 1), b(n + 1), d(n);
  REP(i, n + 1) cin >> a[i];
  REP(i, n + 1) cin >> b[i];
  REP(i, n) cin >> d[i];
  sort(ALL(d));
  vector<vector<int> > dp(n + 1, vector<int>(n + 1, 0)), idx(n + 1, vector<int>(n + 1, INF));
  idx[0][0] = -1;
  REP(i, n + 1) REP(j, n + 1) {
    if (i + 1 <= n) {
      int pos = n - (upper_bound(ALL(d), a[i + 1] + b[j]) - d.begin());
      // cout << i << ' ' << j << ' ' << pos << '\n';
      pos = max(pos, idx[i][j] + 1);
      if (pos < n) {
        if (dp[i + 1][j] < dp[i][j] + 1) {
          dp[i + 1][j] = dp[i][j] + 1;
          idx[i + 1][j] = pos;
        } else if (dp[i + 1][j] == dp[i][j] + 1) {
          idx[i + 1][j] = min(idx[i + 1][j], pos);
        }
      }
      if (dp[i + 1][j] < dp[i][j]) {
        dp[i + 1][j] = dp[i][j];
        idx[i + 1][j] = idx[i][j];
      } else if (dp[i + 1][j] == dp[i][j]) {
        idx[i + 1][j] = min(idx[i + 1][j], idx[i][j]);
      }
    }
    if (j + 1 <= n) {
      int pos = n - (upper_bound(ALL(d), a[i] + b[j + 1]) - d.begin());
      pos = max(pos, idx[i][j] + 1);
      if (pos < n) {
        if (dp[i][j + 1] < dp[i][j] + 1) {
          dp[i][j + 1] = dp[i][j] + 1;
          idx[i][j + 1] = pos;
        } else if (dp[i][j + 1] == dp[i][j] + 1) {
          idx[i][j + 1] = min(idx[i][j + 1], pos);
        }
      }
      if (dp[i][j + 1] < dp[i][j]) {
        dp[i][j + 1] = dp[i][j];
        idx[i][j + 1] = idx[i][j];
      } else if (dp[i][j + 1] == dp[i][j]) {
        idx[i][j + 1] = min(idx[i][j + 1], idx[i][j]);
      }
    }
  }
  cout << dp[n][n] << '\n';
  return 0;
}
0