Submission #626166

# Submission time Handle Problem Language Result Execution time Memory
626166 2022-08-11T09:19:53 Z mraron Catfish Farm (IOI22_fish) C++17
40 / 100
1000 ms 19656 KB
#include "fish.h"

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

using ll = long long ;

#define sz(x) (int)(x).size()
#define xx first
#define yy second

//dp0[i][j] -> i. oszlopban j-ig elé építve piert max hogyha mindkettő szomszédosnál magasabb
//dp1[i][j] -> i. oszlopban j-ig elé építve piert max hogyha bal oldali számít
//dp2[i][j] -> i. oszlopban j-ig elé építve piert max hogyha jobb oldali számít


long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    vector<vector<pair<int,ll>>> lst(N+2, vector<pair<int,ll>>());
    for(int i=0;i<M;++i) {
        lst[X[i]].push_back({Y[i], W[i]});
    }

    for(int i=0;i<=N+1;++i) lst[i].push_back({N+10,0});
    for(auto& i:lst) sort(i.begin(), i.end());
    for(auto& i:lst) 
        for(int j=1;j<sz(i);++j) i[j].yy+=i[j-1].yy;
    
    auto get_sum=[&](int x, int l, int r) -> ll {
        if(l>r) return 0;
        //~ ll sum=0;
        //~ for(int i=0;i<sz(lst[x]);++i) {
            //~ if(l<=lst[x][i].xx && lst[x][i].xx<=r) sum+=lst[x][i].yy;
        //~ }
        //~ cerr<<x<<","<<l<<","<<r<<" -> "<<sum<<"\n";
        auto itL=lower_bound(lst[x].begin(), lst[x].end(), make_pair(l, 0LL));
        auto itR=lower_bound(lst[x].begin(), lst[x].end(), make_pair(r+1, 0LL));
        ll sum=(itR==lst[x].begin()?0:prev(itR)->yy)-(itL==lst[x].begin()?0:prev(itL)->yy);
        return sum;
    };
    
    
    vector<ll> dp0(lst[0].size());
    vector<ll> dp1(lst[0].size());
    vector<ll> dp2(lst[0].size());
    for(int i=1;i<N;++i) {
        vector<ll> ndp0(lst[i].size());
        vector<ll> ndp1(lst[i].size());
        vector<ll> ndp2(lst[i].size());
        
        //dp0
        for(int j=0;j<sz(lst[i]);++j) {
            for(int k=0;k<sz(lst[i-1]);++k) {
                ndp0[j]=max({ndp0[j], dp1[k], dp2[k]+get_sum(i-1, lst[i-1][k].xx, lst[i][j].xx-1)});
            }
        }
        
        //dp1
        for(int j=0;j<sz(lst[i]);++j) {
            for(int k=0;k<sz(lst[i-1]);++k) {
                ndp1[j]=max({ndp1[j], max(dp0[k],dp1[k])+get_sum(i, lst[i][j].xx, lst[i-1][k].xx-1)});
            }
        }
        
        //dp2
        for(int j=0;j<sz(lst[i]);++j) {
            for(int k=0;k<sz(lst[i-1]);++k) {
                ndp2[j]=max({ndp2[j], dp0[k], dp1[k], dp2[k]+get_sum(i-1, lst[i-1][k].xx, lst[i][j].xx-1)});
            }
        }
        //~ cerr<<i<<", 0: "; for(auto j:ndp0) cerr<<j<<" ";cerr<<"\n";
        //~ cerr<<i<<", 1: "; for(auto j:ndp1) cerr<<j<<" ";cerr<<"\n";
        //~ cerr<<i<<", 2: "; for(auto j:ndp2) cerr<<j<<" ";cerr<<"\n\n";
        dp0.swap(ndp0);
        dp1.swap(ndp1);
        dp2.swap(ndp2);
    }
    
    return max({
        *max_element(dp0.begin(), dp0.end()),
        *max_element(dp1.begin(), dp1.end()),
        *max_element(dp2.begin(), dp2.end())
    });
        
}

    
# Verdict Execution time Memory Grader output
1 Correct 55 ms 10176 KB Output is correct
2 Correct 71 ms 11968 KB Output is correct
3 Correct 16 ms 5716 KB Output is correct
4 Correct 22 ms 5716 KB Output is correct
5 Correct 221 ms 19656 KB Output is correct
6 Correct 158 ms 19516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1091 ms 15344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5716 KB Output is correct
2 Correct 15 ms 5716 KB Output is correct
3 Correct 39 ms 7504 KB Output is correct
4 Correct 31 ms 7260 KB Output is correct
5 Correct 63 ms 10552 KB Output is correct
6 Correct 59 ms 10572 KB Output is correct
7 Correct 55 ms 10572 KB Output is correct
8 Correct 56 ms 10592 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 10 ms 428 KB Output is correct
17 Correct 826 ms 2284 KB Output is correct
18 Correct 949 ms 2916 KB Output is correct
19 Correct 514 ms 2772 KB Output is correct
20 Correct 517 ms 2736 KB Output is correct
21 Correct 521 ms 2724 KB Output is correct
22 Execution timed out 1077 ms 5076 KB Time limit exceeded
23 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 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 10 ms 428 KB Output is correct
17 Correct 826 ms 2284 KB Output is correct
18 Correct 949 ms 2916 KB Output is correct
19 Correct 514 ms 2772 KB Output is correct
20 Correct 517 ms 2736 KB Output is correct
21 Correct 521 ms 2724 KB Output is correct
22 Execution timed out 1077 ms 5076 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5716 KB Output is correct
2 Correct 15 ms 5716 KB Output is correct
3 Correct 39 ms 7504 KB Output is correct
4 Correct 31 ms 7260 KB Output is correct
5 Correct 63 ms 10552 KB Output is correct
6 Correct 59 ms 10572 KB Output is correct
7 Correct 55 ms 10572 KB Output is correct
8 Correct 56 ms 10592 KB Output is correct
9 Correct 58 ms 10564 KB Output is correct
10 Correct 54 ms 8384 KB Output is correct
11 Correct 133 ms 16396 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 16 ms 5716 KB Output is correct
19 Correct 15 ms 5716 KB Output is correct
20 Correct 15 ms 5776 KB Output is correct
21 Correct 15 ms 5716 KB Output is correct
22 Correct 66 ms 10320 KB Output is correct
23 Correct 127 ms 16344 KB Output is correct
24 Correct 115 ms 16344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 10176 KB Output is correct
2 Correct 71 ms 11968 KB Output is correct
3 Correct 16 ms 5716 KB Output is correct
4 Correct 22 ms 5716 KB Output is correct
5 Correct 221 ms 19656 KB Output is correct
6 Correct 158 ms 19516 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Execution timed out 1091 ms 15344 KB Time limit exceeded
9 Halted 0 ms 0 KB -