Submission #829301

# Submission time Handle Problem Language Result Execution time Memory
829301 2023-08-18T08:30:38 Z otarius Catfish Farm (IOI22_fish) C++17
100 / 100
198 ms 44140 KB
#include "fish.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
 
// #define int long long
// #define int unsigned long long
 
const ll inf = 1e18;
const ll weirdMod = 998244353;
 
int n, m, y, w;
struct fentree {
    ll t[100005];
    void init() {
        for (int i = 1; i <= n; i++) t[i] = -inf;
    }
    
    void update(int i, ll k) {
        for ( ; i <= n; i += (i & -i)) t[i] = max(t[i], k);
    }
    
    ll query(int i) {
        ll ans = -inf;
        for ( ; i; i -= (i & -i)) ans = max(ans, t[i]);
        return ans;
    }
} t1, t2;
 
vector<pll> pos[100005];
vector<ll> dp1[100005];
vector<ll> dp2[100005];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n = N; m = M;
    
    for (int i = 0; i < M; i++) {
        X[i]++; Y[i]++;
        pos[X[i]].pb({Y[i], W[i]});
    }
    for (int i = 0; i <= n + 1; i++) {
        sort(pos[i].begin(), pos[i].end());
        if (pos[i].empty() || pos[i][0].ff != 1) pos[i].pb({1, 0});
        sort(pos[i].begin(), pos[i].end());
        if (pos[i].back().ff != n) pos[i].pb({n, 0});
        
        dp1[i] = vector<ll>(pos[i].size(), -inf);
        dp2[i] = vector<ll>(pos[i].size(), -inf);
    }
    
    t1.init(); t2.init();
    
    dp1[0][dp1[0].size() - 1] = 0; dp2[0][0] = 0;
    ll a = -inf, b = -inf, ans = 0;
    for (int i = 0; i <= n + 1; i++) {
        int k = pos[i].size();
        
        if (i >= 1) a = max(a, dp2[i - 1][0]);
        if (i >= 2) b = max(b, dp1[i - 2].back());
        
        dp1[i][0] = max(dp1[i][0], a + pos[i][0].sc);
        if (i >= 2) dp1[i][0] = max(dp1[i][0], dp1[i - 2].back() + pos[i][0].sc);
        dp2[i][k - 1] = max(dp2[i][k - 1], b + pos[i][k - 1].sc);
        
        for (int j = 0; j < k; j++) {
            y = pos[i][j].ff;
            w = pos[i][j].sc;
            
            dp1[i][j] = max(dp1[i][j], t1.query(y - 1) + w);
            t1.update(y, dp1[i][j]);
        }
        
        for (int j = k - 1; j >= 0; j--) {
            y = pos[i][j].ff;
            w = pos[i][j].sc;
            
            dp2[i][j] = max(dp2[i][j], t2.query(n - y) + w);
            t2.update(n - y + 1, dp2[i][j]);
        }
        
        ans = max(ans, dp2[i][0]);
    }
    
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 72 ms 23064 KB Output is correct
2 Correct 76 ms 25308 KB Output is correct
3 Correct 30 ms 19836 KB Output is correct
4 Correct 30 ms 19836 KB Output is correct
5 Correct 150 ms 36296 KB Output is correct
6 Correct 198 ms 38256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 88 ms 27512 KB Output is correct
3 Correct 105 ms 34280 KB Output is correct
4 Correct 57 ms 24472 KB Output is correct
5 Correct 76 ms 27024 KB Output is correct
6 Correct 4 ms 7356 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 4 ms 7360 KB Output is correct
9 Correct 4 ms 7272 KB Output is correct
10 Correct 31 ms 19852 KB Output is correct
11 Correct 29 ms 19876 KB Output is correct
12 Correct 72 ms 24380 KB Output is correct
13 Correct 67 ms 27096 KB Output is correct
14 Correct 62 ms 24396 KB Output is correct
15 Correct 68 ms 26328 KB Output is correct
16 Correct 61 ms 24504 KB Output is correct
17 Correct 72 ms 26296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 19760 KB Output is correct
2 Correct 31 ms 19812 KB Output is correct
3 Correct 40 ms 19796 KB Output is correct
4 Correct 40 ms 21312 KB Output is correct
5 Correct 57 ms 23852 KB Output is correct
6 Correct 60 ms 23104 KB Output is correct
7 Correct 60 ms 23752 KB Output is correct
8 Correct 60 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7292 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7292 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 19 ms 10024 KB Output is correct
18 Correct 18 ms 10456 KB Output is correct
19 Correct 18 ms 10348 KB Output is correct
20 Correct 21 ms 10324 KB Output is correct
21 Correct 25 ms 10324 KB Output is correct
22 Correct 33 ms 13380 KB Output is correct
23 Correct 6 ms 7892 KB Output is correct
24 Correct 13 ms 9112 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 6 ms 7896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7292 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 19 ms 10024 KB Output is correct
18 Correct 18 ms 10456 KB Output is correct
19 Correct 18 ms 10348 KB Output is correct
20 Correct 21 ms 10324 KB Output is correct
21 Correct 25 ms 10324 KB Output is correct
22 Correct 33 ms 13380 KB Output is correct
23 Correct 6 ms 7892 KB Output is correct
24 Correct 13 ms 9112 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 6 ms 7896 KB Output is correct
27 Correct 5 ms 7892 KB Output is correct
28 Correct 74 ms 21284 KB Output is correct
29 Correct 113 ms 25932 KB Output is correct
30 Correct 112 ms 25460 KB Output is correct
31 Correct 110 ms 25472 KB Output is correct
32 Correct 96 ms 27128 KB Output is correct
33 Correct 116 ms 25420 KB Output is correct
34 Correct 115 ms 25484 KB Output is correct
35 Correct 49 ms 14924 KB Output is correct
36 Correct 110 ms 27008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 19760 KB Output is correct
2 Correct 31 ms 19812 KB Output is correct
3 Correct 40 ms 19796 KB Output is correct
4 Correct 40 ms 21312 KB Output is correct
5 Correct 57 ms 23852 KB Output is correct
6 Correct 60 ms 23104 KB Output is correct
7 Correct 60 ms 23752 KB Output is correct
8 Correct 60 ms 23796 KB Output is correct
9 Correct 72 ms 26640 KB Output is correct
10 Correct 50 ms 19840 KB Output is correct
11 Correct 116 ms 32488 KB Output is correct
12 Correct 5 ms 7352 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 3 ms 7252 KB Output is correct
15 Correct 3 ms 7252 KB Output is correct
16 Correct 3 ms 7360 KB Output is correct
17 Correct 3 ms 7352 KB Output is correct
18 Correct 30 ms 19880 KB Output is correct
19 Correct 36 ms 19780 KB Output is correct
20 Correct 32 ms 19864 KB Output is correct
21 Correct 29 ms 19776 KB Output is correct
22 Correct 72 ms 27332 KB Output is correct
23 Correct 117 ms 34280 KB Output is correct
24 Correct 105 ms 35184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 23064 KB Output is correct
2 Correct 76 ms 25308 KB Output is correct
3 Correct 30 ms 19836 KB Output is correct
4 Correct 30 ms 19836 KB Output is correct
5 Correct 150 ms 36296 KB Output is correct
6 Correct 198 ms 38256 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 88 ms 27512 KB Output is correct
9 Correct 105 ms 34280 KB Output is correct
10 Correct 57 ms 24472 KB Output is correct
11 Correct 76 ms 27024 KB Output is correct
12 Correct 4 ms 7356 KB Output is correct
13 Correct 3 ms 7252 KB Output is correct
14 Correct 4 ms 7360 KB Output is correct
15 Correct 4 ms 7272 KB Output is correct
16 Correct 31 ms 19852 KB Output is correct
17 Correct 29 ms 19876 KB Output is correct
18 Correct 72 ms 24380 KB Output is correct
19 Correct 67 ms 27096 KB Output is correct
20 Correct 62 ms 24396 KB Output is correct
21 Correct 68 ms 26328 KB Output is correct
22 Correct 61 ms 24504 KB Output is correct
23 Correct 72 ms 26296 KB Output is correct
24 Correct 30 ms 19760 KB Output is correct
25 Correct 31 ms 19812 KB Output is correct
26 Correct 40 ms 19796 KB Output is correct
27 Correct 40 ms 21312 KB Output is correct
28 Correct 57 ms 23852 KB Output is correct
29 Correct 60 ms 23104 KB Output is correct
30 Correct 60 ms 23752 KB Output is correct
31 Correct 60 ms 23796 KB Output is correct
32 Correct 3 ms 7292 KB Output is correct
33 Correct 3 ms 7252 KB Output is correct
34 Correct 3 ms 7252 KB Output is correct
35 Correct 3 ms 7252 KB Output is correct
36 Correct 3 ms 7252 KB Output is correct
37 Correct 3 ms 7252 KB Output is correct
38 Correct 3 ms 7252 KB Output is correct
39 Correct 3 ms 7252 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 4 ms 7508 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
43 Correct 5 ms 7376 KB Output is correct
44 Correct 3 ms 7380 KB Output is correct
45 Correct 6 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 4 ms 7380 KB Output is correct
48 Correct 19 ms 10024 KB Output is correct
49 Correct 18 ms 10456 KB Output is correct
50 Correct 18 ms 10348 KB Output is correct
51 Correct 21 ms 10324 KB Output is correct
52 Correct 25 ms 10324 KB Output is correct
53 Correct 33 ms 13380 KB Output is correct
54 Correct 6 ms 7892 KB Output is correct
55 Correct 13 ms 9112 KB Output is correct
56 Correct 4 ms 7380 KB Output is correct
57 Correct 6 ms 7896 KB Output is correct
58 Correct 5 ms 7892 KB Output is correct
59 Correct 74 ms 21284 KB Output is correct
60 Correct 113 ms 25932 KB Output is correct
61 Correct 112 ms 25460 KB Output is correct
62 Correct 110 ms 25472 KB Output is correct
63 Correct 96 ms 27128 KB Output is correct
64 Correct 116 ms 25420 KB Output is correct
65 Correct 115 ms 25484 KB Output is correct
66 Correct 49 ms 14924 KB Output is correct
67 Correct 110 ms 27008 KB Output is correct
68 Correct 72 ms 26640 KB Output is correct
69 Correct 50 ms 19840 KB Output is correct
70 Correct 116 ms 32488 KB Output is correct
71 Correct 5 ms 7352 KB Output is correct
72 Correct 4 ms 7360 KB Output is correct
73 Correct 3 ms 7252 KB Output is correct
74 Correct 3 ms 7252 KB Output is correct
75 Correct 3 ms 7360 KB Output is correct
76 Correct 3 ms 7352 KB Output is correct
77 Correct 30 ms 19880 KB Output is correct
78 Correct 36 ms 19780 KB Output is correct
79 Correct 32 ms 19864 KB Output is correct
80 Correct 29 ms 19776 KB Output is correct
81 Correct 72 ms 27332 KB Output is correct
82 Correct 117 ms 34280 KB Output is correct
83 Correct 105 ms 35184 KB Output is correct
84 Correct 157 ms 41188 KB Output is correct
85 Correct 158 ms 41980 KB Output is correct
86 Correct 191 ms 42720 KB Output is correct
87 Correct 179 ms 44108 KB Output is correct
88 Correct 4 ms 7252 KB Output is correct
89 Correct 178 ms 44140 KB Output is correct
90 Correct 169 ms 42852 KB Output is correct
91 Correct 145 ms 42760 KB Output is correct