Submission #1075272

# Submission time Handle Problem Language Result Execution time Memory
1075272 2024-08-25T23:16:02 Z mariaclara Catfish Farm (IOI22_fish) C++17
100 / 100
127 ms 37972 KB
#include "fish.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> pii;
typedef tuple<int,int,int> trio;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define mk make_pair
#define fr first 
#define sc second
 
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vector<vector<pii>> val(N);
    vector<vector<ll>> dp[2];
    dp[0].resize(N); // x-1 < x
    dp[1].resize(N); // x-1 > x
 
    for(int i = 0; i < M; i++) val[X[i]].pb({Y[i], W[i]});
    
    dp[0][0].resize(sz(val[0])+1, 0);
    dp[1][0].resize(sz(val[0])+1, 0);
    sort(all(val[0]));
    reverse(all(val[0]));
 
    for(int x = 1; x < N; x++) {
        sort(all(val[x]));
        reverse(all(val[x]));
 
        dp[0][x].resize(sz(val[x])+1);
        dp[1][x].resize(sz(val[x])+1);
 
        // >
        for(int i = 0, j = 0; i < sz(val[x]); i++) {
            auto [y,w] = val[x][i];
            if(i != 0) dp[1][x][i+1] = dp[1][x][i] + w;
 
            while(j < sz(val[x-1]) and val[x-1][j].fr > y) j++;
            
            dp[1][x][i+1] = max(dp[1][x][i+1], dp[1][x-1][j] + w); // LEMBRAR DE dp[1][x][j] max= dp[1][x][j-1]
            //cout << "1x = " << x << ", i = " << i << ", y = " << y << ", w = " << w << ", dp = " << dp[1][x][i+1] << "\n";
        }
 
        // <
        ll w = 0;
        for(int i = sz(val[x]) - 1, j = sz(val[x-1]) - 1, y; i >= -1; i--) {
            if(i >= 0) y = val[x][i].fr;
            else y = N;
  
            while(j >= 0 and val[x-1][j].fr < y) {
                w = max(w, dp[0][x-1][j+1]);
                w += val[x-1][j].sc;
                j--;
            }
 
            dp[0][x][i+1] = max({dp[0][x][i+1], dp[1][x-1][sz(val[x-1])], w});
            //cout << "0x = " << x << ", i = " << i << ", y = " << y << ", w = " << w << ", dp = " << dp[0][x][i+1] << "\n";
        }
 
        dp[1][x][0] = max(dp[1][x][0], dp[0][x][0]);
        for(int i = 1; i <= sz(val[x]); i++)
            dp[1][x][i] = max({dp[1][x][i], dp[1][x][i-1], dp[0][x][i]});
    }
 
    return dp[1][N-1][sz(val[N-1])];
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 18116 KB Output is correct
2 Correct 38 ms 20940 KB Output is correct
3 Correct 12 ms 13660 KB Output is correct
4 Correct 11 ms 13656 KB Output is correct
5 Correct 95 ms 36548 KB Output is correct
6 Correct 124 ms 37972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 59 ms 24112 KB Output is correct
3 Correct 66 ms 28048 KB Output is correct
4 Correct 32 ms 18112 KB Output is correct
5 Correct 37 ms 20936 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 18 ms 13656 KB Output is correct
11 Correct 13 ms 13660 KB Output is correct
12 Correct 31 ms 18128 KB Output is correct
13 Correct 37 ms 20932 KB Output is correct
14 Correct 33 ms 18152 KB Output is correct
15 Correct 34 ms 20240 KB Output is correct
16 Correct 33 ms 18112 KB Output is correct
17 Correct 45 ms 20188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 13660 KB Output is correct
2 Correct 11 ms 13660 KB Output is correct
3 Correct 28 ms 16048 KB Output is correct
4 Correct 23 ms 16164 KB Output is correct
5 Correct 47 ms 20816 KB Output is correct
6 Correct 36 ms 20048 KB Output is correct
7 Correct 40 ms 20748 KB Output is correct
8 Correct 54 ms 20560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 12 ms 3656 KB Output is correct
18 Correct 11 ms 4188 KB Output is correct
19 Correct 11 ms 4284 KB Output is correct
20 Correct 12 ms 4188 KB Output is correct
21 Correct 12 ms 4156 KB Output is correct
22 Correct 23 ms 8008 KB Output is correct
23 Correct 4 ms 1116 KB Output is correct
24 Correct 8 ms 2652 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 12 ms 3656 KB Output is correct
18 Correct 11 ms 4188 KB Output is correct
19 Correct 11 ms 4284 KB Output is correct
20 Correct 12 ms 4188 KB Output is correct
21 Correct 12 ms 4156 KB Output is correct
22 Correct 23 ms 8008 KB Output is correct
23 Correct 4 ms 1116 KB Output is correct
24 Correct 8 ms 2652 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 55 ms 18320 KB Output is correct
29 Correct 76 ms 24912 KB Output is correct
30 Correct 98 ms 24148 KB Output is correct
31 Correct 75 ms 24152 KB Output is correct
32 Correct 80 ms 25424 KB Output is correct
33 Correct 89 ms 24400 KB Output is correct
34 Correct 83 ms 24148 KB Output is correct
35 Correct 43 ms 10028 KB Output is correct
36 Correct 81 ms 25424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 13660 KB Output is correct
2 Correct 11 ms 13660 KB Output is correct
3 Correct 28 ms 16048 KB Output is correct
4 Correct 23 ms 16164 KB Output is correct
5 Correct 47 ms 20816 KB Output is correct
6 Correct 36 ms 20048 KB Output is correct
7 Correct 40 ms 20748 KB Output is correct
8 Correct 54 ms 20560 KB Output is correct
9 Correct 52 ms 20380 KB Output is correct
10 Correct 32 ms 13400 KB Output is correct
11 Correct 71 ms 26712 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 13 ms 13644 KB Output is correct
19 Correct 13 ms 13660 KB Output is correct
20 Correct 11 ms 13660 KB Output is correct
21 Correct 14 ms 13680 KB Output is correct
22 Correct 40 ms 20564 KB Output is correct
23 Correct 74 ms 26796 KB Output is correct
24 Correct 75 ms 27244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 18116 KB Output is correct
2 Correct 38 ms 20940 KB Output is correct
3 Correct 12 ms 13660 KB Output is correct
4 Correct 11 ms 13656 KB Output is correct
5 Correct 95 ms 36548 KB Output is correct
6 Correct 124 ms 37972 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 59 ms 24112 KB Output is correct
9 Correct 66 ms 28048 KB Output is correct
10 Correct 32 ms 18112 KB Output is correct
11 Correct 37 ms 20936 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 18 ms 13656 KB Output is correct
17 Correct 13 ms 13660 KB Output is correct
18 Correct 31 ms 18128 KB Output is correct
19 Correct 37 ms 20932 KB Output is correct
20 Correct 33 ms 18152 KB Output is correct
21 Correct 34 ms 20240 KB Output is correct
22 Correct 33 ms 18112 KB Output is correct
23 Correct 45 ms 20188 KB Output is correct
24 Correct 15 ms 13660 KB Output is correct
25 Correct 11 ms 13660 KB Output is correct
26 Correct 28 ms 16048 KB Output is correct
27 Correct 23 ms 16164 KB Output is correct
28 Correct 47 ms 20816 KB Output is correct
29 Correct 36 ms 20048 KB Output is correct
30 Correct 40 ms 20748 KB Output is correct
31 Correct 54 ms 20560 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 600 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 12 ms 3656 KB Output is correct
49 Correct 11 ms 4188 KB Output is correct
50 Correct 11 ms 4284 KB Output is correct
51 Correct 12 ms 4188 KB Output is correct
52 Correct 12 ms 4156 KB Output is correct
53 Correct 23 ms 8008 KB Output is correct
54 Correct 4 ms 1116 KB Output is correct
55 Correct 8 ms 2652 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 3 ms 1116 KB Output is correct
58 Correct 2 ms 860 KB Output is correct
59 Correct 55 ms 18320 KB Output is correct
60 Correct 76 ms 24912 KB Output is correct
61 Correct 98 ms 24148 KB Output is correct
62 Correct 75 ms 24152 KB Output is correct
63 Correct 80 ms 25424 KB Output is correct
64 Correct 89 ms 24400 KB Output is correct
65 Correct 83 ms 24148 KB Output is correct
66 Correct 43 ms 10028 KB Output is correct
67 Correct 81 ms 25424 KB Output is correct
68 Correct 52 ms 20380 KB Output is correct
69 Correct 32 ms 13400 KB Output is correct
70 Correct 71 ms 26712 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 436 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 13 ms 13644 KB Output is correct
78 Correct 13 ms 13660 KB Output is correct
79 Correct 11 ms 13660 KB Output is correct
80 Correct 14 ms 13680 KB Output is correct
81 Correct 40 ms 20564 KB Output is correct
82 Correct 74 ms 26796 KB Output is correct
83 Correct 75 ms 27244 KB Output is correct
84 Correct 99 ms 35016 KB Output is correct
85 Correct 127 ms 35844 KB Output is correct
86 Correct 112 ms 35404 KB Output is correct
87 Correct 105 ms 36688 KB Output is correct
88 Correct 1 ms 344 KB Output is correct
89 Correct 121 ms 36860 KB Output is correct
90 Correct 122 ms 36692 KB Output is correct
91 Correct 103 ms 36692 KB Output is correct