Submission #880226

#TimeUsernameProblemLanguageResultExecution timeMemory
880226cpptowinKnapsack (NOI18_knapsack)C++17
29 / 100
2 ms360 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 1000010 #define N 2010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; #define int long long #define inf 1000000000 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1) #define offbit(i,j) (i^(1<<j)) #define onbit(i,j) (i|(1<<j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} using namespace std; struct things { int v,w,k; }a[maxn]; int n,s; namespace sub1 { void solve() { cout << min(s / a[1].w,a[1].k) * a[1].v; } } namespace sub2 { int dp[N]; void solve() { fo(i,1,n) { fod(j,s,1) if(j >= a[i].w) dp[j] = max(dp[j],dp[j - a[i].w] + a[i].v); } cout << dp[s]; } } namespace sub3 { int dp[N]; vector<things> arr; void solve() { fo(i,1,n) { fo(j,1,a[i].k) arr.push_back({a[i].v,a[i].w,1}); } for(auto [v,w,k] : arr) { fod(j,s,1) if(j >= w) dp[j] = max(dp[j],dp[j - w] + v); } cout << dp[s]; } } main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> s >> n; fo(i,1,n) cin >> a[i].v >> a[i].w >> a[i].k; if(n == 1) sub1::solve(); else if(n <= 100 and a[1].k == 1) sub2::solve(); else if(n <= 100 and a[1].k > 1) sub3::solve(); }

Compilation message (stderr)

knapsack.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main()
      | ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:70:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:71:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...