結果

問題 No.54 Happy Hallowe'en
ユーザー face4face4
提出日時 2019-11-20 22:43:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 76,784 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-29 13:35:51
合計ジャッジ時間 1,987 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// kmjpさんの解説を読んだ
// v1,t1 と v2,t2について1->2がokで2->1がダメなとき、
// v1 < t2 かつ v2 >= t1より、
// v1+t1 < v2+t2
// 1を先に回った方が良いことから、(v+t)昇順に回るのが
// 良いとわかる
// 面白い
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> vp;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        vp.push_back({a+b, b});
    }
    sort(vp.begin(), vp.end());
    bool dp[20000] = {};
    dp[0] = true;
    for(pair<int,int> p : vp){
        for(int j = p.second-1; j >= 0; j--){
            dp[j+p.first-p.second] |= dp[j];
        }
    }
    for(int j = 19999;;j--){
        if(dp[j]){
            cout << j << endl;
            return 0;
        }
    }
}
0