제출 #1188444

#제출 시각아이디문제언어결과실행 시간메모리
1188444teokakabadzeKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms448 KiB
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define int long long
#define pii pair<int, int>
using namespace std;

const int N = 5e5 + 5, M = 1e9 + 7;
int T, n, s, dp[2003], dp1[2003];

main()
{
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> s >> n;
    int i, j, st;
    for(i = 0; i < n; i++)
    {
        int v, w, k;
        cin >> v >> w >> k;
        for(st = s; st > max(-1ll, s - w); st--)
        {
            int cnt = 0, r = st, l = st, p = 0, c = 0;
            deque<int> d;
            while(r >= 0)
            {
                c = (st - l) / w;
                if(l >= 0)
                {
                    while(d.size() && d.back() < dp[l] + c * v)
                    d.pop_back();
                    d.push_back(dp[l] + c * v);
                    dp1[l] = dp[l] + c * v;
                    cnt++;
                }
                if(cnt == k + 1 || l < 0) 
                {
                    if(d.size()) dp[r] = max(dp[r], d.front() - p * v);
                    if(d.front() == dp1[r]) d.pop_front(); 
                    r -= w;
                    cnt--;
                    p++;
                }
                if(l >= 0) l -= w;
            }
        }
    }
    cout << dp[s] << '\n';
}

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

knapsack.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
#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...