제출 #127520

#제출 시각아이디문제언어결과실행 시간메모리
127520OptxPrimeKitchen (BOI19_kitchen)C++11
21 / 100
176 ms107964 KiB
#include <iostream> #include <cmath> #include<vector> #include <algorithm> #include <utility> #include<stack> #include<queue> #include<map> #include <fstream> using namespace std; #define pb push_back #define mp make_pair #define ll long long int inf=1000000000; int a[310],b[310]; int dp[310][91000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m,k; int mealsum=0,sum=0; bool is=true; cin>>n>>m>>k; for( int i=1;i<=n;i++ ) { cin>>a[i]; if( a[i] < k ){ is=false; // return 0; } mealsum+=a[i]; } for( int i=1;i<=m;i++ ){ cin>>b[i]; sum+=b[i]; } if(!is){ cout << "Impossible" <<endl; return 0; } sum = 305*505; for( int i=0;i<=m;i++ ){ for( int j=0;j<=sum;j++ ) dp[i][j]=-inf; } dp[0][0]=0; for( int i=1;i<=m;i++ ){ for( int j=1;j<=sum;j++ ){ if( j - b[i] >=0 ) dp[i][j] = max( dp[i-1][j], dp[i-1][ j - b[i] ] + min( n,b[i] ) ); else dp[i][j]=dp[i-1][j]; } } for( int i = mealsum;i<= sum;i++ ){ if( dp[m][i] >= n*k ){ cout << i - mealsum << endl; return 0; } } cout << "Impossible" <<endl; return 0; }

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

kitchen.cpp: In function 'int main()':
kitchen.cpp:48:43: warning: iteration 91000 invokes undefined behavior [-Waggressive-loop-optimizations]
         for( int j=0;j<=sum;j++ ) dp[i][j]=-inf;
                                   ~~~~~~~~^~~~~
kitchen.cpp:48:23: note: within this loop
         for( int j=0;j<=sum;j++ ) dp[i][j]=-inf;
                      ~^~~~~
cc1plus: warning: iteration 90999 invokes undefined behavior [-Waggressive-loop-optimizations]
kitchen.cpp:52:23: note: within this loop
         for( int j=1;j<=sum;j++ ){
                      ~^~~~~
#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...