답안 #46856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46856 2018-04-24T01:43:29 Z ffresh 스트랩 (JOI14_straps) C++17
100 / 100
13 ms 760 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 2005,inf = -2e9-150;

int dp[N];

pair<int,int> inp[N];
int main(){
    //freopen("input.txt","r",stdin);

    int n;
    scanf("%d",&n);

    int a,b,ret=0;
    
    for(int i=0;i<N;++i)dp[i]= inf;
    dp[1]= 0;
    
    for(int i=0;i<n;++i){
        scanf("%d%d",&inp[i].first,&inp[i].second);
    }
    sort(inp,inp+n,greater<pair<int,int> >());

    for(int i=0;i<n;++i){
        int x = inp[i].first-1, y = inp[i].second;

        if(x<0){
            for(int j=1;j<=n;++j)
                if(dp[j]!=inf)dp[j-1]= max(dp[j-1],dp[j]+y);
        }
        else{
            for(int j=n;j>=1;--j){
                int nj = min(n,j+x);
                if(dp[j]!=inf)
                    dp[nj]= max(dp[nj], dp[j] + y);
            }
        }
    }

    for(int i=0;i<=n;++i)ret= max(ret,dp[i]);
    printf("%d\n",ret);
    return 0;
}

Compilation message

straps.cpp: In function 'int main()':
straps.cpp:18:9: warning: unused variable 'a' [-Wunused-variable]
     int a,b,ret=0;
         ^
straps.cpp:18:11: warning: unused variable 'b' [-Wunused-variable]
     int a,b,ret=0;
           ^
straps.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
straps.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&inp[i].first,&inp[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 244 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 2 ms 740 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
13 Correct 2 ms 740 KB Output is correct
14 Correct 2 ms 740 KB Output is correct
15 Correct 2 ms 740 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 2 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 740 KB Output is correct
2 Correct 2 ms 740 KB Output is correct
3 Correct 2 ms 740 KB Output is correct
4 Correct 2 ms 740 KB Output is correct
5 Correct 2 ms 740 KB Output is correct
6 Correct 2 ms 740 KB Output is correct
7 Correct 2 ms 740 KB Output is correct
8 Correct 3 ms 740 KB Output is correct
9 Correct 3 ms 740 KB Output is correct
10 Correct 3 ms 740 KB Output is correct
11 Correct 3 ms 740 KB Output is correct
12 Correct 6 ms 740 KB Output is correct
13 Correct 6 ms 740 KB Output is correct
14 Correct 6 ms 740 KB Output is correct
15 Correct 6 ms 740 KB Output is correct
16 Correct 7 ms 740 KB Output is correct
17 Correct 7 ms 740 KB Output is correct
18 Correct 7 ms 740 KB Output is correct
19 Correct 6 ms 740 KB Output is correct
20 Correct 6 ms 740 KB Output is correct
21 Correct 7 ms 740 KB Output is correct
22 Correct 6 ms 752 KB Output is correct
23 Correct 7 ms 752 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 7 ms 752 KB Output is correct
26 Correct 7 ms 752 KB Output is correct
27 Correct 7 ms 752 KB Output is correct
28 Correct 7 ms 752 KB Output is correct
29 Correct 13 ms 752 KB Output is correct
30 Correct 12 ms 752 KB Output is correct
31 Correct 9 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 752 KB Output is correct
2 Correct 2 ms 752 KB Output is correct
3 Correct 2 ms 752 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 2 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 4 ms 752 KB Output is correct
10 Correct 3 ms 752 KB Output is correct
11 Correct 3 ms 752 KB Output is correct
12 Correct 3 ms 752 KB Output is correct
13 Correct 3 ms 752 KB Output is correct
14 Correct 3 ms 752 KB Output is correct
15 Correct 3 ms 752 KB Output is correct
16 Correct 4 ms 752 KB Output is correct
17 Correct 6 ms 752 KB Output is correct
18 Correct 6 ms 752 KB Output is correct
19 Correct 6 ms 752 KB Output is correct
20 Correct 6 ms 752 KB Output is correct
21 Correct 6 ms 752 KB Output is correct
22 Correct 6 ms 752 KB Output is correct
23 Correct 8 ms 752 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 752 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 10 ms 760 KB Output is correct
28 Correct 6 ms 760 KB Output is correct
29 Correct 6 ms 760 KB Output is correct
30 Correct 6 ms 760 KB Output is correct
31 Correct 6 ms 760 KB Output is correct
32 Correct 9 ms 760 KB Output is correct
33 Correct 7 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 760 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 6 ms 760 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 7 ms 760 KB Output is correct
6 Correct 7 ms 760 KB Output is correct
7 Correct 11 ms 760 KB Output is correct
8 Correct 7 ms 760 KB Output is correct
9 Correct 7 ms 760 KB Output is correct
10 Correct 7 ms 760 KB Output is correct
11 Correct 10 ms 760 KB Output is correct
12 Correct 11 ms 760 KB Output is correct
13 Correct 7 ms 760 KB Output is correct
14 Correct 10 ms 760 KB Output is correct
15 Correct 7 ms 760 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 7 ms 760 KB Output is correct
18 Correct 8 ms 760 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 10 ms 760 KB Output is correct
21 Correct 9 ms 760 KB Output is correct
22 Correct 10 ms 760 KB Output is correct
23 Correct 9 ms 760 KB Output is correct
24 Correct 8 ms 760 KB Output is correct
25 Correct 6 ms 760 KB Output is correct