이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
const int mxN = 1e5+10;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
vector<vector<int>> items;
int S,N;
ll dp[100000][2000];
ll f(int i,int tot){
if(tot<0) return -INF;
if(i<0) return 0;
if(dp[i][tot]!=-1) return dp[i][tot];
ll ans=-INF,cnt=0;
while(cnt<=items[i][2]&&tot-items[i][1]*cnt>=0){
ans=max(ans,f(i-1,tot-items[i][1]*cnt)+items[i][0]*cnt);
++cnt;
}
return dp[i][tot]=ans;
}
void solve(ll tc) {
int p,w,c;cin>>S>>N;
// price,weight,copy
for(ll i=0;i<N;++i){
cin>>p>>w>>c;
items.pb({p,w,c});
}
memset(dp,-1,sizeof(dp));
show(f(N-1,S));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve(0);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp:28:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
28 | #pragma GCC optimize("-fwhole-program")
| ^
knapsack.cpp:35:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
35 | #pragma GCC optimize("-fstrict-overflow")
| ^
knapsack.cpp:37:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
37 | #pragma GCC optimize("-fcse-skip-blocks")
| ^
knapsack.cpp:51:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
51 | #pragma GCC optimize("-funsafe-loop-optimizations")
| ^
knapsack.cpp:81:19: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
81 | ll f(int i,int tot){
| ^
knapsack.cpp:81:19: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
knapsack.cpp:81:19: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
knapsack.cpp:81:19: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
knapsack.cpp:94:17: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
94 | void solve(ll tc) {
| ^
knapsack.cpp:94:17: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
knapsack.cpp:94:17: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
knapsack.cpp:94:17: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
knapsack.cpp:105:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
105 | int main() {
| ^
knapsack.cpp:105:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
knapsack.cpp:105:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
knapsack.cpp:105:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |