Submission #490672

# Submission time Handle Problem Language Result Execution time Memory
490672 2021-11-28T13:26:15 Z CyberSleeper Knapsack (NOI18_knapsack) C++14
0 / 100
8 ms 2680 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ld          long double
#define pii         pair<int, int>
#define pll         pair<ll, ll>
#define ar3         array<int, 3>
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
using namespace std;

const int MX=100005, MOD=1e9+7, BLOCK=500, INF=2e9+7;
const ll INFF=1e18+7;
const ld ERR=1e-7, pi=3.14159265358979323846;

int S, N, DP[2][2005];
vector<pii> A[MX];

int main(){
    fastio;
    cin >> S >> N;
    for(int i=1, v, w, k; i<=N; i++){
        cin >> v >> w >> k;
        A[w].pb({v, k});
    }
    for(int i=1; i<=S; i++)
        DP[0][i]=-INF;
    DP[0][0]=0;
    for(int i=1; i<=S; i++){
        sort(A[i].begin(), A[i].end(), greater<pii>());
        int now=i%2, bef=now^1;
        for(int j=1; j<=S; j++)
            DP[now][j]=-INF;
        DP[now][0]=0;
        for(int j=0; j<=S; j++){
            int skor=DP[bef][j], idx=0, used=0, slot=j;
            while((idx<A[i].size()) && slot<=S){
                skor+=A[i][idx].fi;
                slot+=i;
                DP[now][slot]=max(DP[now][slot], skor);
                used++;
                if(used>=A[i][idx].se){
                    idx++;
                    used=0;
                }
            }
            DP[now][j]=max(DP[bef][j], DP[now][j]);
        }
    }
    N%=2;
    for(int i=0; i<S; i++)
        DP[S%2][S]=max(DP[S%2][S], DP[S%2][i]);
    cout << DP[S%2][S] << nl;
}

Compilation message

knapsack.cpp: In function 'int main()':
knapsack.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             while((idx<A[i].size()) && slot<=S){
      |                    ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2648 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Correct 4 ms 2636 KB Output is correct
4 Incorrect 4 ms 2636 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 8 ms 2636 KB Output is correct
3 Correct 8 ms 2680 KB Output is correct
4 Incorrect 8 ms 2636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 8 ms 2636 KB Output is correct
3 Correct 8 ms 2680 KB Output is correct
4 Incorrect 8 ms 2636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2648 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Correct 4 ms 2636 KB Output is correct
4 Incorrect 4 ms 2636 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2648 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Correct 4 ms 2636 KB Output is correct
4 Incorrect 4 ms 2636 KB Output isn't correct