제출 #427933

#제출 시각아이디문제언어결과실행 시간메모리
427933AmylopectinKnapsack (NOI18_knapsack)C++14
100 / 100
679 ms2500 KiB
#include <iostream> #include <stdio.h> using namespace std; const int mxn = 1e5 + 10; long long ta[mxn] = {},nru[mxn] = {},chc[mxn] = {}; long long fima(long long l,long long r) { if(l > r) return l; return r; } int main() { long long i,j,n,m,cva,cwe,cco,cma = 0,k; scanf("%lld %lld",&m,&n); for(i=0; i<n; i++) { scanf("%lld %lld %lld",&cva,&cwe,&cco); for(j=0; j<cwe; j++) { nru[j] = ta[j]; } for(j=cwe; j<=m; j++) { if(chc[j-cwe] == cco) { // nru[j] = fima(ta[j-(cco * cwe)] + (cco * cva), ta[j]); nru[j] = ta[j]; for(k=1; k<=cco; k++) { if(ta[j-(k*cwe)] + (k*cva) > nru[j]) { nru[j] = ta[j-(k*cwe)] + (k*cva); chc[j] = k; } } // if(ta[j-(cco * cwe)] + (cco * cva) > ta[j]) // { // nru[j] = ta[j-(cco * cwe)] + (cco * cva); // chc[j] = cco; // } // else // { // nru[j] = ta[j]; // } // chc[j] = cco; } else { // nru[j] = fima(, ta[j]); if(nru[j-cwe] + cva > ta[j]) { // if(j-cwe < cwe) // { // nru[j] = ta[j-cwe] + cva; // } // else // { nru[j] = nru[j-cwe] + cva; // } chc[j] = chc[j-cwe] + 1; } else { nru[j] = ta[j]; } } } for(j=cwe; j<=m; j++) { chc[j] = 0; ta[j] = fima(nru[j],ta[j]); nru[j] = 0; } } for(i=0; i<=m; i++) { cma = fima(cma,ta[i]); } printf("%lld\n",cma); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%lld %lld",&m,&n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
knapsack.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%lld %lld %lld",&cva,&cwe,&cco);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...