Submission #832255

# Submission time Handle Problem Language Result Execution time Memory
832255 2023-08-21T07:55:13 Z fatemetmhr Catfish Farm (IOI22_fish) C++17
100 / 100
189 ms 66124 KB
// komak!

#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
#define mp       make_pair
#define pb       push_back

typedef long long ll;

const ll mod   = 1e9 + 7;
const int maxn5 = 3e5 + 10;

vector <pair<int, ll>> av[maxn5];
vector <ll> ps[maxn5], dp[maxn5][2];

long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
                      std::vector<int> w) {

    for(int i = 0; i < m; i++){
        av[x[i]].pb({y[i], w[i]});
    }
    for(int i = 0; i < n; i++){
        av[i].pb({n, 0});
        sort(all(av[i]));
        ps[i].resize(int(av[i].size()));
        ps[i][0] = av[i][0].se;
        for(int j = 1; j < int(av[i].size()); j++){
            ps[i][j] = ps[i][j - 1] + av[i][j].se;
        }
        dp[i][0].resize(int(av[i].size()));
        dp[i][1].resize(int(av[i].size()));
    }

    ll ans = 0;

    for(int i = 0; i < int(av[0].size()); i++){
        dp[0][0][i] = (i ? -ps[0][i - 1] : 0);
        int pt = upper_bound(all(av[1]), mp(av[0][i].fi - 1, mod)) - av[1].begin() - 1;
        dp[0][1][i] = (pt >= 0 ? ps[1][pt] : 0);
        if(i)
            dp[0][0][i] = max(dp[0][0][i - 1], dp[0][0][i]);
    }

    for(int i = int(av[0].size()) - 2; i >= 0; i--)
        dp[0][1][i] = max(dp[0][1][i], dp[0][1][i + 1]);


    for(int i = 1; i < n; i++){
        ll keepmx = ans;
        for(int j = 0; j < int(av[i].size()); j++){
            //debug(i);
            //debug(j);
            //debug(av[i][j].fi);
            int pt = upper_bound(all(av[i - 1]), mp(av[i][j].fi - 1, mod)) - av[i - 1].begin() - 1;
            dp[i][0][j] = keepmx;
            if(pt >= 0)
                dp[i][0][j] = max(dp[i][0][j], dp[i - 1][0][pt] + ps[i - 1][pt]);
            //debug(dp[i][0][j]);
            //debug(pt);
            ans = max(ans, dp[i][0][j]);
            dp[i][1][j] = max(keepmx, dp[i][0][j]);
            dp[i][0][j] += (j ? -ps[i][j - 1] : 0);
            if(j)
                dp[i][0][j] = max(dp[i][0][j - 1], dp[i][0][j]);
            pt = upper_bound(all(av[i - 1]), mp(av[i][j].fi, mod)) - av[i - 1].begin();
            if(pt < int(av[i - 1].size())){
                ////debug(dp[i - 1][1][pt]);

                dp[i][1][j] = max(dp[i][1][j], dp[i - 1][1][pt] - (j ? ps[i][j - 1] : 0));
            }
            //debug(dp[i][1][j]);
            //debug(pt);
            ans = max(ans, dp[i][1][j]);
            if(i < n - 1){
                pt = upper_bound(all(av[i + 1]), mp(av[i][j].fi - 1, mod)) - av[i + 1].begin() - 1;
                dp[i][1][j] += (pt >= 0 ? ps[i + 1][pt] : 0);
                //debug(pt);


            }
        }
        for(int j = int(av[i].size()) - 2; j >= 0; j--)
            dp[i][1][j] = max(dp[i][1][j], dp[i][1][j + 1]);
    }

    return ans;
}






















# Verdict Execution time Memory Grader output
1 Correct 58 ms 44756 KB Output is correct
2 Correct 70 ms 47184 KB Output is correct
3 Correct 35 ms 40988 KB Output is correct
4 Correct 34 ms 40976 KB Output is correct
5 Correct 141 ms 59744 KB Output is correct
6 Correct 160 ms 59900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28448 KB Output is correct
2 Correct 99 ms 49888 KB Output is correct
3 Correct 123 ms 53556 KB Output is correct
4 Correct 63 ms 44708 KB Output is correct
5 Correct 69 ms 47252 KB Output is correct
6 Correct 14 ms 28448 KB Output is correct
7 Correct 17 ms 28444 KB Output is correct
8 Correct 14 ms 28372 KB Output is correct
9 Correct 15 ms 28372 KB Output is correct
10 Correct 34 ms 40952 KB Output is correct
11 Correct 35 ms 40984 KB Output is correct
12 Correct 70 ms 44780 KB Output is correct
13 Correct 67 ms 47264 KB Output is correct
14 Correct 63 ms 44804 KB Output is correct
15 Correct 79 ms 46648 KB Output is correct
16 Correct 61 ms 44800 KB Output is correct
17 Correct 78 ms 46576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 40904 KB Output is correct
2 Correct 34 ms 40928 KB Output is correct
3 Correct 63 ms 41804 KB Output is correct
4 Correct 48 ms 42352 KB Output is correct
5 Correct 72 ms 44840 KB Output is correct
6 Correct 72 ms 44884 KB Output is correct
7 Correct 88 ms 44884 KB Output is correct
8 Correct 85 ms 44876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28364 KB Output is correct
2 Correct 14 ms 28388 KB Output is correct
3 Correct 14 ms 28412 KB Output is correct
4 Correct 14 ms 28372 KB Output is correct
5 Correct 15 ms 28480 KB Output is correct
6 Correct 14 ms 28404 KB Output is correct
7 Correct 14 ms 28468 KB Output is correct
8 Correct 14 ms 28368 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 17 ms 28628 KB Output is correct
11 Correct 18 ms 28512 KB Output is correct
12 Correct 15 ms 28500 KB Output is correct
13 Correct 15 ms 28500 KB Output is correct
14 Correct 14 ms 28492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28364 KB Output is correct
2 Correct 14 ms 28388 KB Output is correct
3 Correct 14 ms 28412 KB Output is correct
4 Correct 14 ms 28372 KB Output is correct
5 Correct 15 ms 28480 KB Output is correct
6 Correct 14 ms 28404 KB Output is correct
7 Correct 14 ms 28468 KB Output is correct
8 Correct 14 ms 28368 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 17 ms 28628 KB Output is correct
11 Correct 18 ms 28512 KB Output is correct
12 Correct 15 ms 28500 KB Output is correct
13 Correct 15 ms 28500 KB Output is correct
14 Correct 14 ms 28492 KB Output is correct
15 Correct 14 ms 28500 KB Output is correct
16 Correct 19 ms 28700 KB Output is correct
17 Correct 33 ms 32220 KB Output is correct
18 Correct 33 ms 32852 KB Output is correct
19 Correct 30 ms 32596 KB Output is correct
20 Correct 29 ms 32596 KB Output is correct
21 Correct 29 ms 32644 KB Output is correct
22 Correct 47 ms 36692 KB Output is correct
23 Correct 18 ms 29156 KB Output is correct
24 Correct 28 ms 31040 KB Output is correct
25 Correct 15 ms 28500 KB Output is correct
26 Correct 18 ms 29220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28364 KB Output is correct
2 Correct 14 ms 28388 KB Output is correct
3 Correct 14 ms 28412 KB Output is correct
4 Correct 14 ms 28372 KB Output is correct
5 Correct 15 ms 28480 KB Output is correct
6 Correct 14 ms 28404 KB Output is correct
7 Correct 14 ms 28468 KB Output is correct
8 Correct 14 ms 28368 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 17 ms 28628 KB Output is correct
11 Correct 18 ms 28512 KB Output is correct
12 Correct 15 ms 28500 KB Output is correct
13 Correct 15 ms 28500 KB Output is correct
14 Correct 14 ms 28492 KB Output is correct
15 Correct 14 ms 28500 KB Output is correct
16 Correct 19 ms 28700 KB Output is correct
17 Correct 33 ms 32220 KB Output is correct
18 Correct 33 ms 32852 KB Output is correct
19 Correct 30 ms 32596 KB Output is correct
20 Correct 29 ms 32596 KB Output is correct
21 Correct 29 ms 32644 KB Output is correct
22 Correct 47 ms 36692 KB Output is correct
23 Correct 18 ms 29156 KB Output is correct
24 Correct 28 ms 31040 KB Output is correct
25 Correct 15 ms 28500 KB Output is correct
26 Correct 18 ms 29220 KB Output is correct
27 Correct 16 ms 28936 KB Output is correct
28 Correct 104 ms 47776 KB Output is correct
29 Correct 140 ms 54912 KB Output is correct
30 Correct 131 ms 54476 KB Output is correct
31 Correct 130 ms 54476 KB Output is correct
32 Correct 136 ms 55792 KB Output is correct
33 Correct 133 ms 54572 KB Output is correct
34 Correct 142 ms 54504 KB Output is correct
35 Correct 59 ms 38888 KB Output is correct
36 Correct 143 ms 55904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 40904 KB Output is correct
2 Correct 34 ms 40928 KB Output is correct
3 Correct 63 ms 41804 KB Output is correct
4 Correct 48 ms 42352 KB Output is correct
5 Correct 72 ms 44840 KB Output is correct
6 Correct 72 ms 44884 KB Output is correct
7 Correct 88 ms 44884 KB Output is correct
8 Correct 85 ms 44876 KB Output is correct
9 Correct 76 ms 44920 KB Output is correct
10 Correct 73 ms 41752 KB Output is correct
11 Correct 125 ms 55156 KB Output is correct
12 Correct 14 ms 28372 KB Output is correct
13 Correct 21 ms 28488 KB Output is correct
14 Correct 14 ms 28372 KB Output is correct
15 Correct 15 ms 28372 KB Output is correct
16 Correct 15 ms 28372 KB Output is correct
17 Correct 26 ms 28436 KB Output is correct
18 Correct 35 ms 40892 KB Output is correct
19 Correct 35 ms 40992 KB Output is correct
20 Correct 35 ms 40916 KB Output is correct
21 Correct 44 ms 40916 KB Output is correct
22 Correct 85 ms 47508 KB Output is correct
23 Correct 144 ms 55108 KB Output is correct
24 Correct 144 ms 55644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 44756 KB Output is correct
2 Correct 70 ms 47184 KB Output is correct
3 Correct 35 ms 40988 KB Output is correct
4 Correct 34 ms 40976 KB Output is correct
5 Correct 141 ms 59744 KB Output is correct
6 Correct 160 ms 59900 KB Output is correct
7 Correct 14 ms 28448 KB Output is correct
8 Correct 99 ms 49888 KB Output is correct
9 Correct 123 ms 53556 KB Output is correct
10 Correct 63 ms 44708 KB Output is correct
11 Correct 69 ms 47252 KB Output is correct
12 Correct 14 ms 28448 KB Output is correct
13 Correct 17 ms 28444 KB Output is correct
14 Correct 14 ms 28372 KB Output is correct
15 Correct 15 ms 28372 KB Output is correct
16 Correct 34 ms 40952 KB Output is correct
17 Correct 35 ms 40984 KB Output is correct
18 Correct 70 ms 44780 KB Output is correct
19 Correct 67 ms 47264 KB Output is correct
20 Correct 63 ms 44804 KB Output is correct
21 Correct 79 ms 46648 KB Output is correct
22 Correct 61 ms 44800 KB Output is correct
23 Correct 78 ms 46576 KB Output is correct
24 Correct 34 ms 40904 KB Output is correct
25 Correct 34 ms 40928 KB Output is correct
26 Correct 63 ms 41804 KB Output is correct
27 Correct 48 ms 42352 KB Output is correct
28 Correct 72 ms 44840 KB Output is correct
29 Correct 72 ms 44884 KB Output is correct
30 Correct 88 ms 44884 KB Output is correct
31 Correct 85 ms 44876 KB Output is correct
32 Correct 14 ms 28364 KB Output is correct
33 Correct 14 ms 28388 KB Output is correct
34 Correct 14 ms 28412 KB Output is correct
35 Correct 14 ms 28372 KB Output is correct
36 Correct 15 ms 28480 KB Output is correct
37 Correct 14 ms 28404 KB Output is correct
38 Correct 14 ms 28468 KB Output is correct
39 Correct 14 ms 28368 KB Output is correct
40 Correct 16 ms 28500 KB Output is correct
41 Correct 17 ms 28628 KB Output is correct
42 Correct 18 ms 28512 KB Output is correct
43 Correct 15 ms 28500 KB Output is correct
44 Correct 15 ms 28500 KB Output is correct
45 Correct 14 ms 28492 KB Output is correct
46 Correct 14 ms 28500 KB Output is correct
47 Correct 19 ms 28700 KB Output is correct
48 Correct 33 ms 32220 KB Output is correct
49 Correct 33 ms 32852 KB Output is correct
50 Correct 30 ms 32596 KB Output is correct
51 Correct 29 ms 32596 KB Output is correct
52 Correct 29 ms 32644 KB Output is correct
53 Correct 47 ms 36692 KB Output is correct
54 Correct 18 ms 29156 KB Output is correct
55 Correct 28 ms 31040 KB Output is correct
56 Correct 15 ms 28500 KB Output is correct
57 Correct 18 ms 29220 KB Output is correct
58 Correct 16 ms 28936 KB Output is correct
59 Correct 104 ms 47776 KB Output is correct
60 Correct 140 ms 54912 KB Output is correct
61 Correct 131 ms 54476 KB Output is correct
62 Correct 130 ms 54476 KB Output is correct
63 Correct 136 ms 55792 KB Output is correct
64 Correct 133 ms 54572 KB Output is correct
65 Correct 142 ms 54504 KB Output is correct
66 Correct 59 ms 38888 KB Output is correct
67 Correct 143 ms 55904 KB Output is correct
68 Correct 76 ms 44920 KB Output is correct
69 Correct 73 ms 41752 KB Output is correct
70 Correct 125 ms 55156 KB Output is correct
71 Correct 14 ms 28372 KB Output is correct
72 Correct 21 ms 28488 KB Output is correct
73 Correct 14 ms 28372 KB Output is correct
74 Correct 15 ms 28372 KB Output is correct
75 Correct 15 ms 28372 KB Output is correct
76 Correct 26 ms 28436 KB Output is correct
77 Correct 35 ms 40892 KB Output is correct
78 Correct 35 ms 40992 KB Output is correct
79 Correct 35 ms 40916 KB Output is correct
80 Correct 44 ms 40916 KB Output is correct
81 Correct 85 ms 47508 KB Output is correct
82 Correct 144 ms 55108 KB Output is correct
83 Correct 144 ms 55644 KB Output is correct
84 Correct 160 ms 64736 KB Output is correct
85 Correct 164 ms 65568 KB Output is correct
86 Correct 166 ms 63300 KB Output is correct
87 Correct 189 ms 64488 KB Output is correct
88 Correct 15 ms 28372 KB Output is correct
89 Correct 169 ms 64496 KB Output is correct
90 Correct 156 ms 65384 KB Output is correct
91 Correct 153 ms 66124 KB Output is correct