Submission #699065

# Submission time Handle Problem Language Result Execution time Memory
699065 2023-02-15T13:49:31 Z dxz05 Catfish Farm (IOI22_fish) C++17
9 / 100
853 ms 77560 KB
// #pragma GCC optimize("Ofast,O2,O3")
// #pragma GCC target("avx,avx2")

#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define MP make_pair

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vector<vector<pair<int, int>>> fish(N);
    vector<vector<ll>> sum(N);

    int MaxL = 10;

    vector<vector<ll>> pref(N, vector<ll>(MaxL + 1, 0));

    for (int i = 0; i < M; i++){
        ++Y[i];
        fish[X[i]].emplace_back(Y[i], W[i]);
        pref[X[i]][Y[i]] += W[i];
    }

    for (int i = 0; i < N; i++){
        for (int j = 1; j <= MaxL; j++) pref[i][j] += pref[i][j - 1];

        sort(fish[i].begin(), fish[i].end());
        int k = (int)fish[i].size();
        sum[i].resize(k);
        for (int j = 0; j < k; j++){
            sum[i][j] = fish[i][j].second;
            if (j > 0) sum[i][j] += sum[i][j - 1];
        }
    }

    function<ll(int, int, int)> get_sum = [&](int i, int l, int r){ // sum of fish with X = i, l <= Y <= r
        r = min(r, MaxL);
        l = max(l, 1);
        if (l > r) return 0ll;
        return pref[i][r] - pref[i][l - 1];

        int pl = lower_bound(fish[i].begin(), fish[i].end(), MP(l, 0)) - fish[i].begin();
        int pr = lower_bound(fish[i].begin(), fish[i].end(), MP(r + 1, 0)) - fish[i].begin() - 1;
        if (pl > pr) return 0ll;
        return sum[i][pr] - (pl > 0 ? sum[i][pl - 1] : 0ll);
    };

    vector<vector<ll>> dpl(N, vector<ll>(MaxL + 1, 0));
    for (int i = 1; i < N; i++){
        for (int l = 0; l <= MaxL; l++){
            for (int j = 0; j <= MaxL; j++){
                dpl[i][l] = max(dpl[i][l], dpl[i - 1][j] + get_sum(i - 1, j + 1, l));
            }
            for (int j = 0; j <= MaxL; j++){
                if (i >= 2) dpl[i][l] = max(dpl[i][l], dpl[i - 2][j] + get_sum(i - 1, 1, max(l, j)));
            }
        }
    }

    vector<vector<ll>> dpr(N, vector<ll>(MaxL + 1, 0));
    for (int i = N - 2; i >= 0; i--){
        for (int l = 0; l <= MaxL; l++){
            for (int j = 0; j <= MaxL; j++){
                dpr[i][l] = max(dpr[i][l], dpr[i + 1][j] + get_sum(i + 1, j + 1, l));
            }
            for (int j = 0; j <= MaxL; j++){
                if (i + 2 < N) dpr[i][l] = max(dpr[i][l], dpr[i + 2][j] + get_sum(i + 1, 1, max(l, j)));
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < N; i++){
        for (int l = 0; l <= MaxL; l++){
            res = max(res, dpl[i][l] + dpr[i][l]);
        }
    }

    for (int i = 0; i + 1 < N; i++){
        for (int l1 = 0; l1 <= MaxL; l1++){
            for (int l2 = 0; l2 <= MaxL; l2++){
                ll cur = dpl[i][l1] + dpr[i + 1][l2];

                cur += get_sum(i, l1 + 1, l2);
                cur += get_sum(i + 1, l2 + 1, l1);

                res = max(res, cur);
            }
        }
    }

    for (int i = 1; i + 1 < N; i++){
        for (int l1 = 0; l1 <= MaxL; l1++){
            for (int l2 = 0; l2 <= MaxL; l2++){
                ll cur = dpl[i - 1][l1] + dpr[i + 1][l2];

                cur += get_sum(i, 1, max(l1, l2));

                res = max(res, cur);
            }
        }
    }

    for (int i = 1; i + 2 < N; i++){
        for (int l1 = 0; l1 <= MaxL; l1++){
            for (int l2 = 0; l2 <= MaxL; l2++){
                ll cur = dpl[i - 1][l1] + dpr[i + 2][l2];

                cur += get_sum(i, 1, l1);
                cur += get_sum(i + 1, 1, l2);

                res = max(res, cur);
            }
        }
    }

    return res;
}
# Verdict Execution time Memory Grader output
1 Runtime error 735 ms 71268 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 785 ms 77560 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 760 ms 40208 KB Output is correct
2 Correct 748 ms 40132 KB Output is correct
3 Correct 743 ms 40852 KB Output is correct
4 Correct 770 ms 43376 KB Output is correct
5 Correct 853 ms 48832 KB Output is correct
6 Correct 825 ms 48832 KB Output is correct
7 Correct 844 ms 48824 KB Output is correct
8 Correct 830 ms 48832 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Incorrect 2 ms 340 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '278323186206'
12 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Incorrect 2 ms 340 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '278323186206'
12 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Incorrect 2 ms 340 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '278323186206'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 760 ms 40208 KB Output is correct
2 Correct 748 ms 40132 KB Output is correct
3 Correct 743 ms 40852 KB Output is correct
4 Correct 770 ms 43376 KB Output is correct
5 Correct 853 ms 48832 KB Output is correct
6 Correct 825 ms 48832 KB Output is correct
7 Correct 844 ms 48824 KB Output is correct
8 Correct 830 ms 48832 KB Output is correct
9 Runtime error 53 ms 38436 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 735 ms 71268 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -