Submission #1032218

# Submission time Handle Problem Language Result Execution time Memory
1032218 2024-07-23T13:25:34 Z Mr_Husanboy Catfish Farm (IOI22_fish) C++17
35 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long

template<typename T>
int len(T &a){
    return a.size();
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
struct SegmentTree{

    //To change
    struct Node{
        //defaults
        ll mn = 0, add = 0; bool marked = false;
        void apply(ll val){
            mn += val;
            add += val;
            marked = true;
        }
    };

    void push(int x){
        if(t[x].marked){
            t[x << 1].apply(t[x].add);
            t[x << 1 | 1].apply(t[x].add);
            t[x].add = 0; t[x].marked = false;
        }
    }

    Node merge(Node a, Node b){
        Node res;
        if(a.mn > b.mn){
            res.mn = a.mn;
        }else{
            res.mn = b.mn;
        }
        return res;
    }
    Node neutral;
    vector<Node> t;
    int n;

    //construction

    void init(int _n){
        n = _n;
        t.assign(4 * n, neutral);
    }

    void build(vector<int> &a, int x, int lx, int rx){
        if(lx == rx){
            t[x].mn = a[lx];
            return;
        }
        int mx = (lx + rx) >> 1;
        build(a, x << 1, lx, mx);
        build(a, x << 1 | 1, mx + 1, rx);
        t[x] = merge(t[x << 1], t[x << 1 | 1]);
    }

    void upd(int x, int lx, int rx, int l, int r, ll val){
        if(rx < l || r < lx) return;
        if(l <= lx && rx <= r){
            t[x].apply(val); return;
        }
        push(x);
        int mx = (lx + rx) >> 1;
        upd(x << 1, lx, mx, l, r, val);
        upd(x << 1 | 1, mx + 1, rx, l, r, val);
        t[x] = merge(t[x << 1], t[x << 1 | 1]);
    }

    Node get(int x, int lx, int rx, int l, int r){
        if(rx < l || r < lx){
            return neutral;
        }
        if(l <= lx && rx <= r){
            return t[x];
        }
        push(x);
        int mx = (lx + rx) >> 1;
        return merge(get(x << 1, lx, mx, l, r), get(x << 1 | 1, mx + 1, rx, l, r));
    }

    // lessen

    void build(vector<int> &a){
        int sz = len(a);
        init(sz);
        build(a, 1, 0, n - 1);
    }

    void upd(int l, int r, ll val){
        upd(1, 0, n - 1, l, r, val);
    }

    Node get(int l, int r){
        return get(1, 0, n - 1, l, r);
    }
};


long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
                      std::vector<int> w) {
    vector<vector<ll>> s(n, vector<ll>(n + 1));
    for(int i = 0; i < m; i ++) s[x[i]][y[i] + 1] = w[i];
    for(int i = 0; i < n; i ++){
        for(int j = 1; j <= n; j ++) s[i][j] += s[i][j - 1];//, cout << s[i][j]<< ' ';
            // cout << endl;
    }
    int h = n;
    vector dp(h + 1, vector(h + 1, 0ll));

    for(int i = 0; i <= h; i ++){
        for(int j = 0; j <= i; j ++){
            dp[i][j] = s[1][i] - s[1][j];
        }
        for(int j = i + 1; j <= h; j ++){
            dp[i][j] = s[0][j] - s[0][i];
        }
    }

    for(int c = 2; c < n; c ++){
        vector tdp(h + 1, vector(h + 1, 0ll));
        for(int i = 0; i <= h; i ++){
            ll mx = 0;
            for(int j = 0; j <= h; j ++){
                mx = max(mx, dp[j][i]);
            }
            for(int j = 0; j <= i; j ++){
                tdp[i][j] = s[c][i] - s[c][j] + mx;
            }
            mx = 0;
            for(int j = 0; j <= i; j ++) mx = max(mx, dp[j][i]);
            priority_queue<ll> q;
            ll mx2 = 0;
            q.push(dp[i][i]);
            vector<ll> suf(h + 1);
            for(int j = h; j > i; j --){
                mx2 = max(mx2, dp[j][i]);
                suf[j] = mx2;
            }

            for(int j = i + 1; j <= h; j ++){
                tdp[i][j] = mx + s[c - 1][j] - s[c - 1][i];
                tdp[i][j] = max(tdp[i][j], suf[j]);
                tdp[i][j] = max(tdp[i][j], q.top() + s[c - 1][j] - s[c - 1][i]);
                q.push(dp[j][i] - s[c - 1][j] - s[c - 1][i]);
            }
        }
        swap(tdp, dp);
    }

    ll ans = 0;

    for(int i = 0; i <= h; i ++){
        ans = max(ans, *max_element(all(dp[i])));
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 861 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 842 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 803 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 440 KB Output is correct
9 Correct 19 ms 860 KB Output is correct
10 Correct 188 ms 2636 KB Output is correct
11 Correct 18 ms 860 KB Output is correct
12 Correct 144 ms 2396 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 159 ms 2596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 440 KB Output is correct
9 Correct 19 ms 860 KB Output is correct
10 Correct 188 ms 2636 KB Output is correct
11 Correct 18 ms 860 KB Output is correct
12 Correct 144 ms 2396 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 159 ms 2596 KB Output is correct
15 Correct 141 ms 2400 KB Output is correct
16 Correct 3 ms 608 KB Output is correct
17 Correct 191 ms 4428 KB Output is correct
18 Correct 183 ms 4432 KB Output is correct
19 Correct 146 ms 4192 KB Output is correct
20 Correct 155 ms 4412 KB Output is correct
21 Correct 157 ms 4184 KB Output is correct
22 Correct 169 ms 6236 KB Output is correct
23 Correct 192 ms 2912 KB Output is correct
24 Correct 193 ms 3716 KB Output is correct
25 Correct 149 ms 2624 KB Output is correct
26 Correct 188 ms 2912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 440 KB Output is correct
9 Correct 19 ms 860 KB Output is correct
10 Correct 188 ms 2636 KB Output is correct
11 Correct 18 ms 860 KB Output is correct
12 Correct 144 ms 2396 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 159 ms 2596 KB Output is correct
15 Correct 141 ms 2400 KB Output is correct
16 Correct 3 ms 608 KB Output is correct
17 Correct 191 ms 4428 KB Output is correct
18 Correct 183 ms 4432 KB Output is correct
19 Correct 146 ms 4192 KB Output is correct
20 Correct 155 ms 4412 KB Output is correct
21 Correct 157 ms 4184 KB Output is correct
22 Correct 169 ms 6236 KB Output is correct
23 Correct 192 ms 2912 KB Output is correct
24 Correct 193 ms 3716 KB Output is correct
25 Correct 149 ms 2624 KB Output is correct
26 Correct 188 ms 2912 KB Output is correct
27 Execution timed out 1024 ms 212300 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 803 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 861 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -