제출 #1192812

#제출 시각아이디문제언어결과실행 시간메모리
1192812GoBananas69Knapsack (NOI18_knapsack)C++20
73 / 100
1093 ms16244 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; void fastscan(int &number) { bool negative = false; register int c; number = 0; c = getchar(); if (c == '-') { negative = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; if (negative) number *= -1; } int main() { cin.tie(0)->sync_with_stdio(0); int s, n; fastscan(s); fastscan(n); if (s < 0 || n <= 0) { cout << 0 << '\n'; return 0; } vector<ll> v(1, 0), w(1, 0); for (int i = 0; i < n; ++i) { int price, weight, count; fastscan(price); fastscan(weight); fastscan(count); int y = s / weight; count = min(y, count); int k = 1; while (k <= count) { w.push_back(weight * k); v.push_back(price * k); count -= k; k *= 2; } if (count > 0) { w.push_back(weight * count); v.push_back(price * count); } } n = v.size() - 1; if (n == 0) { cout << 0 << '\n'; return 0; } vector<vector<ll>> dp(2, vector<ll>(s + 1, 0)); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= s; ++j) { if (w[i] > j) { dp[1][j] = dp[0][j]; } else { dp[1][j] = max(dp[0][j], v[i] + dp[0][j - w[i]]); } } swap(dp[1], dp[0]); } cout << dp[0][s] << '\n'; }

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

knapsack.cpp: In function 'void fastscan(int&)':
knapsack.cpp:9:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 |     register int c;
      |                  ^
#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...