結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー outlineoutline
提出日時 2021-03-12 15:02:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,500 ms
コード長 2,226 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 143,264 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-04-22 02:37:35
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 126 ms
53,248 KB
testcase_12 AC 124 ms
54,016 KB
testcase_13 AC 113 ms
47,744 KB
testcase_14 AC 16 ms
9,344 KB
testcase_15 AC 84 ms
37,504 KB
testcase_16 AC 157 ms
67,200 KB
testcase_17 AC 20 ms
11,136 KB
testcase_18 AC 162 ms
70,528 KB
testcase_19 AC 117 ms
53,504 KB
testcase_20 AC 25 ms
13,440 KB
testcase_21 AC 10 ms
7,424 KB
testcase_22 AC 19 ms
12,288 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 90 ms
39,936 KB
testcase_25 AC 184 ms
73,728 KB
testcase_26 AC 170 ms
73,856 KB
testcase_27 AC 169 ms
73,728 KB
testcase_28 AC 177 ms
73,728 KB
testcase_29 AC 164 ms
73,856 KB
testcase_30 AC 132 ms
73,600 KB
testcase_31 AC 111 ms
73,728 KB
testcase_32 AC 179 ms
73,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    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];
        D[i] *= -1;
    }
    sort(begin(D), end(D));

    using node = pair<int, int>;
    vector<vector<node>> dp(N + 1, vector<node>(N + 1, {0, 0}));
    auto update = [](node& a, node b){
        if(b.first > a.first)   a = b;
        else if(b.first == a.first) chmin(a.second, b.second);
    };
    for(int i = 0; i <= N; ++i){
        for(int j = 0; j <= N; ++j){
            auto& [cnt, pos] = dp[i][j];
            if(i < N){
                int score = A[i + 1] + B[j];
                int npos = lower_bound(begin(D) + pos, end(D), -score) - begin(D);
                update(dp[i + 1][j], {cnt + (npos < N), min(npos + 1, N)});
            }
            if(j < N){
                int score = A[i] + B[j + 1];
                int npos = lower_bound(begin(D) + pos, end(D), -score) - begin(D);
                update(dp[i][j + 1], {cnt + (npos < N), min(npos + 1, N)});
            }
        }
    }

    int ans = 0;
    for(int i = 0; i <= N; ++i){
        chmax(ans, dp[i][N - i].first);
    }
    cout << ans << endl;

    return 0;
}
0