제출 #438578

#제출 시각아이디문제언어결과실행 시간메모리
438578HaidaraKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms716 KiB
/* * * * * * * * * * * ID: Haidara * * LANG: C++17 * * PROB: * * * * * * * * * * */ #include<bits/stdc++.h> #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define rep(i,x,n) for(int i=x;i<n;i++) #define FOR(i,n) rep(i,0,n) #define per(i,x,n) for(int i=x;i>n;i--) #define ROF(i,x) for(int i=x;i>=0;i--) #define v(i) vector< i > #define p(i,j) pair< i , j > #define pii pair<int,int> #define m(i,j) map< i , j > #define pq(i) priority_queue< i > #define ff first #define all(x) x.begin(),x.end() #define ss second #define pp push_back using namespace std; const int inf=1LL<<62LL; const int mod=1e9+7; const int maxn=100001; int s,n,v[maxn],w[maxn],k[maxn],dp[maxn][2001]; int solve(int inx=0,int curr=0) { if(dp[inx][curr]) return dp[inx][curr]; if(inx==n) return 0; FOR(i,k[inx]) { if(curr+i*w[inx]<=s) dp[inx][curr]=max(dp[inx][curr],solve(inx+1,curr+i*w[inx])+i*v[i]); else break; } return dp[inx][curr]; } signed main() { cin>>s>>n; FOR(i,n) { cin>>v[i]>>w[i]>>k[i]; k[i]=min(k[i],s); } cout<<solve(); }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp:22:18: warning: overflow in conversion from 'long long int' to 'int' changes value from '4611686018427387904' to '0' [-Woverflow]
   22 | const int inf=1LL<<62LL;
      |               ~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...