結果

問題 No.527 ナップサック容量問題
ユーザー Nafmo2
提出日時 2017-04-29 08:24:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 894 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 73,712 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-13 19:08:41
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cassert>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const int MOD = 1000000007;
ll dp[100010];
ll N,v,w,V;
ll bk=100000000007;
int main(){
    ios::sync_with_stdio(false);
    cin>>N;
    assert( N <= 100 && 1<=N );
    REP(i,100010)dp[i]=bk;
    REP(i,N){
        cin>>v>>w;
       assert( v <= 1000 && 1<=v );
       assert( w <= 1000&& 1<=w );
        for(int j=100010-1;j>v;j--)
            dp[j]=min(dp[j],dp[j-v]+w);
        for(int j=v;j>0;j--)
            dp[j]=min(dp[j],w);
    }
    cin>>V;
    assert( V <= 100000&& 0<=V );
    dp[V]>0&&dp[V]!=bk?cout<<dp[V]:cout<<"1";
    cout<<endl;
    dp[V+1]<bk?cout<<dp[V+1]-1:cout<<"inf";
    cout<<endl;
}
0