結果

問題 No.54 Happy Hallowe'en
ユーザー PachicobuePachicobue
提出日時 2018-11-21 03:28:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 205,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 02:33:49
合計ジャッジ時間 3,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 41 ms
4,380 KB
testcase_06 AC 61 ms
4,376 KB
testcase_07 AC 94 ms
4,380 KB
testcase_08 AC 124 ms
4,380 KB
testcase_09 AC 163 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 161 ms
4,380 KB
testcase_13 AC 162 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
int main()
{
    int N;
    std::cin >> N;
    using P = std::pair<int, int>;
    std::vector<P> D(N);
    for (int i = 0; i < N; i++) { std::cin >> D[i].first >> D[i].second; }
    std::sort(D.begin(), D.end(), [](const P& p1, const P& p2) { return p1.first + p1.second < p2.first + p2.second; });
    std::bitset<20001> dp;
    dp[0] = true;
    for (const auto& p : D) {
        for (int i = p.second - 1; i >= 0; i--) { dp[i + p.first] = dp[i] | dp[i + p.first]; }
    }
    for (int i = 20000; i >= 0; i--) {
        if (dp[i]) { return std::cout << i << std::endl, 0; }
    }
    return 0;
}
0