답안 #811229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
811229 2023-08-07T02:48:15 Z blackyuki 메기 농장 (IOI22_fish) C++17
100 / 100
147 ms 38608 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001001001;

ll max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W){
    vvp g(N+1);
    rep(i,M)g[X[i]+1].pb(Y[i]+1,W[i]);
    g[0].pb(0,0);
    rep(i,N+1)sort(all(g[i]));
    vi dp1(N+1,-inf),dp2(N+1,-inf);
    vvi dp3(N+1),dp4(N+1);
    rep(i,N+1)rep(j,g[i].size()){
        dp3[i].pb(-inf);dp4[i].pb(-inf);
    }
    dp1[0]=0;dp3[0][0]=0;
    REP(i,1,N+1){
        chmax(dp1[i],dp1[i-1]);chmax(dp2[i],dp2[i-1]);
        if(i<N)rep(j,g[i].size()){
            ll val=-inf;
            chmax(val,dp2[i-1]);
            if(i>1)chmax(val,dp1[i-2]);
            ll l=lb(g[i-1],P(g[i][j].fi,-1))-1;
            if(l>=0)chmax(val,dp3[i-1][l]);
            if(j>0)chmax(val,dp3[i][j-1]);
            val+=g[i][j].se;
            chmax(dp1[i],val);
            dp3[i][j]=val;
            if(j>0)chmax(dp3[i][j],dp3[i][j-1]);
        }
        for(int j=g[i].size()-1;j>=0;j--){
            ll val=-inf;
            if(i>1)chmax(val,dp1[i-2]);
            if(i>1)chmax(val,dp2[i-2]);
            ll l=lb(g[i-1],P(g[i][j].fi+1,-1));
            if(l<g[i-1].size())chmax(val,dp4[i-1][l]);
            if(j+1<g[i].size())chmax(val,dp4[i][j+1]);
            val+=g[i][j].se;
            chmax(dp2[i],val);
            dp4[i][j]=val;
            if(j+1<g[i].size())chmax(dp4[i][j],dp4[i][j+1]);
        }
    }
    return max(dp1[N],dp2[N]);
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:52:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             if(l<g[i-1].size())chmax(val,dp4[i-1][l]);
      |                ~^~~~~~~~~~~~~~
fish.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if(j+1<g[i].size())chmax(val,dp4[i][j+1]);
      |                ~~~^~~~~~~~~~~~
fish.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             if(j+1<g[i].size())chmax(dp4[i][j],dp4[i][j+1]);
      |                ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 13776 KB Output is correct
2 Correct 36 ms 15668 KB Output is correct
3 Correct 5 ms 8916 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 102 ms 27320 KB Output is correct
6 Correct 120 ms 30768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 71 ms 18336 KB Output is correct
3 Correct 80 ms 24636 KB Output is correct
4 Correct 35 ms 15180 KB Output is correct
5 Correct 38 ms 17436 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 4 ms 8920 KB Output is correct
11 Correct 4 ms 8876 KB Output is correct
12 Correct 30 ms 15316 KB Output is correct
13 Correct 37 ms 17452 KB Output is correct
14 Correct 32 ms 14960 KB Output is correct
15 Correct 39 ms 16444 KB Output is correct
16 Correct 32 ms 14928 KB Output is correct
17 Correct 35 ms 16432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8916 KB Output is correct
3 Correct 26 ms 14300 KB Output is correct
4 Correct 20 ms 13116 KB Output is correct
5 Correct 48 ms 20544 KB Output is correct
6 Correct 44 ms 20544 KB Output is correct
7 Correct 46 ms 20648 KB Output is correct
8 Correct 47 ms 20556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 4052 KB Output is correct
19 Correct 15 ms 3812 KB Output is correct
20 Correct 15 ms 3776 KB Output is correct
21 Correct 15 ms 3876 KB Output is correct
22 Correct 30 ms 7412 KB Output is correct
23 Correct 4 ms 852 KB Output is correct
24 Correct 11 ms 2260 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 4052 KB Output is correct
19 Correct 15 ms 3812 KB Output is correct
20 Correct 15 ms 3776 KB Output is correct
21 Correct 15 ms 3876 KB Output is correct
22 Correct 30 ms 7412 KB Output is correct
23 Correct 4 ms 852 KB Output is correct
24 Correct 11 ms 2260 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 1 ms 852 KB Output is correct
28 Correct 80 ms 16392 KB Output is correct
29 Correct 111 ms 20176 KB Output is correct
30 Correct 106 ms 19940 KB Output is correct
31 Correct 109 ms 19952 KB Output is correct
32 Correct 108 ms 24164 KB Output is correct
33 Correct 106 ms 19948 KB Output is correct
34 Correct 107 ms 19940 KB Output is correct
35 Correct 40 ms 8772 KB Output is correct
36 Correct 110 ms 22504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8916 KB Output is correct
3 Correct 26 ms 14300 KB Output is correct
4 Correct 20 ms 13116 KB Output is correct
5 Correct 48 ms 20544 KB Output is correct
6 Correct 44 ms 20544 KB Output is correct
7 Correct 46 ms 20648 KB Output is correct
8 Correct 47 ms 20556 KB Output is correct
9 Correct 51 ms 20684 KB Output is correct
10 Correct 42 ms 12452 KB Output is correct
11 Correct 90 ms 24792 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 4 ms 8916 KB Output is correct
19 Correct 4 ms 8800 KB Output is correct
20 Correct 4 ms 8916 KB Output is correct
21 Correct 4 ms 8916 KB Output is correct
22 Correct 50 ms 18036 KB Output is correct
23 Correct 97 ms 24720 KB Output is correct
24 Correct 96 ms 24780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 13776 KB Output is correct
2 Correct 36 ms 15668 KB Output is correct
3 Correct 5 ms 8916 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 102 ms 27320 KB Output is correct
6 Correct 120 ms 30768 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 71 ms 18336 KB Output is correct
9 Correct 80 ms 24636 KB Output is correct
10 Correct 35 ms 15180 KB Output is correct
11 Correct 38 ms 17436 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 8920 KB Output is correct
17 Correct 4 ms 8876 KB Output is correct
18 Correct 30 ms 15316 KB Output is correct
19 Correct 37 ms 17452 KB Output is correct
20 Correct 32 ms 14960 KB Output is correct
21 Correct 39 ms 16444 KB Output is correct
22 Correct 32 ms 14928 KB Output is correct
23 Correct 35 ms 16432 KB Output is correct
24 Correct 4 ms 8916 KB Output is correct
25 Correct 4 ms 8916 KB Output is correct
26 Correct 26 ms 14300 KB Output is correct
27 Correct 20 ms 13116 KB Output is correct
28 Correct 48 ms 20544 KB Output is correct
29 Correct 44 ms 20544 KB Output is correct
30 Correct 46 ms 20648 KB Output is correct
31 Correct 47 ms 20556 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 16 ms 2896 KB Output is correct
49 Correct 16 ms 4052 KB Output is correct
50 Correct 15 ms 3812 KB Output is correct
51 Correct 15 ms 3776 KB Output is correct
52 Correct 15 ms 3876 KB Output is correct
53 Correct 30 ms 7412 KB Output is correct
54 Correct 4 ms 852 KB Output is correct
55 Correct 11 ms 2260 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 3 ms 852 KB Output is correct
58 Correct 1 ms 852 KB Output is correct
59 Correct 80 ms 16392 KB Output is correct
60 Correct 111 ms 20176 KB Output is correct
61 Correct 106 ms 19940 KB Output is correct
62 Correct 109 ms 19952 KB Output is correct
63 Correct 108 ms 24164 KB Output is correct
64 Correct 106 ms 19948 KB Output is correct
65 Correct 107 ms 19940 KB Output is correct
66 Correct 40 ms 8772 KB Output is correct
67 Correct 110 ms 22504 KB Output is correct
68 Correct 51 ms 20684 KB Output is correct
69 Correct 42 ms 12452 KB Output is correct
70 Correct 90 ms 24792 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 4 ms 8916 KB Output is correct
78 Correct 4 ms 8800 KB Output is correct
79 Correct 4 ms 8916 KB Output is correct
80 Correct 4 ms 8916 KB Output is correct
81 Correct 50 ms 18036 KB Output is correct
82 Correct 97 ms 24720 KB Output is correct
83 Correct 96 ms 24780 KB Output is correct
84 Correct 122 ms 31052 KB Output is correct
85 Correct 125 ms 31624 KB Output is correct
86 Correct 134 ms 37220 KB Output is correct
87 Correct 141 ms 38608 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 147 ms 38492 KB Output is correct
90 Correct 124 ms 36044 KB Output is correct
91 Correct 123 ms 35280 KB Output is correct