제출 #448342

#제출 시각아이디문제언어결과실행 시간메모리
448342mnair797Knapsack (NOI18_knapsack)C++14
100 / 100
75 ms7252 KiB
#include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define pb push_back #define mp make_pair #define fi first #define se second #define N 100005 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" #define int long long using namespace std; typedef long double ld; const int inf = 1e10; const int minf = -1e10; int s, n; int v[N], w[N], k[N]; void readfile() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); if (fopen(Task".inp","r")) { freopen(Task".inp","r",stdin); //freopen(Task".out","w",stdout); } cin >> s >> n; for(int i=1; i<=n; i++) cin >> v[i] >> w[i] >> k[i]; } void proc() { vector<int> dp(s+1,0); vector<ii> obj[s+1]; for(int i=1; i<=n; i++) obj[w[i]].pb(ii(v[i],k[i])); for(int i=0; i<=s; i++){ if (obj[i].size()==0) continue; sort(obj[i].begin(),obj[i].end(),greater<ii>()); int id = 0; for(int j=0; j*i < s; j++){ if (id >= obj[i].size()) break; for(int k=s; k>=i; k--){ dp[k] = max(dp[k], dp[k-i] + obj[i][id].fi); } obj[i][id].se--; if (obj[i][id].se==0) id++; } } cout << dp[s]; } signed main() { readfile(); proc(); return 0; }

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

knapsack.cpp: In function 'void proc()':
knapsack.cpp:52:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             if (id >= obj[i].size()) break;
      |                 ~~~^~~~~~~~~~~~~~~~
knapsack.cpp: In function 'void readfile()':
knapsack.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...