結果

問題 No.54 Happy Hallowe'en
ユーザー なおなお
提出日時 2014-10-30 23:14:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,488 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 70,456 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-28 23:29:25
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 39 ms
4,380 KB
testcase_05 AC 65 ms
4,380 KB
testcase_06 AC 96 ms
4,384 KB
testcase_07 AC 139 ms
4,380 KB
testcase_08 AC 182 ms
4,376 KB
testcase_09 AC 230 ms
4,504 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 38 ms
4,376 KB
testcase_12 AC 219 ms
4,376 KB
testcase_13 AC 216 ms
4,376 KB
testcase_14 AC 39 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 42 ms
4,376 KB
testcase_18 AC 29 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定解法: DP

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
void rc(int v,int mn,int mx){if(v<mn||mx<v){cerr<<"error"<<endl;}}

const int MAXN = 10000;
const int MAXV = 10000;
const int MAXT = 10000;
int N,V,T;
set<int> s[MAXT+1];
bool dp[MAXT+1];

int main(){
    cin >> N; rc(N,1,MAXN);
    int maxt = 0;
    REP(i,N){
        cin >> V >> T; rc(V,1,MAXV); rc(T,1,MAXT);
        s[T-1].insert(V);
        maxt = max(maxt, T);
    }
    dp[0] = true;
    int res = 0;
    REP(i,maxt){
        RREP(j,i+1){
            if(!dp[j]) continue;
            for(auto it = s[i].begin(); it != s[i].end(); ++it){
                int v = *it;
                int k = j + v;
                if(k < maxt) dp[k] = true;
                res = max(res, k);
            }
        }
    }
    cout << res << endl;
    return 0;
}

/* 解説 

s[i]には所持数i以下に適用できるデータを持ち、
閾値が低い家から順に処理していきます。

dp[j]には所持数jが存在するかを持たせ、
現在の所持数が i以下の場合に、+V することが出来るので
i以下のjについて dp[j] が存在する場合 dp[j+V] にフラグを立てます。
重複して+Vしないよう、i→0 の順に処理する必要があります。

*/
0