제출 #1096025

#제출 시각아이디문제언어결과실행 시간메모리
1096025InvMODKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define siz(v) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 2e1+5; const ll MOD = 1e9+7; const ll INF = 1e18; int S, n; ll dp[N]; void process(ll &v, ll &w){ if(w > S) return; for(int i = S; i >= w; i--){ ckmx(dp[i], dp[i-w] + v); } return; } void solve() { cin >> S >> n; for(int i = 1; i <= n; i++){ ll v,w,k; cin >> v >> w >> k; for(int j = 0; j < (32 - __builtin_clz(k)); j++){ if(k >= (1<<j)){ k -= (1<<j); process(v * (1ll<<j), w * (1ll<<j)); } } if(k){ process(v * k, w * k); } } cout << *max_element(dp, dp+1+S) <<"\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:47:27: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to an rvalue of type 'll' {aka 'long long int'}
   47 |                 process(v * (1ll<<j), w * (1ll<<j));
      |                         ~~^~~~~~~~~~
knapsack.cpp:30:18: note:   initializing argument 1 of 'void process(ll&, ll&)'
   30 | void process(ll &v, ll &w){
      |              ~~~~^
knapsack.cpp:51:23: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to an rvalue of type 'll' {aka 'long long int'}
   51 |             process(v * k, w * k);
      |                     ~~^~~
knapsack.cpp:30:18: note:   initializing argument 1 of 'void process(ll&, ll&)'
   30 | void process(ll &v, ll &w){
      |              ~~~~^
knapsack.cpp: In function 'int main()':
knapsack.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~