結果
| 問題 | No.527 ナップサック容量問題 | 
| コンテスト | |
| ユーザー |  ama_nuko | 
| 提出日時 | 2018-06-12 02:31:35 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 13 ms / 2,000 ms | 
| コード長 | 1,187 bytes | 
| コンパイル時間 | 784 ms | 
| コンパイル使用メモリ | 95,948 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-30 13:49:43 | 
| 合計ジャッジ時間 | 2,292 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:2:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:67:17:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'max' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:51:9: note: 'max' was declared here
   51 |     int max;
      |         ^~~
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:62:17:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'min' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:43:9: note: 'min' was declared here
   43 |     int min;
      |         ^~~
            
            ソースコード
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>
#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9+7;
signed main(){
    int n, vv;
    cin >> n;
    vector<int> v(n), w(n);
    rep(i, n) cin >> v[i] >> w[i];
    cin >> vv;
    vector<int> dp(100001);
    rep(i, n){
        for(int j = 100000; j >= 0; j--){
            if(j < w[i]){
                continue;
            }
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    int sum = 0;
    rep(i, n){
        sum += v[i];
    }
    int min;
    rep(i, 100001){
        if(dp[i] == vv){
            min = i;
            break;
        }
    }
    int max;
    for(int i = 100000; i >= 0; i--){
        if(dp[i] == vv){
            max = i;
            break;
        }
    }
    if(min == 0){
        cout << 1 << endl;
    }else{
        cout << min << endl;
    }
    if(sum == vv){
        cout << "inf" << endl;
    }else{
        cout << max << endl;
    }
    return 0;
}
            
            
            
        