Submission #639558

# Submission time Handle Problem Language Result Execution time Memory
639558 2022-09-10T15:38:40 Z SlavicG Catfish Farm (IOI22_fish) C++17
0 / 100
873 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) {
        len[i].push_back(n);
        len[i].push_back(0);
        sort(len[i].begin(), 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());

            if(curlen) dp[i][0][curlen] = max(dp[i][0][curlen], p[i - 1][curlen - 1] + it1->second);
            if(curlen) dp[i][1][curlen] = max(dp[i][1][curlen], it2->second - p[i][curlen - 1]);
        }
    }
    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 873 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 763 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 744 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 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 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 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 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 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 744 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 873 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -