답안 #1030523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030523 2024-07-22T06:23:57 Z vjudge1 Knapsack (NOI18_knapsack) C++17
100 / 100
56 ms 41112 KB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;
using aa = array<int,3>;

const int N = 1e6+5;
const int INF = 1e9;

ll dp[2005][2005];
vector<ii> m[2005];
int pre[2005][2005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,s;
    cin >> s >> n;
    for(int i=1;i<=s;i++) {
        for(int j=1;j<=s;j++) dp[i][j]=0;
    }
    for(int i=1;i<=n;i++) {
        int v,w,k;
        cin >> v >> w >> k;
        m[w].push_back({v,k});
    }
    for(int i=1;i<=s;i++) {
        sort(m[i].begin(),m[i].end(),greater<>());
    }
    for(int i=1;i<=s;i++) {
        int cur=0;
        for(ii x:m[i]) {
            int t=cur;
            cur+=x.second;
            cur=min(cur,s/i);
            for(int j=t+1;j<=cur;j++) {
                pre[i][j]=pre[i][j-1]+x.first;
            }
            if(cur>=s/i) break;
        }
    }
    ll ans=0;
    for(int i=1;i<=s;i++) {
        for(ll j=1;j<=s;j++) {
            for(int k=1;i*k<=j;k++) {
                dp[i][j]=max(dp[i][j],dp[i-1][j-i*k]+pre[i][k]);
                ans=max(ans,dp[i][j]);
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            //cout << dp[i][j] << ' ';
        }
        //cout << endl;
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17244 KB Output is correct
2 Correct 13 ms 17244 KB Output is correct
3 Correct 14 ms 17244 KB Output is correct
4 Correct 13 ms 17244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 30 ms 31732 KB Output is correct
3 Correct 30 ms 31836 KB Output is correct
4 Correct 31 ms 31836 KB Output is correct
5 Correct 28 ms 32088 KB Output is correct
6 Correct 29 ms 32092 KB Output is correct
7 Correct 30 ms 32088 KB Output is correct
8 Correct 30 ms 32088 KB Output is correct
9 Correct 30 ms 32092 KB Output is correct
10 Correct 29 ms 32092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 30 ms 31732 KB Output is correct
3 Correct 30 ms 31836 KB Output is correct
4 Correct 31 ms 31836 KB Output is correct
5 Correct 28 ms 32088 KB Output is correct
6 Correct 29 ms 32092 KB Output is correct
7 Correct 30 ms 32088 KB Output is correct
8 Correct 30 ms 32088 KB Output is correct
9 Correct 30 ms 32092 KB Output is correct
10 Correct 29 ms 32092 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 30 ms 31832 KB Output is correct
13 Correct 31 ms 31832 KB Output is correct
14 Correct 30 ms 31836 KB Output is correct
15 Correct 30 ms 31860 KB Output is correct
16 Correct 30 ms 32092 KB Output is correct
17 Correct 30 ms 32092 KB Output is correct
18 Correct 31 ms 32092 KB Output is correct
19 Correct 32 ms 32092 KB Output is correct
20 Correct 32 ms 32092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17244 KB Output is correct
2 Correct 13 ms 17244 KB Output is correct
3 Correct 14 ms 17244 KB Output is correct
4 Correct 13 ms 17244 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 30 ms 31732 KB Output is correct
7 Correct 30 ms 31836 KB Output is correct
8 Correct 31 ms 31836 KB Output is correct
9 Correct 28 ms 32088 KB Output is correct
10 Correct 29 ms 32092 KB Output is correct
11 Correct 30 ms 32088 KB Output is correct
12 Correct 30 ms 32088 KB Output is correct
13 Correct 30 ms 32092 KB Output is correct
14 Correct 29 ms 32092 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 30 ms 31832 KB Output is correct
17 Correct 31 ms 31832 KB Output is correct
18 Correct 30 ms 31836 KB Output is correct
19 Correct 30 ms 31860 KB Output is correct
20 Correct 30 ms 32092 KB Output is correct
21 Correct 30 ms 32092 KB Output is correct
22 Correct 31 ms 32092 KB Output is correct
23 Correct 32 ms 32092 KB Output is correct
24 Correct 32 ms 32092 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 30 ms 31884 KB Output is correct
27 Correct 30 ms 31908 KB Output is correct
28 Correct 30 ms 31836 KB Output is correct
29 Correct 30 ms 31704 KB Output is correct
30 Correct 31 ms 32092 KB Output is correct
31 Correct 30 ms 32088 KB Output is correct
32 Correct 31 ms 32256 KB Output is correct
33 Correct 30 ms 32092 KB Output is correct
34 Correct 30 ms 32188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17244 KB Output is correct
2 Correct 13 ms 17244 KB Output is correct
3 Correct 14 ms 17244 KB Output is correct
4 Correct 13 ms 17244 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 30 ms 31732 KB Output is correct
7 Correct 30 ms 31836 KB Output is correct
8 Correct 31 ms 31836 KB Output is correct
9 Correct 28 ms 32088 KB Output is correct
10 Correct 29 ms 32092 KB Output is correct
11 Correct 30 ms 32088 KB Output is correct
12 Correct 30 ms 32088 KB Output is correct
13 Correct 30 ms 32092 KB Output is correct
14 Correct 29 ms 32092 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 30 ms 31832 KB Output is correct
17 Correct 31 ms 31832 KB Output is correct
18 Correct 30 ms 31836 KB Output is correct
19 Correct 30 ms 31860 KB Output is correct
20 Correct 30 ms 32092 KB Output is correct
21 Correct 30 ms 32092 KB Output is correct
22 Correct 31 ms 32092 KB Output is correct
23 Correct 32 ms 32092 KB Output is correct
24 Correct 32 ms 32092 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 30 ms 31884 KB Output is correct
27 Correct 30 ms 31908 KB Output is correct
28 Correct 30 ms 31836 KB Output is correct
29 Correct 30 ms 31704 KB Output is correct
30 Correct 31 ms 32092 KB Output is correct
31 Correct 30 ms 32088 KB Output is correct
32 Correct 31 ms 32256 KB Output is correct
33 Correct 30 ms 32092 KB Output is correct
34 Correct 30 ms 32188 KB Output is correct
35 Correct 19 ms 1496 KB Output is correct
36 Correct 50 ms 32912 KB Output is correct
37 Correct 43 ms 32984 KB Output is correct
38 Correct 49 ms 32976 KB Output is correct
39 Correct 51 ms 32772 KB Output is correct
40 Correct 53 ms 40880 KB Output is correct
41 Correct 49 ms 41052 KB Output is correct
42 Correct 51 ms 41112 KB Output is correct
43 Correct 49 ms 41044 KB Output is correct
44 Correct 54 ms 41064 KB Output is correct
45 Correct 55 ms 33872 KB Output is correct
46 Correct 53 ms 32988 KB Output is correct
47 Correct 50 ms 34652 KB Output is correct
48 Correct 51 ms 36952 KB Output is correct
49 Correct 49 ms 33336 KB Output is correct
50 Correct 56 ms 33104 KB Output is correct