제출 #678151

#제출 시각아이디문제언어결과실행 시간메모리
678151Tien_NoobKnapsack (NOI18_knapsack)C++17
100 / 100
72 ms4136 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5, M = 2e3; vector<int> keep[M + 1]; int v[N + 1], w[N + 1], k[N + 1], id[N + 1], s, n; long long dp[N + 1]; void read() { cin >> s >> n; for (int i = 1; i <= n; ++ i) { cin >> v[i] >> w[i] >> k[i]; id[i] = i; } sort(id + 1, id + n + 1, [&](const int &x, const int &y) { return v[x] > v[y]; }); } void solve() { for (int j = 1; j <= n; ++ j) { int i = id[j]; while(k[i]--) { if (keep[w[i]].size() == s/w[i]) { break; } keep[w[i]].push_back(v[i]); } } for (int i = 1; i <= s; ++ i) { if (keep[i].empty()) { continue; } for (int j = s; j >= 0; -- j) { int x = j; long long sum = 0; for (int l : keep[i]) { x += i; sum += l; if (x > s) { break; } dp[x] = max(dp[x], dp[j] + sum); } } for (int j = 1; j <= s; ++ j) { dp[j] = max(dp[j], dp[j - 1]); } } cout << dp[s]; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:31:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |             if (keep[w[i]].size() == s/w[i])
      |                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         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...