제출 #880223

#제출 시각아이디문제언어결과실행 시간메모리
880223cpptowinKnapsack (NOI18_knapsack)C++17
29 / 100
1 ms616 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 5010
#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];
    }
}

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();
}

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

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