結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー finefine
提出日時 2019-12-15 16:05:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,500 ms
コード長 1,715 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 172,744 KB
実行使用メモリ 73,928 KB
最終ジャッジ日時 2023-09-15 15:35:24
合計ジャッジ時間 5,965 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 167 ms
52,972 KB
testcase_12 AC 167 ms
53,956 KB
testcase_13 AC 150 ms
47,652 KB
testcase_14 AC 20 ms
9,604 KB
testcase_15 AC 111 ms
37,552 KB
testcase_16 AC 211 ms
67,208 KB
testcase_17 AC 26 ms
11,304 KB
testcase_18 AC 223 ms
70,300 KB
testcase_19 AC 151 ms
53,416 KB
testcase_20 AC 32 ms
13,272 KB
testcase_21 AC 12 ms
7,724 KB
testcase_22 AC 22 ms
12,028 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 120 ms
40,228 KB
testcase_25 AC 243 ms
73,836 KB
testcase_26 AC 235 ms
73,820 KB
testcase_27 AC 230 ms
73,928 KB
testcase_28 AC 235 ms
73,804 KB
testcase_29 AC 216 ms
73,828 KB
testcase_30 AC 162 ms
73,812 KB
testcase_31 AC 134 ms
73,732 KB
testcase_32 AC 240 ms
73,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    
    vector<int> a(n + 1), b(n + 1), d(n);
    for (int i = 0; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    vector< vector<int> > dp(n + 1, vector<int>(n + 1, 0));
    vector< vector<int> > memo(n + 1, vector<int>(n + 1, n));

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i < n) {
                int tar = a[i + 1] + b[j];
                int idx = upper_bound(d.begin(), d.begin() + memo[i][j], tar) - d.begin();
                int score = dp[i][j];
                if (idx > 0) {
                    --idx;
                    ++score;
                }
                if (dp[i + 1][j] < score || (dp[i + 1][j] == score && memo[i + 1][j] < idx)) {
                    dp[i + 1][j] = score;
                    memo[i + 1][j] = idx;
                } 
            }

            if (j < n) {
                int tar = a[i] + b[j + 1];
                int idx = upper_bound(d.begin(), d.begin() + memo[i][j], tar) - d.begin();
                int score = dp[i][j];
                if (idx > 0) {
                    --idx;
                    ++score;
                }
                if (dp[i][j + 1] < score || (dp[i][j + 1] == score && memo[i][j + 1] < idx)) {
                    dp[i][j + 1] = score;
                    memo[i][j + 1] = idx;
                } 
            }
        }
    }
    cout << dp[n][n] << "\n";
    return 0;
}
0