結果

問題 No.527 ナップサック容量問題
ユーザー asdf1asdf1
提出日時 2018-03-23 10:25:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 4,274 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 145,676 KB
実行使用メモリ 294,188 KB
最終ジャッジ日時 2023-09-07 02:22:20
合計ジャッジ時間 4,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
17,712 KB
testcase_01 AC 6 ms
19,808 KB
testcase_02 AC 5 ms
15,724 KB
testcase_03 AC 6 ms
19,724 KB
testcase_04 AC 4 ms
11,612 KB
testcase_05 AC 35 ms
122,272 KB
testcase_06 AC 69 ms
251,176 KB
testcase_07 AC 54 ms
202,036 KB
testcase_08 AC 29 ms
105,876 KB
testcase_09 AC 4 ms
11,748 KB
testcase_10 AC 68 ms
253,224 KB
testcase_11 AC 48 ms
179,464 KB
testcase_12 AC 35 ms
128,308 KB
testcase_13 AC 69 ms
261,396 KB
testcase_14 AC 26 ms
95,524 KB
testcase_15 AC 40 ms
150,792 KB
testcase_16 AC 6 ms
20,040 KB
testcase_17 AC 33 ms
124,204 KB
testcase_18 AC 38 ms
140,552 KB
testcase_19 AC 6 ms
21,864 KB
testcase_20 AC 28 ms
101,676 KB
testcase_21 AC 79 ms
294,188 KB
testcase_22 AC 53 ms
197,924 KB
testcase_23 AC 76 ms
284,192 KB
testcase_24 AC 17 ms
62,832 KB
testcase_25 AC 51 ms
189,796 KB
testcase_26 AC 46 ms
171,476 KB
testcase_27 AC 47 ms
173,412 KB
testcase_28 AC 40 ms
150,888 KB
testcase_29 AC 78 ms
292,244 KB
testcase_30 AC 10 ms
34,192 KB
testcase_31 AC 34 ms
126,264 KB
testcase_32 AC 41 ms
154,920 KB
testcase_33 AC 36 ms
132,580 KB
testcase_34 AC 43 ms
161,360 KB
testcase_35 AC 43 ms
161,048 KB
testcase_36 AC 5 ms
17,756 KB
testcase_37 AC 33 ms
122,140 KB
testcase_38 AC 41 ms
152,944 KB
testcase_39 AC 38 ms
140,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

/*---------------------------------------------------------------
long long int kaizyo(long long int hh){
    cmp=1;
    while(hh>1){
        cmp=(cmp*hh)%MOD;
        hh--;
    }
    return cmp;
}
long long int ruizyo(long long int aa, long long int bb){
    if(aa==0){
        return 1;
    }
    else if(aa%2==0){
        long long int tt=ruizyo(aa/2,bb);
        return (tt*tt)%MOD;
    }
    else{
        return (ruizyo(aa-1,bb)*bb)%MOD;
    }
}フェルマ-のア
---------------------------------------------------------------

while(x!=0){
            sum+=x%10;
          / x/=10;
        }
        各桁の和
---------------------------------------------------------------

pair<int,int> p[100000];
cin >> tmp;
p[i]=make_pair(tmp,i);
cout << p[i].second+1 << endl;//ペアの右側つまりiを出力
---------------------------------------------------------------

s.find(w[i])==string::npos
findの使い方
---------------------------------------------------------------

for(int i=0;i<n;i++){
    b[i]=x%2;
    x/=2;
  }二進数
---------------------------------------------------------------

bool f[100001];//1000000以下の素数を調べよう!
rrep(i,2,100001){
       f[i]=false;
    }
rrep(i,2,100001){
        if(!f[i]){
            for(int j=i+i;j<=100000;j+=i){
                f[j]=true;
            }
        }
    }
    for(int i=3;i<=100000;i+=2){
        if(!f[i]){
            c[i]++;
        }
    }
---------------------------------------------------------------

visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに
---------------------------------------------------------------

long long gcd(long long aaa,long long bbb){
    if(bbb==0){
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}
 
long long lcm(long long aaa,long long bbb){
    long long g = gcd(aaa,bbb);
    return aaa/g * bbb;
}左から最大公約数と最小公倍数


---------------------------------------------------------------

long long int prime_cnt[10000];
       for(int i=2;i*i<=n;i++){
           while(n%i==0){
               n/=i;
               prime_cnt[i]+=1;
           }
           if(n>1){
               prime_cnt[n]+=1;
               break;
           }
      }ある数nを素因数分解しましょう
---------------------------------------------------------------*/

long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w[1000000],v[1000000],x,y,sum=0,pos,dp[101][1000002];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

       cin >> n;
       rep(i,n)cin>>v[i]>>w[i];
       cin>>a;
       rep(i,n){
          rep(j,100006){
              if(j>=w[i]){
                  dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
              }
              else{
                  dp[i+1][j]=dp[i][j];
              }
          }
       }
       ll ansmin=INF;
       ll ansmax=0;
       rep(i,100006){
           if(dp[n][i]==a){
               ansmin=min(ansmin,i);
               ansmax=max(ansmax,i);
           }
       }
       if(ansmin==0){
           Cout(1);
       }
       else{
       Cout(ansmin);
       }
       if(ansmax>=100000){
           Cout("inf");
       }
       else{
       Cout(ansmax);
       }
       
return 0;
}
0