제출 #1103861

#제출 시각아이디문제언어결과실행 시간메모리
1103861FernandoJC07Knapsack (NOI18_knapsack)C++14
17 / 100
453 ms64072 KiB
#include <iostream> #include <math.h> #include <string> #include <sstream> #include <algorithm> #include <vector> #include <utility> #include <stdio.h> #include <unordered_map> #include <cstring> #define Kaspárov main using namespace std; #pragma GCC optimize("Ofast,unroll-loops") //\\ PRINCIPAL \\// #define int long long #define ull unsigned long long #define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); //srand(time(NULL)); //\\ VECTOR \\// #define pb push_back #define ff first #define ss second #define pb push_back #define all(x) (x).begin(), (x).end() #define lb lower_bound #define ordenar(x) sort( x.begin(), x.end() ) #define ordenarA(x,n) sort( x, x + n ) //\\ OPERACIONES RAPIDAS \\// #define sf(n) scanf("%d", &n) #define sff(n,m) scanf("%d%d",&n,&m) #define sfl(n) scanf("%lld", &n) #define sffl(n,m) scanf("%lld%lld",&n,&m) #define pf(n) printf("%d\n",n) #define pfl(n) printf("%lld ",n) #define pfs(s) printf("%s\n",s) const int MAXN = 2e6+5, mod = 1e9+7; void solve(); int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout); } void solve(){ int s, n; cin>>s>>n; int dp[MAXN+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[MAXN]; for(int j = 0; j<=MAXN; ++j) pm[j] = dp[j]; for(int j = 0; j<=MAXN; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; ///if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); ///cout<<lugar<<" "<<pm[lugar]<<endl; } } } ///cout<<endl; for(int j = 0; j<=MAXN; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x = 1; x<=s; ++x) maxn = max(maxn, dp[x]); cout<<maxn; } /* 15 5 4 12 1 2 1 1 10 4 1 1 1 1 2 2 1 */

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:67:15: warning: iteration 2000005 invokes undefined behavior [-Waggressive-loop-optimizations]
   67 |         pm[j] = dp[j];
      |         ~~~~~~^~~~~~~
knapsack.cpp:66:25: note: within this loop
   66 |         for(int j = 0; j<=MAXN; ++j)
      |                        ~^~~~~~
knapsack.cpp:84:22: warning: iteration 2000005 invokes undefined behavior [-Waggressive-loop-optimizations]
   84 |          dp[j] = pm[j];
      |                  ~~~~^
knapsack.cpp:83:26: note: within this loop
   83 |          for(int j = 0; j<=MAXN; ++j)
      |                         ~^~~~~~
knapsack.cpp:67:15: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset [16000040, 16000047] is out of the bounds [0, 16000040] of object 'pm' with type 'long long int [2000005]' [-Warray-bounds]
   67 |         pm[j] = dp[j];
      |         ~~~~~~^~~~~~~
knapsack.cpp:65:13: note: 'pm' declared here
   65 |         int pm[MAXN];
      |             ^~
knapsack.cpp:84:16: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset [16000040, 16000047] is out of the bounds [0, 16000040] of object 'pm' with type 'long long int [2000005]' [-Warray-bounds]
   84 |          dp[j] = pm[j];
      |          ~~~~~~^~~~~~~
knapsack.cpp:65:13: note: 'pm' declared here
   65 |         int pm[MAXN];
      |             ^~
#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...