Submission #990453

# Submission time Handle Problem Language Result Execution time Memory
990453 2024-05-30T12:50:33 Z hariaakas646 Catfish Farm (IOI22_fish) C++17
9 / 100
608 ms 109100 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

int n, m;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    n = N;
    m = M;
    vector<map<int, lli>> grid(n);
    frange(i, m) {
        grid[X[i]][Y[i]+1] = W[i];
    }
    frange(i, n) grid[i][0] = grid[i][2e9] = 0;

    vector<map<int, lli>> dp1(n), dp2(n);
    dp1[0][0] = 0;
    dp1[0][2e9] = 0;
    for(auto p : grid[0]) {
        dp2[0][p.f] = p.s;
        auto it = dp2[0].find(p.f);
        if(it != dp2[0].begin())
            dp2[0][p.f] += (*prev(it)).s;
    }

    forr(i, 1, n) {
        lli ma = 0;
        for(auto p : dp1[i-1]) ma = max(ma, p.s);
        deque<lli> dq;
        lli tot = 0;
        for(auto p : grid[i]) {
            
            tot += p.s;
            auto it = dp2[i-1].lower_bound(p.f);
            lli v2 = 2e9+1;
            auto it2 = grid[i].upper_bound(p.f);
            if(it2 != grid[i].end()) v2 = (*it2).f;

            while(it != dp2[i-1].end() && (*it).f < v2) {
                lli v = (*it).s - tot;
                while(dq.size() && dq.back() <= v) dq.pop_back();
                dq.pb(v);
                it++;
            }
            if(dq.size())
                dp2[i][p.s] = dq.front() + tot; 
            
            dp2[i][p.s] = max(dp2[i][p.s], ma + tot);
            
        }
        tot = 0;
        dq = {};
        auto it = grid[i].end();
        while(it != grid[i].begin()) {
            it--;
            auto p= *it;
            dp1[i][p.f] = 0;
            auto it2 = dp2[i-1].upper_bound(p.f);
            if(it2 != dp2[i-1].begin()) {
                it2--;
                dp1[i][p.f] = (*it2).s;
            }
            // printf("%d %d\n", i, p.f);
            if(dq.size()) {
                dp1[i][p.f] = max(dp1[i][p.f], dq.front() + tot);
                // printf("%d %d %lld\n", i, p.f, dq.front() + tot);
            }
            it2 = dp1[i-1].lower_bound(p.f);
            lli v2 = 2e9+1;
            auto it3 = grid[i].upper_bound(p.f);
            if(it3 != grid[i].end()) v2 = (*it3).f;
            while(it2 != dp1[i-1].end() && (*it2).f < v2) {
                lli v = (*it2).s - tot;
                while(dq.size() && dq.back() <= v) dq.pop_back();
                dq.pb(v);
                it2++;
            }
            
            tot += p.s;
        }
    }   
    lli ma = 0;
    for(auto p : dp1[n-1]) ma = max(ma, p.s);
    return ma;
}
# Verdict Execution time Memory Grader output
1 Correct 119 ms 53088 KB Output is correct
2 Correct 135 ms 60476 KB Output is correct
3 Correct 44 ms 45648 KB Output is correct
4 Correct 44 ms 45648 KB Output is correct
5 Correct 608 ms 109100 KB Output is correct
6 Correct 275 ms 93540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 307 ms 70424 KB Output is correct
3 Correct 357 ms 81828 KB Output is correct
4 Correct 111 ms 53076 KB Output is correct
5 Correct 135 ms 60500 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 45 ms 45624 KB Output is correct
11 Correct 44 ms 45772 KB Output is correct
12 Correct 189 ms 59736 KB Output is correct
13 Correct 220 ms 68628 KB Output is correct
14 Correct 137 ms 57232 KB Output is correct
15 Correct 163 ms 63568 KB Output is correct
16 Correct 157 ms 57088 KB Output is correct
17 Correct 161 ms 63572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 45656 KB Output is correct
2 Correct 43 ms 45660 KB Output is correct
3 Incorrect 71 ms 52560 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 45656 KB Output is correct
2 Correct 43 ms 45660 KB Output is correct
3 Incorrect 71 ms 52560 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 119 ms 53088 KB Output is correct
2 Correct 135 ms 60476 KB Output is correct
3 Correct 44 ms 45648 KB Output is correct
4 Correct 44 ms 45648 KB Output is correct
5 Correct 608 ms 109100 KB Output is correct
6 Correct 275 ms 93540 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 307 ms 70424 KB Output is correct
9 Correct 357 ms 81828 KB Output is correct
10 Correct 111 ms 53076 KB Output is correct
11 Correct 135 ms 60500 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 45 ms 45624 KB Output is correct
17 Correct 44 ms 45772 KB Output is correct
18 Correct 189 ms 59736 KB Output is correct
19 Correct 220 ms 68628 KB Output is correct
20 Correct 137 ms 57232 KB Output is correct
21 Correct 163 ms 63568 KB Output is correct
22 Correct 157 ms 57088 KB Output is correct
23 Correct 161 ms 63572 KB Output is correct
24 Correct 43 ms 45656 KB Output is correct
25 Correct 43 ms 45660 KB Output is correct
26 Incorrect 71 ms 52560 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742'
27 Halted 0 ms 0 KB -