Submission #1076218

# Submission time Handle Problem Language Result Execution time Memory
1076218 2024-08-26T11:51:37 Z vjudge1 Catfish Farm (IOI22_fish) C++17
0 / 100
54 ms 14004 KB
#include "fish.h"

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vll = vector<ll>;

struct AIB {
    int n;
    bool rev;
    vll V;

    AIB(int N, bool RV) : n(N + 1), rev(RV), V(N + 1, 0) {}

    void update(int p, ll v) {
        if(rev) p = n - p - 1;
        ++p;
        while(p < n) {
            V[p] = max(V[p], v);
            p += p & -p;
        }
    }

    ll query(int p) {
        if(rev) p = n - p - 1;
        ++p;
        ll re = 0;
        while(p) {
            re = max(re, V[p]);
            p -= p & -p;
        }
        return re;
    }
};

ll max_weights(int n, int m, vi X, vi Y, vi W) {
    vector<vector<ii> > A(n);
    for(int i = 0; i < m; ++i) 
        A[X[i]].push_back({Y[i], W[i]});
    for(int i = 0; i < n; ++i) {
        sort(A[i].begin(), A[i].end());
    }

    vll DP_tot(n, 0), DP0(n, 0), DP1(n, 0);

    AIB MaPre(n, 0), MaSuf(n, 1);

    ll re = 0;
    for(int i = 0; i < n; ++i) {
        ll rez_min = 0;
        if(i > 1) rez_min = DP_tot[i - 2];


        reverse(A[i].begin(), A[i].end());
        if(i + 1 < n) {
            for(auto [y, w] : A[i]) { /// urcam, facem 0
                ll re0 = rez_min;
                if(MaPre.query(y - 1) > re0) re0 = MaPre.query(y - 1);
                if(MaSuf.query(y + 1) > re0) re0 = MaSuf.query(y + 1);

                re0 += w;

                MaPre.update(y, re0);
                DP0[i] = max(DP0[i], re0);
            }
        }

        reverse(A[i].begin(), A[i].end());
        if(i) {
            for(auto [y, w] : A[i]) {
                ll re1 = rez_min;
                if(MaSuf.query(y + 1) > re1) re1 = MaSuf.query(y + 1);

                re1 += w;

                MaSuf.update(y, re1);
                MaPre.update(y, re1);
                DP1[i] = max(DP1[i], re1);
            }
        }

        DP_tot[i] = max(DP0[i], DP1[i]);
        if(i) DP_tot[i] = max(DP_tot[i], DP_tot[i - 1]);
        re = max(re, DP_tot[i]);
    }
    return re;
}
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 9924 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '999990243'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 54 ms 14004 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '1999984072'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Incorrect 25 ms 9944 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '94207210638'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '94207210638'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '94207210638'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Incorrect 25 ms 9944 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 9924 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '999990243'
2 Halted 0 ms 0 KB -