結果

問題 No.54 Happy Hallowe'en
ユーザー msm1993msm1993
提出日時 2020-05-15 15:05:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 77,140 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 04:32:35
合計ジャッジ時間 2,072 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 9 ms
4,348 KB
testcase_05 AC 14 ms
4,348 KB
testcase_06 AC 19 ms
4,348 KB
testcase_07 AC 28 ms
4,348 KB
testcase_08 AC 36 ms
4,348 KB
testcase_09 AC 46 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 44 ms
4,348 KB
testcase_13 AC 45 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 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