답안 #25556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25556 2017-06-23T04:45:23 Z tlwpdus 스트랩 (JOI14_straps) C++
100 / 100
46 ms 85708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll knap[2100][5100], INF = 1LL<<50;
int n, bia = 2010;
int a[2100], b[2100];

int main() {
    int i, j, k;

    //freopen("input","r",stdin);

    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    for (i=1;i<=n;i++) a[i]--;
    for (j=0;j<5100;j++) knap[0][j] = -INF;
    knap[0][bia] = 0;
    ll res = 0;
    for (i=1;i<=n;i++) {
        for (j=0;j<=n+bia+1;j++) {
            knap[i][j] = knap[i-1][j];
            if (j==n+bia+1) {
                knap[i][j] = max(knap[i][j],knap[i-1][j]+b[i]);
                for (k=j-a[i];k<=n+bia;k++) knap[i][j] = max(knap[i][j],knap[i-1][k]+b[i]);
            }
            else if (j-a[i]>=0&&j-a[i]<=n+bia) knap[i][j] = max(knap[i][j],knap[i-1][j-a[i]]+b[i]);
            if (i==n&&j-bia>=-1) res = max(res,knap[i][j]);
        }
    }
    printf("%lld\n",res);

    return 0;
}

Compilation message

straps.cpp: In function 'int main()':
straps.cpp:16:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
straps.cpp:17:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
                                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 85708 KB Output is correct
2 Correct 0 ms 85708 KB Output is correct
3 Correct 0 ms 85708 KB Output is correct
4 Correct 0 ms 85708 KB Output is correct
5 Correct 0 ms 85708 KB Output is correct
6 Correct 0 ms 85708 KB Output is correct
7 Correct 0 ms 85708 KB Output is correct
8 Correct 0 ms 85708 KB Output is correct
9 Correct 0 ms 85708 KB Output is correct
10 Correct 0 ms 85708 KB Output is correct
11 Correct 0 ms 85708 KB Output is correct
12 Correct 0 ms 85708 KB Output is correct
13 Correct 0 ms 85708 KB Output is correct
14 Correct 0 ms 85708 KB Output is correct
15 Correct 0 ms 85708 KB Output is correct
16 Correct 0 ms 85708 KB Output is correct
17 Correct 0 ms 85708 KB Output is correct
18 Correct 0 ms 85708 KB Output is correct
19 Correct 0 ms 85708 KB Output is correct
20 Correct 0 ms 85708 KB Output is correct
21 Correct 0 ms 85708 KB Output is correct
22 Correct 0 ms 85708 KB Output is correct
23 Correct 0 ms 85708 KB Output is correct
24 Correct 0 ms 85708 KB Output is correct
25 Correct 0 ms 85708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 85708 KB Output is correct
2 Correct 0 ms 85708 KB Output is correct
3 Correct 0 ms 85708 KB Output is correct
4 Correct 0 ms 85708 KB Output is correct
5 Correct 0 ms 85708 KB Output is correct
6 Correct 0 ms 85708 KB Output is correct
7 Correct 0 ms 85708 KB Output is correct
8 Correct 9 ms 85708 KB Output is correct
9 Correct 9 ms 85708 KB Output is correct
10 Correct 6 ms 85708 KB Output is correct
11 Correct 9 ms 85708 KB Output is correct
12 Correct 29 ms 85708 KB Output is correct
13 Correct 36 ms 85708 KB Output is correct
14 Correct 23 ms 85708 KB Output is correct
15 Correct 29 ms 85708 KB Output is correct
16 Correct 23 ms 85708 KB Output is correct
17 Correct 33 ms 85708 KB Output is correct
18 Correct 16 ms 85708 KB Output is correct
19 Correct 23 ms 85708 KB Output is correct
20 Correct 23 ms 85708 KB Output is correct
21 Correct 43 ms 85708 KB Output is correct
22 Correct 26 ms 85708 KB Output is correct
23 Correct 19 ms 85708 KB Output is correct
24 Correct 26 ms 85708 KB Output is correct
25 Correct 26 ms 85708 KB Output is correct
26 Correct 36 ms 85708 KB Output is correct
27 Correct 29 ms 85708 KB Output is correct
28 Correct 26 ms 85708 KB Output is correct
29 Correct 29 ms 85708 KB Output is correct
30 Correct 19 ms 85708 KB Output is correct
31 Correct 33 ms 85708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 85708 KB Output is correct
2 Correct 0 ms 85708 KB Output is correct
3 Correct 0 ms 85708 KB Output is correct
4 Correct 0 ms 85708 KB Output is correct
5 Correct 0 ms 85708 KB Output is correct
6 Correct 0 ms 85708 KB Output is correct
7 Correct 0 ms 85708 KB Output is correct
8 Correct 0 ms 85708 KB Output is correct
9 Correct 9 ms 85708 KB Output is correct
10 Correct 9 ms 85708 KB Output is correct
11 Correct 19 ms 85708 KB Output is correct
12 Correct 23 ms 85708 KB Output is correct
13 Correct 6 ms 85708 KB Output is correct
14 Correct 3 ms 85708 KB Output is correct
15 Correct 6 ms 85708 KB Output is correct
16 Correct 6 ms 85708 KB Output is correct
17 Correct 29 ms 85708 KB Output is correct
18 Correct 23 ms 85708 KB Output is correct
19 Correct 43 ms 85708 KB Output is correct
20 Correct 16 ms 85708 KB Output is correct
21 Correct 33 ms 85708 KB Output is correct
22 Correct 33 ms 85708 KB Output is correct
23 Correct 26 ms 85708 KB Output is correct
24 Correct 19 ms 85708 KB Output is correct
25 Correct 26 ms 85708 KB Output is correct
26 Correct 19 ms 85708 KB Output is correct
27 Correct 33 ms 85708 KB Output is correct
28 Correct 39 ms 85708 KB Output is correct
29 Correct 26 ms 85708 KB Output is correct
30 Correct 29 ms 85708 KB Output is correct
31 Correct 16 ms 85708 KB Output is correct
32 Correct 26 ms 85708 KB Output is correct
33 Correct 33 ms 85708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 85708 KB Output is correct
2 Correct 16 ms 85708 KB Output is correct
3 Correct 29 ms 85708 KB Output is correct
4 Correct 33 ms 85708 KB Output is correct
5 Correct 23 ms 85708 KB Output is correct
6 Correct 16 ms 85708 KB Output is correct
7 Correct 19 ms 85708 KB Output is correct
8 Correct 16 ms 85708 KB Output is correct
9 Correct 19 ms 85708 KB Output is correct
10 Correct 39 ms 85708 KB Output is correct
11 Correct 19 ms 85708 KB Output is correct
12 Correct 23 ms 85708 KB Output is correct
13 Correct 36 ms 85708 KB Output is correct
14 Correct 33 ms 85708 KB Output is correct
15 Correct 19 ms 85708 KB Output is correct
16 Correct 19 ms 85708 KB Output is correct
17 Correct 29 ms 85708 KB Output is correct
18 Correct 26 ms 85708 KB Output is correct
19 Correct 26 ms 85708 KB Output is correct
20 Correct 46 ms 85708 KB Output is correct
21 Correct 13 ms 85708 KB Output is correct
22 Correct 26 ms 85708 KB Output is correct
23 Correct 23 ms 85708 KB Output is correct
24 Correct 39 ms 85708 KB Output is correct
25 Correct 19 ms 85708 KB Output is correct