Submission #825576

# Submission time Handle Problem Language Result Execution time Memory
825576 2023-08-15T04:19:25 Z becaido Catfish Farm (IOI22_fish) C++17
100 / 100
127 ms 17028 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4,abm")
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const ll INF = 1e18;
const int SIZE = 1e5 + 5;

int n;
vector<pair<int, int>> v[SIZE];
ll ans, zero[2], fzero[2], all[2];
vector<pair<int, ll>> inc[2], dek[2];

inline void chmax(ll &x, const ll &y) {
    x = max(x, y);
}

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n = N;
    FOR (i, 0, M - 1) {
        X[i]++, Y[i]++;
        v[X[i]].pb(Y[i], W[i]);
    }
    fzero[0] = all[0] = -INF;
    FOR (i, 1, n) {
        int f = i & 1;
        sort(v[i].begin(), v[i].end());
        zero[f] = fzero[f] = all[f] = -INF;
        inc[f].clear(), dek[f].clear();

        ll mx = zero[!f], sum = 0;
        int pos = 0;
        for (auto [j, x] : v[i - 1]) {
            while (pos < inc[!f].size() && inc[!f][pos].F < j) {
                mx = max(mx, inc[!f][pos].S - sum);
                pos++;
            }
            sum += x;
            inc[f].pb(j, sum + mx);
        }
        while (pos < inc[!f].size() && inc[!f][pos].F < n) {
            mx = max(mx, inc[!f][pos].S - sum);
            pos++;
        }
        chmax(all[f], sum + mx);
        mx = all[!f], sum = 0, pos = (int) dek[!f].size() - 1;
        for (auto [j, x] : v[i]) sum += x;
        mx += sum;
        for (auto it = v[i].rbegin(); it != v[i].rend(); it++) {
            auto [j, x] = *it;
            j--;
            while (pos >= 0 && dek[!f][pos].F > j) {
                mx = max(mx, dek[!f][pos].S + sum);
                pos--;
            }
            sum -= x;
            dek[f].pb(j, mx - sum);
        }
        while (pos >= 0 && dek[!f][pos].F > 0) {
            mx = max(mx, dek[!f][pos].S + sum);
            pos--;
        }
        chmax(fzero[f], mx - sum);
        reverse(dek[f].begin(), dek[f].end());
        chmax(zero[f], zero[!f]);
        chmax(zero[f], fzero[!f]);
        chmax(all[f], fzero[!f]);
        chmax(all[f], all[!f]);
    }
    int f = n & 1;
    ll ans = 0;
    chmax(ans, zero[f]);
    chmax(ans, fzero[f]);
    chmax(ans, all[f]);
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:42:24: 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]
   42 |             while (pos < inc[!f].size() && inc[!f][pos].F < j) {
      |                    ~~~~^~~~~~~~~~~~~~~~
fish.cpp:49: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]
   49 |         while (pos < inc[!f].size() && inc[!f][pos].F < n) {
      |                ~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 9476 KB Output is correct
2 Correct 35 ms 10348 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 98 ms 17028 KB Output is correct
6 Correct 99 ms 13976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 56 ms 14560 KB Output is correct
3 Correct 68 ms 16692 KB Output is correct
4 Correct 28 ms 9408 KB Output is correct
5 Correct 34 ms 10392 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 28 ms 9488 KB Output is correct
13 Correct 38 ms 10352 KB Output is correct
14 Correct 28 ms 8612 KB Output is correct
15 Correct 33 ms 9340 KB Output is correct
16 Correct 28 ms 8644 KB Output is correct
17 Correct 32 ms 9080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 17 ms 5600 KB Output is correct
4 Correct 13 ms 4624 KB Output is correct
5 Correct 33 ms 8080 KB Output is correct
6 Correct 29 ms 8068 KB Output is correct
7 Correct 30 ms 8060 KB Output is correct
8 Correct 32 ms 8060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 15 ms 4180 KB Output is correct
18 Correct 17 ms 4460 KB Output is correct
19 Correct 16 ms 4452 KB Output is correct
20 Correct 16 ms 4392 KB Output is correct
21 Correct 14 ms 4340 KB Output is correct
22 Correct 27 ms 6156 KB Output is correct
23 Correct 4 ms 2900 KB Output is correct
24 Correct 10 ms 3644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 4 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 15 ms 4180 KB Output is correct
18 Correct 17 ms 4460 KB Output is correct
19 Correct 16 ms 4452 KB Output is correct
20 Correct 16 ms 4392 KB Output is correct
21 Correct 14 ms 4340 KB Output is correct
22 Correct 27 ms 6156 KB Output is correct
23 Correct 4 ms 2900 KB Output is correct
24 Correct 10 ms 3644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 4 ms 2900 KB Output is correct
27 Correct 3 ms 2808 KB Output is correct
28 Correct 75 ms 10948 KB Output is correct
29 Correct 93 ms 13712 KB Output is correct
30 Correct 112 ms 13092 KB Output is correct
31 Correct 93 ms 13088 KB Output is correct
32 Correct 86 ms 14612 KB Output is correct
33 Correct 97 ms 13076 KB Output is correct
34 Correct 94 ms 13076 KB Output is correct
35 Correct 38 ms 6864 KB Output is correct
36 Correct 95 ms 13976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 17 ms 5600 KB Output is correct
4 Correct 13 ms 4624 KB Output is correct
5 Correct 33 ms 8080 KB Output is correct
6 Correct 29 ms 8068 KB Output is correct
7 Correct 30 ms 8060 KB Output is correct
8 Correct 32 ms 8060 KB Output is correct
9 Correct 30 ms 8056 KB Output is correct
10 Correct 30 ms 6484 KB Output is correct
11 Correct 62 ms 10480 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 3 ms 2648 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 35 ms 7028 KB Output is correct
23 Correct 76 ms 10572 KB Output is correct
24 Correct 65 ms 10432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 9476 KB Output is correct
2 Correct 35 ms 10348 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 98 ms 17028 KB Output is correct
6 Correct 99 ms 13976 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 56 ms 14560 KB Output is correct
9 Correct 68 ms 16692 KB Output is correct
10 Correct 28 ms 9408 KB Output is correct
11 Correct 34 ms 10392 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 28 ms 9488 KB Output is correct
19 Correct 38 ms 10352 KB Output is correct
20 Correct 28 ms 8612 KB Output is correct
21 Correct 33 ms 9340 KB Output is correct
22 Correct 28 ms 8644 KB Output is correct
23 Correct 32 ms 9080 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 17 ms 5600 KB Output is correct
27 Correct 13 ms 4624 KB Output is correct
28 Correct 33 ms 8080 KB Output is correct
29 Correct 29 ms 8068 KB Output is correct
30 Correct 30 ms 8060 KB Output is correct
31 Correct 32 ms 8060 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 1 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 15 ms 4180 KB Output is correct
49 Correct 17 ms 4460 KB Output is correct
50 Correct 16 ms 4452 KB Output is correct
51 Correct 16 ms 4392 KB Output is correct
52 Correct 14 ms 4340 KB Output is correct
53 Correct 27 ms 6156 KB Output is correct
54 Correct 4 ms 2900 KB Output is correct
55 Correct 10 ms 3644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 4 ms 2900 KB Output is correct
58 Correct 3 ms 2808 KB Output is correct
59 Correct 75 ms 10948 KB Output is correct
60 Correct 93 ms 13712 KB Output is correct
61 Correct 112 ms 13092 KB Output is correct
62 Correct 93 ms 13088 KB Output is correct
63 Correct 86 ms 14612 KB Output is correct
64 Correct 97 ms 13076 KB Output is correct
65 Correct 94 ms 13076 KB Output is correct
66 Correct 38 ms 6864 KB Output is correct
67 Correct 95 ms 13976 KB Output is correct
68 Correct 30 ms 8056 KB Output is correct
69 Correct 30 ms 6484 KB Output is correct
70 Correct 62 ms 10480 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 1 ms 2644 KB Output is correct
73 Correct 1 ms 2644 KB Output is correct
74 Correct 1 ms 2644 KB Output is correct
75 Correct 2 ms 2644 KB Output is correct
76 Correct 1 ms 2644 KB Output is correct
77 Correct 3 ms 2644 KB Output is correct
78 Correct 3 ms 2648 KB Output is correct
79 Correct 2 ms 2644 KB Output is correct
80 Correct 3 ms 2644 KB Output is correct
81 Correct 35 ms 7028 KB Output is correct
82 Correct 76 ms 10572 KB Output is correct
83 Correct 65 ms 10432 KB Output is correct
84 Correct 109 ms 14252 KB Output is correct
85 Correct 105 ms 14100 KB Output is correct
86 Correct 109 ms 14456 KB Output is correct
87 Correct 127 ms 14608 KB Output is correct
88 Correct 1 ms 2644 KB Output is correct
89 Correct 104 ms 14612 KB Output is correct
90 Correct 101 ms 14128 KB Output is correct
91 Correct 96 ms 13772 KB Output is correct