Submission #639561

# Submission time Handle Problem Language Result Execution time Memory
639561 2022-09-10T15:49:56 Z SlavicG Catfish Farm (IOI22_fish) C++17
35 / 100
1000 ms 2097152 KB
#include "fish.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll inf = 1e16;
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    vector<vector<ll>> p(n, vector<ll>(n, 0));
    vector<int> len[n];
    for(int i = 0; i < m; ++i) {
        p[x[i]][y[i]] += w[i];
        len[x[i]].push_back(y[i]);
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 1; j < n; ++j) {
            p[i][j] += p[i][j - 1];
        }
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= n; ++j) len[i].push_back(j);
        len[i].push_back(n);
        len[i].push_back(0);
        sort(len[i].begin(), len[i].end());
        len[i].erase(unique(len[i].begin(), len[i].end()), len[i].end());
    }
    map<ll, ll> dp[n + 1][2];
    for(int i = 0; i <= n; ++i) {
        dp[0][0][i] = dp[0][1][i] = 0;
    }

    //0 - increasing, 1 - decreasing
    for(int i = 1; i < n; ++i) {
        vector<pair<ll, ll>> mx0, mx1;
        for(ll lastlen: len[i - 1]) {
            dp[i][0][0] = max({dp[i][0][0], dp[i - 1][0][lastlen], dp[i - 1][1][lastlen]});
            dp[i][1][0] = max({dp[i][1][0], dp[i - 1][0][lastlen], dp[i - 1][1][lastlen]});

            ll cur = 0;
            if(!mx0.empty()) cur = mx0.back().second;
            cur = max(cur, dp[i - 1][0][lastlen] - (lastlen ? p[i - 1][lastlen - 1] : 0));
            mx0.push_back({lastlen, cur});
        }

        reverse(len[i - 1].begin(), len[i - 1].end());

        for(ll lastlen: len[i - 1]) {
            ll cur = 0;
            if(!mx1.empty()) cur = mx1.back().second;
            cur = max(cur, dp[i - 1][0][lastlen] + (lastlen ? p[i][lastlen - 1] : 0));
            cur = max(cur, dp[i - 1][1][lastlen] + (lastlen ? p[i][lastlen - 1] : 0));
            mx1.push_back({lastlen, cur});
        }
        reverse(mx1.begin(), mx1.end());
        for(ll curlen: len[i]) {
            auto it1 = upper_bound(mx0.begin(), mx0.end(), make_pair(curlen, LLONG_MAX));
            assert(it1 != mx0.begin()); --it1;
            auto it2 = lower_bound(mx1.begin(), mx1.end(), make_pair(curlen, LLONG_MIN));
            assert(it2 != mx1.end());

            dp[i][0][curlen] = max(dp[i][0][curlen], (curlen ? p[i - 1][curlen - 1] : 0) + it1->second);
            dp[i][1][curlen] = max(dp[i][1][curlen], it2->second - (curlen ? p[i][curlen - 1] : 0));
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; ++i) {
        ans = max({ans, dp[n - 1][0][i], dp[n - 1][1][i]});
    }
    return ans;
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
*/
# Verdict Execution time Memory Grader output
1 Runtime error 711 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 767 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 717 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 16 ms 3512 KB Output is correct
10 Correct 57 ms 12940 KB Output is correct
11 Correct 15 ms 3552 KB Output is correct
12 Correct 56 ms 12876 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 55 ms 12940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 16 ms 3512 KB Output is correct
10 Correct 57 ms 12940 KB Output is correct
11 Correct 15 ms 3552 KB Output is correct
12 Correct 56 ms 12876 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 55 ms 12940 KB Output is correct
15 Correct 58 ms 12876 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 71 ms 15108 KB Output is correct
18 Correct 72 ms 14960 KB Output is correct
19 Correct 69 ms 14620 KB Output is correct
20 Correct 73 ms 14668 KB Output is correct
21 Correct 69 ms 14664 KB Output is correct
22 Correct 82 ms 16964 KB Output is correct
23 Correct 56 ms 13088 KB Output is correct
24 Correct 64 ms 14024 KB Output is correct
25 Correct 55 ms 12944 KB Output is correct
26 Correct 62 ms 13068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 16 ms 3512 KB Output is correct
10 Correct 57 ms 12940 KB Output is correct
11 Correct 15 ms 3552 KB Output is correct
12 Correct 56 ms 12876 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 55 ms 12940 KB Output is correct
15 Correct 58 ms 12876 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 71 ms 15108 KB Output is correct
18 Correct 72 ms 14960 KB Output is correct
19 Correct 69 ms 14620 KB Output is correct
20 Correct 73 ms 14668 KB Output is correct
21 Correct 69 ms 14664 KB Output is correct
22 Correct 82 ms 16964 KB Output is correct
23 Correct 56 ms 13088 KB Output is correct
24 Correct 64 ms 14024 KB Output is correct
25 Correct 55 ms 12944 KB Output is correct
26 Correct 62 ms 13068 KB Output is correct
27 Execution timed out 1106 ms 244208 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 717 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 711 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -