結果

問題 No.54 Happy Hallowe'en
ユーザー tubo28tubo28
提出日時 2014-10-31 01:50:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 553 ms / 5,000 ms
コード長 1,057 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 20:05:02
合計ジャッジ時間 4,828 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 151 ms
4,376 KB
testcase_05 AC 222 ms
4,376 KB
testcase_06 AC 294 ms
4,376 KB
testcase_07 AC 389 ms
4,376 KB
testcase_08 AC 464 ms
4,380 KB
testcase_09 AC 553 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 550 ms
4,380 KB
testcase_13 AC 553 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define loop(i,a,b) for(ll i=(a);i<ll(b);i++)
#define rep(i,b) loop(i,0,b)

// housou de kotae wo kikimashita

int main(){
    int N;
    while(cin>>N){
    vector<tuple<int,int,int>> v(N);
    rep(i,N){
        int x,y,z;
        cin>>x>>y;
        z=x+y;
        v[i]=tie(z,x,y);
    }
    sort(v.begin(),v.end());
    vi cur(30000);
    cur[0]=1;
    rep(i,N){
        vi next(30000);
        int V,T;
        tie(ignore,V,T)=v[i];
        for(int j=0;j<=20000;j++){
            next[j]|=cur[j];
            if(cur[j] && j<T){
                next[j+V]|=cur[j];
            }
        }
        // for(int j=0;j<20;j++){
        //     cout<<next[j]<<" ";
        // }
        // cout<<endl;
        swap(cur,next);
    }
    int ans=0;
    rep(i,cur.size())if(cur[i])ans=i;
    cout<<ans<<endl;
    }
}
0