답안 #682967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682967 2023-01-17T11:39:26 Z Jarif_Rahman 메기 농장 (IOI22_fish) C++17
100 / 100
258 ms 56012 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W){
    vector<vector<pair<int, ll>>> v(n);
    for(int i = 0; i < n; i++) v[i].pb({0, 0});
    //for(int i = 0; i < n; i++) v[i].pb({n+1, 0});
    for(int i = 0; i < m; i++) v[X[i]].pb({Y[i]+1, W[i]});

    for(auto &s: v) sort(s.begin(), s.end());

    vector<vector<ll>> dp_up(n), dp_down, dtu2, pref;
    vector<ll> dtu(n, 0);

    for(int i = 0; i < n; i++) dp_up[i].resize(v[i].size(), 0);
    dp_down = dp_up;
    dtu2 = dp_up;
    pref = dp_up;

    for(int i = 0; i < n; i++) for(int j = 0; j < pref[i].size(); j++){
        if(j) pref[i][j] = pref[i][j-1];
        pref[i][j]+=v[i][j].sc;
    }

    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j < v[i].size(); j++){
            if(i == n-1){
                dp_down[i][j] = 0;
                dp_up[i][j] = 0;
                continue;
            }

            int x = 1e8;
            if(j+1 < v[i].size()) x = v[i][j+1].f-1;
            int in1 = upper_bound(v[i+1].begin(), v[i+1].end(), make_pair(x, ll(1e9)))-v[i+1].begin();
            in1--;

            dp_up[i][j]-=pref[i][j];
            dp_down[i][j]-=pref[i+1].back()-pref[i+1][in1];
            dp_up[i][j] = max(dp_up[i][j], pref[i].back()-pref[i][j]+dp_down[i+1].back());

            if(i+2 < n){
                int y = 1e8;
                if(in1+1 < v[i+1].size()) y = v[i+1][in1+1].f-1;
                int in2 = upper_bound(v[i+2].begin(), v[i+2].end(), make_pair(y, ll(1e9)))-v[i+2].begin();
                in2--;
                dp_down[i][j] = max(dp_down[i][j], dtu2[i+2][in2]+pref[i+1][in1]);
                dp_down[i][j] = max(dp_down[i][j], dtu[i+2]-pref[i+1][in1]);
                dp_down[i][j] = max(dp_down[i][j], pref[i+1].back()+dp_down[i+2].back());
            }
        }

        if(i){
            ll mx = 0, s = 0;
            auto it = v[i-1].begin();
            for(int j = 0; j < v[i].size(); j++){
                while(it != v[i-1].end() && it->f < (j+1 == v[i].size() ? 1e8:v[i][j+1].f)) s+=it->sc, it++;
                mx = max(mx, s+dp_up[i][j]);
            }
            fill(dp_up[i-1].begin(), dp_up[i-1].end(), mx);
            dtu[i] = mx;

            mx = 0;
            for(int j = 0; j < v[i].size(); j++) mx = max(mx, pref[i].back()-pref[i][j]+dp_down[i][j]);
            fill(dp_down[i-1].begin(), dp_down[i-1].end(), mx);

            for(int j = 0; j < v[i].size(); j++){
                if(j) dtu2[i][j] = dtu2[i][j-1];
                dtu2[i][j] = max(dtu2[i][j], dp_up[i][j]);
            }
        }
    }

    return max(*max_element(dp_up[0].begin(), dp_up[0].end()), *max_element(dp_down[0].begin(), dp_down[0].end()));
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:25:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < n; i++) for(int j = 0; j < pref[i].size(); j++){
      |                                               ~~^~~~~~~~~~~~~~~~
fish.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int j = 0; j < v[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
fish.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if(j+1 < v[i].size()) x = v[i][j+1].f-1;
      |                ~~~~^~~~~~~~~~~~~
fish.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 if(in1+1 < v[i+1].size()) y = v[i+1][in1+1].f-1;
      |                    ~~~~~~^~~~~~~~~~~~~~~
fish.cpp:61:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for(int j = 0; j < v[i].size(); j++){
      |                            ~~^~~~~~~~~~~~~
fish.cpp:62:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 while(it != v[i-1].end() && it->f < (j+1 == v[i].size() ? 1e8:v[i][j+1].f)) s+=it->sc, it++;
      |                                                      ~~~~^~~~~~~~~~~~~~
fish.cpp:69:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int j = 0; j < v[i].size(); j++) mx = max(mx, pref[i].back()-pref[i][j]+dp_down[i][j]);
      |                            ~~^~~~~~~~~~~~~
fish.cpp:72:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for(int j = 0; j < v[i].size(); j++){
      |                            ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 32708 KB Output is correct
2 Correct 98 ms 37160 KB Output is correct
3 Correct 41 ms 28364 KB Output is correct
4 Correct 39 ms 28364 KB Output is correct
5 Correct 200 ms 56012 KB Output is correct
6 Correct 237 ms 55184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 128 ms 39860 KB Output is correct
3 Correct 133 ms 46004 KB Output is correct
4 Correct 76 ms 32696 KB Output is correct
5 Correct 80 ms 37264 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 38 ms 28452 KB Output is correct
11 Correct 41 ms 28472 KB Output is correct
12 Correct 98 ms 32704 KB Output is correct
13 Correct 78 ms 37168 KB Output is correct
14 Correct 70 ms 32704 KB Output is correct
15 Correct 90 ms 36396 KB Output is correct
16 Correct 74 ms 32788 KB Output is correct
17 Correct 82 ms 36284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 28384 KB Output is correct
2 Correct 39 ms 28408 KB Output is correct
3 Correct 70 ms 28880 KB Output is correct
4 Correct 63 ms 30672 KB Output is correct
5 Correct 99 ms 34484 KB Output is correct
6 Correct 97 ms 33840 KB Output is correct
7 Correct 100 ms 34380 KB Output is correct
8 Correct 128 ms 34552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 20 ms 4396 KB Output is correct
18 Correct 19 ms 4948 KB Output is correct
19 Correct 17 ms 4820 KB Output is correct
20 Correct 18 ms 4820 KB Output is correct
21 Correct 18 ms 4864 KB Output is correct
22 Correct 36 ms 9280 KB Output is correct
23 Correct 4 ms 1108 KB Output is correct
24 Correct 13 ms 3128 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 4 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 20 ms 4396 KB Output is correct
18 Correct 19 ms 4948 KB Output is correct
19 Correct 17 ms 4820 KB Output is correct
20 Correct 18 ms 4820 KB Output is correct
21 Correct 18 ms 4864 KB Output is correct
22 Correct 36 ms 9280 KB Output is correct
23 Correct 4 ms 1108 KB Output is correct
24 Correct 13 ms 3128 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 4 ms 1080 KB Output is correct
27 Correct 3 ms 1208 KB Output is correct
28 Correct 100 ms 21648 KB Output is correct
29 Correct 132 ms 29400 KB Output is correct
30 Correct 128 ms 29088 KB Output is correct
31 Correct 134 ms 29136 KB Output is correct
32 Correct 126 ms 30036 KB Output is correct
33 Correct 140 ms 29136 KB Output is correct
34 Correct 135 ms 29032 KB Output is correct
35 Correct 52 ms 12004 KB Output is correct
36 Correct 129 ms 30424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 28384 KB Output is correct
2 Correct 39 ms 28408 KB Output is correct
3 Correct 70 ms 28880 KB Output is correct
4 Correct 63 ms 30672 KB Output is correct
5 Correct 99 ms 34484 KB Output is correct
6 Correct 97 ms 33840 KB Output is correct
7 Correct 100 ms 34380 KB Output is correct
8 Correct 128 ms 34552 KB Output is correct
9 Correct 108 ms 34164 KB Output is correct
10 Correct 78 ms 21076 KB Output is correct
11 Correct 157 ms 41800 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 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 296 KB Output is correct
18 Correct 37 ms 28372 KB Output is correct
19 Correct 37 ms 28372 KB Output is correct
20 Correct 37 ms 28460 KB Output is correct
21 Correct 37 ms 28400 KB Output is correct
22 Correct 107 ms 35148 KB Output is correct
23 Correct 155 ms 41812 KB Output is correct
24 Correct 153 ms 42424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 32708 KB Output is correct
2 Correct 98 ms 37160 KB Output is correct
3 Correct 41 ms 28364 KB Output is correct
4 Correct 39 ms 28364 KB Output is correct
5 Correct 200 ms 56012 KB Output is correct
6 Correct 237 ms 55184 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 128 ms 39860 KB Output is correct
9 Correct 133 ms 46004 KB Output is correct
10 Correct 76 ms 32696 KB Output is correct
11 Correct 80 ms 37264 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 38 ms 28452 KB Output is correct
17 Correct 41 ms 28472 KB Output is correct
18 Correct 98 ms 32704 KB Output is correct
19 Correct 78 ms 37168 KB Output is correct
20 Correct 70 ms 32704 KB Output is correct
21 Correct 90 ms 36396 KB Output is correct
22 Correct 74 ms 32788 KB Output is correct
23 Correct 82 ms 36284 KB Output is correct
24 Correct 37 ms 28384 KB Output is correct
25 Correct 39 ms 28408 KB Output is correct
26 Correct 70 ms 28880 KB Output is correct
27 Correct 63 ms 30672 KB Output is correct
28 Correct 99 ms 34484 KB Output is correct
29 Correct 97 ms 33840 KB Output is correct
30 Correct 100 ms 34380 KB Output is correct
31 Correct 128 ms 34552 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 296 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 296 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 440 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 440 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 20 ms 4396 KB Output is correct
49 Correct 19 ms 4948 KB Output is correct
50 Correct 17 ms 4820 KB Output is correct
51 Correct 18 ms 4820 KB Output is correct
52 Correct 18 ms 4864 KB Output is correct
53 Correct 36 ms 9280 KB Output is correct
54 Correct 4 ms 1108 KB Output is correct
55 Correct 13 ms 3128 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 4 ms 1080 KB Output is correct
58 Correct 3 ms 1208 KB Output is correct
59 Correct 100 ms 21648 KB Output is correct
60 Correct 132 ms 29400 KB Output is correct
61 Correct 128 ms 29088 KB Output is correct
62 Correct 134 ms 29136 KB Output is correct
63 Correct 126 ms 30036 KB Output is correct
64 Correct 140 ms 29136 KB Output is correct
65 Correct 135 ms 29032 KB Output is correct
66 Correct 52 ms 12004 KB Output is correct
67 Correct 129 ms 30424 KB Output is correct
68 Correct 108 ms 34164 KB Output is correct
69 Correct 78 ms 21076 KB Output is correct
70 Correct 157 ms 41800 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 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 296 KB Output is correct
77 Correct 37 ms 28372 KB Output is correct
78 Correct 37 ms 28372 KB Output is correct
79 Correct 37 ms 28460 KB Output is correct
80 Correct 37 ms 28400 KB Output is correct
81 Correct 107 ms 35148 KB Output is correct
82 Correct 155 ms 41812 KB Output is correct
83 Correct 153 ms 42424 KB Output is correct
84 Correct 180 ms 52896 KB Output is correct
85 Correct 170 ms 54988 KB Output is correct
86 Correct 208 ms 50684 KB Output is correct
87 Correct 218 ms 53532 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 258 ms 53480 KB Output is correct
90 Correct 185 ms 54732 KB Output is correct
91 Correct 175 ms 55652 KB Output is correct