Submission #1055723

# Submission time Handle Problem Language Result Execution time Memory
1055723 2024-08-13T04:28:56 Z vjudge1 Catfish Farm (IOI22_fish) C++17
84 / 100
1000 ms 150608 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#pragma GCC optimize(2)
set<int>fishies[100010];
map<int,ll>fishiess[100010];
map<int,ll>dp[100010][2];
int N;
inline ll ones(int col,int len){
    auto it=fishiess[col].upper_bound(len);
    if(it==fishiess[col].begin())return 0;
    return (--it)->second;
}
struct segtree{
    ll T[1<<18];
    ll query(int i,int l,int r,int ll,int rr){
        if(l>rr||ll>r) return -1e18;
        if(ll<=l&&r<=rr) return T[i];
        return max(query(i*2,l,l+r>>1,ll,rr),
                query(i*2+1,l+r+2>>1,r,ll,rr));
    }
    void upd(int i,int l,int r,int p,ll x){
        T[i]=max(T[i],x);if(l==r)return;
        if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
        else upd(i*2+1,l+r+2>>1,r,p,x);
    }
};
struct a_data_type{
    segtree Sec,First,Overal,Third;
    inline ll sec(int pos){
        return Sec.query(1,0,N,pos,N);
    }
    inline ll first(int pos){
        return First.query(1,0,N,0,pos);
    }
    inline ll overal(int pos){
        return Overal.query(1,0,N,pos,N);
    }
    inline ll third(int pos){
        return Third.query(1,0,N,0,pos);
    }
    set<int>prv;
    void init(int i) {
        for(auto j:prv)
            Overal.upd(1,0,N,j,0),
            First.upd(1,0,N,j,0),
            Sec.upd(1,0,N,j,0),
            Third.upd(1,0,N,j,0);
        prv.clear();
        for(auto j:fishies[i]){
            prv.insert(--j);
            ll A=dp[i][0][j];
            ll B=dp[i][1][j];
            Overal.upd(1,0,N,j,max(A,B));
            First.upd(1,0,N,j,max(A,B)-ones(i+1,j));
            Sec.upd(1,0,N,j,dp[i][0][j]);
            Third.upd(1,0,N,j,dp[i][1][j]-ones(i,j)-ones(i+1,j));
        }
    }
} likehell[2];
ll max_weights(int N_,int M,vector<int> X,vector<int> Y,vector<int> W) {
    N=N_;
    for(int i=0;i<M;i++)
        fishies[X[i]+1].insert(Y[i]+1),
        fishiess[X[i]+1][Y[i]+1]=W[i];
    for(int i=1;i<=N;i++){
        fishiess[i][N+1];
        auto it=++fishiess[i].begin();
        while(it!=fishiess[i].end())
            it->second+=prev(it)->second,it++;
    }
    for(int i=1;i<=N;i++)
        fishies[i].insert(1),
        fishies[i].insert(N+1);
    fishies[N+1].insert(0);
    for(auto i:fishies[1])
        dp[1][1][i-1]=ones(2,i-1);
    int b=0;
    likehell[b].init(1);
    for(int i=2;i<=N;i++){
        for(auto rw:fishies[i]) {
            ll cons=ones(i+1,rw-1)+ones(i-1,rw-1);
            ll F=likehell[!b].first(rw-1);
            ll S=likehell[!b].overal(rw)-ones(i-1,rw-1);
            dp[i][1][rw-1]=cons+max(F,S);
        }
        for(auto rw2:fishies[i]){
            ll cons=ones(i+1,rw2-1)+ones(i-1,rw2-1);
            ll F=likehell[b].third(rw2-1);
            ll S=likehell[b].overal(rw2);
            dp[i][1][rw2-1]=max(dp[i][1][rw2-1],F+cons);
            dp[i][0][rw2-1]=S-ones(i,rw2-1)-ones(i-1,rw2-1)+cons;
        }
        for(auto rw2:fishies[i]) {
            ll K=likehell[b].sec(rw2-1)-ones(i,rw2-1);
            dp[i][0][rw2-1]=max(dp[i][0][rw2-1],ones(i+1,rw2-1)+K);
        }
        b=!b;
        likehell[b].init(i);
    }
    return likehell[b].overal(0);
}

Compilation message

fish.cpp: In member function 'll segtree::query(int, int, int, int, int)':
fish.cpp:20:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |         return max(query(i*2,l,l+r>>1,ll,rr),
      |                                ~^~
fish.cpp:21:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |                 query(i*2+1,l+r+2>>1,r,ll,rr));
      |                             ~~~^~
fish.cpp: In member function 'void segtree::upd(int, int, int, int, ll)':
fish.cpp:25:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |            ~^~
fish.cpp:25:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |                                ~^~
fish.cpp:26:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |         else upd(i*2+1,l+r+2>>1,r,p,x);
      |                        ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 248 ms 90708 KB Output is correct
2 Correct 303 ms 100688 KB Output is correct
3 Correct 134 ms 63952 KB Output is correct
4 Correct 156 ms 64084 KB Output is correct
5 Correct 940 ms 150608 KB Output is correct
6 Correct 768 ms 147792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 529 ms 117864 KB Output is correct
3 Correct 662 ms 132688 KB Output is correct
4 Correct 246 ms 90808 KB Output is correct
5 Correct 291 ms 100692 KB Output is correct
6 Correct 3 ms 23128 KB Output is correct
7 Correct 3 ms 23128 KB Output is correct
8 Correct 3 ms 23132 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 133 ms 63972 KB Output is correct
11 Correct 129 ms 64076 KB Output is correct
12 Correct 312 ms 86960 KB Output is correct
13 Correct 371 ms 95972 KB Output is correct
14 Correct 298 ms 88996 KB Output is correct
15 Correct 332 ms 95604 KB Output is correct
16 Correct 284 ms 89428 KB Output is correct
17 Correct 313 ms 95596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 64088 KB Output is correct
2 Correct 137 ms 64080 KB Output is correct
3 Correct 151 ms 64596 KB Output is correct
4 Correct 142 ms 67156 KB Output is correct
5 Correct 176 ms 72528 KB Output is correct
6 Correct 180 ms 72704 KB Output is correct
7 Correct 202 ms 72544 KB Output is correct
8 Correct 198 ms 72532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 23168 KB Output is correct
3 Correct 2 ms 23152 KB Output is correct
4 Correct 3 ms 23232 KB Output is correct
5 Correct 2 ms 23132 KB Output is correct
6 Correct 3 ms 23132 KB Output is correct
7 Correct 2 ms 23132 KB Output is correct
8 Correct 3 ms 23164 KB Output is correct
9 Correct 3 ms 23388 KB Output is correct
10 Correct 4 ms 23924 KB Output is correct
11 Correct 4 ms 23388 KB Output is correct
12 Correct 4 ms 23644 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 4 ms 23424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 23168 KB Output is correct
3 Correct 2 ms 23152 KB Output is correct
4 Correct 3 ms 23232 KB Output is correct
5 Correct 2 ms 23132 KB Output is correct
6 Correct 3 ms 23132 KB Output is correct
7 Correct 2 ms 23132 KB Output is correct
8 Correct 3 ms 23164 KB Output is correct
9 Correct 3 ms 23388 KB Output is correct
10 Correct 4 ms 23924 KB Output is correct
11 Correct 4 ms 23388 KB Output is correct
12 Correct 4 ms 23644 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 4 ms 23424 KB Output is correct
15 Correct 3 ms 23384 KB Output is correct
16 Correct 6 ms 23640 KB Output is correct
17 Correct 86 ms 35112 KB Output is correct
18 Correct 85 ms 34788 KB Output is correct
19 Correct 81 ms 34960 KB Output is correct
20 Correct 81 ms 34900 KB Output is correct
21 Correct 78 ms 34896 KB Output is correct
22 Correct 179 ms 46416 KB Output is correct
23 Correct 16 ms 25688 KB Output is correct
24 Correct 52 ms 31120 KB Output is correct
25 Correct 4 ms 23896 KB Output is correct
26 Correct 15 ms 25432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 23168 KB Output is correct
3 Correct 2 ms 23152 KB Output is correct
4 Correct 3 ms 23232 KB Output is correct
5 Correct 2 ms 23132 KB Output is correct
6 Correct 3 ms 23132 KB Output is correct
7 Correct 2 ms 23132 KB Output is correct
8 Correct 3 ms 23164 KB Output is correct
9 Correct 3 ms 23388 KB Output is correct
10 Correct 4 ms 23924 KB Output is correct
11 Correct 4 ms 23388 KB Output is correct
12 Correct 4 ms 23644 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 4 ms 23424 KB Output is correct
15 Correct 3 ms 23384 KB Output is correct
16 Correct 6 ms 23640 KB Output is correct
17 Correct 86 ms 35112 KB Output is correct
18 Correct 85 ms 34788 KB Output is correct
19 Correct 81 ms 34960 KB Output is correct
20 Correct 81 ms 34900 KB Output is correct
21 Correct 78 ms 34896 KB Output is correct
22 Correct 179 ms 46416 KB Output is correct
23 Correct 16 ms 25688 KB Output is correct
24 Correct 52 ms 31120 KB Output is correct
25 Correct 4 ms 23896 KB Output is correct
26 Correct 15 ms 25432 KB Output is correct
27 Correct 8 ms 25432 KB Output is correct
28 Correct 492 ms 79284 KB Output is correct
29 Correct 740 ms 102480 KB Output is correct
30 Correct 666 ms 102224 KB Output is correct
31 Correct 671 ms 102124 KB Output is correct
32 Correct 695 ms 100820 KB Output is correct
33 Correct 676 ms 102228 KB Output is correct
34 Correct 671 ms 102224 KB Output is correct
35 Correct 206 ms 54096 KB Output is correct
36 Correct 687 ms 102216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 64088 KB Output is correct
2 Correct 137 ms 64080 KB Output is correct
3 Correct 151 ms 64596 KB Output is correct
4 Correct 142 ms 67156 KB Output is correct
5 Correct 176 ms 72528 KB Output is correct
6 Correct 180 ms 72704 KB Output is correct
7 Correct 202 ms 72544 KB Output is correct
8 Correct 198 ms 72532 KB Output is correct
9 Correct 257 ms 101972 KB Output is correct
10 Correct 159 ms 61012 KB Output is correct
11 Correct 349 ms 98388 KB Output is correct
12 Correct 3 ms 23128 KB Output is correct
13 Correct 3 ms 23128 KB Output is correct
14 Correct 2 ms 23132 KB Output is correct
15 Correct 2 ms 23132 KB Output is correct
16 Correct 3 ms 23132 KB Output is correct
17 Correct 2 ms 23132 KB Output is correct
18 Correct 137 ms 64028 KB Output is correct
19 Correct 132 ms 63916 KB Output is correct
20 Correct 130 ms 64080 KB Output is correct
21 Correct 130 ms 63924 KB Output is correct
22 Correct 330 ms 101972 KB Output is correct
23 Correct 436 ms 114512 KB Output is correct
24 Correct 386 ms 116308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 90708 KB Output is correct
2 Correct 303 ms 100688 KB Output is correct
3 Correct 134 ms 63952 KB Output is correct
4 Correct 156 ms 64084 KB Output is correct
5 Correct 940 ms 150608 KB Output is correct
6 Correct 768 ms 147792 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 529 ms 117864 KB Output is correct
9 Correct 662 ms 132688 KB Output is correct
10 Correct 246 ms 90808 KB Output is correct
11 Correct 291 ms 100692 KB Output is correct
12 Correct 3 ms 23128 KB Output is correct
13 Correct 3 ms 23128 KB Output is correct
14 Correct 3 ms 23132 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 133 ms 63972 KB Output is correct
17 Correct 129 ms 64076 KB Output is correct
18 Correct 312 ms 86960 KB Output is correct
19 Correct 371 ms 95972 KB Output is correct
20 Correct 298 ms 88996 KB Output is correct
21 Correct 332 ms 95604 KB Output is correct
22 Correct 284 ms 89428 KB Output is correct
23 Correct 313 ms 95596 KB Output is correct
24 Correct 132 ms 64088 KB Output is correct
25 Correct 137 ms 64080 KB Output is correct
26 Correct 151 ms 64596 KB Output is correct
27 Correct 142 ms 67156 KB Output is correct
28 Correct 176 ms 72528 KB Output is correct
29 Correct 180 ms 72704 KB Output is correct
30 Correct 202 ms 72544 KB Output is correct
31 Correct 198 ms 72532 KB Output is correct
32 Correct 3 ms 23128 KB Output is correct
33 Correct 3 ms 23168 KB Output is correct
34 Correct 2 ms 23152 KB Output is correct
35 Correct 3 ms 23232 KB Output is correct
36 Correct 2 ms 23132 KB Output is correct
37 Correct 3 ms 23132 KB Output is correct
38 Correct 2 ms 23132 KB Output is correct
39 Correct 3 ms 23164 KB Output is correct
40 Correct 3 ms 23388 KB Output is correct
41 Correct 4 ms 23924 KB Output is correct
42 Correct 4 ms 23388 KB Output is correct
43 Correct 4 ms 23644 KB Output is correct
44 Correct 3 ms 23132 KB Output is correct
45 Correct 4 ms 23424 KB Output is correct
46 Correct 3 ms 23384 KB Output is correct
47 Correct 6 ms 23640 KB Output is correct
48 Correct 86 ms 35112 KB Output is correct
49 Correct 85 ms 34788 KB Output is correct
50 Correct 81 ms 34960 KB Output is correct
51 Correct 81 ms 34900 KB Output is correct
52 Correct 78 ms 34896 KB Output is correct
53 Correct 179 ms 46416 KB Output is correct
54 Correct 16 ms 25688 KB Output is correct
55 Correct 52 ms 31120 KB Output is correct
56 Correct 4 ms 23896 KB Output is correct
57 Correct 15 ms 25432 KB Output is correct
58 Correct 8 ms 25432 KB Output is correct
59 Correct 492 ms 79284 KB Output is correct
60 Correct 740 ms 102480 KB Output is correct
61 Correct 666 ms 102224 KB Output is correct
62 Correct 671 ms 102124 KB Output is correct
63 Correct 695 ms 100820 KB Output is correct
64 Correct 676 ms 102228 KB Output is correct
65 Correct 671 ms 102224 KB Output is correct
66 Correct 206 ms 54096 KB Output is correct
67 Correct 687 ms 102216 KB Output is correct
68 Correct 257 ms 101972 KB Output is correct
69 Correct 159 ms 61012 KB Output is correct
70 Correct 349 ms 98388 KB Output is correct
71 Correct 3 ms 23128 KB Output is correct
72 Correct 3 ms 23128 KB Output is correct
73 Correct 2 ms 23132 KB Output is correct
74 Correct 2 ms 23132 KB Output is correct
75 Correct 3 ms 23132 KB Output is correct
76 Correct 2 ms 23132 KB Output is correct
77 Correct 137 ms 64028 KB Output is correct
78 Correct 132 ms 63916 KB Output is correct
79 Correct 130 ms 64080 KB Output is correct
80 Correct 130 ms 63924 KB Output is correct
81 Correct 330 ms 101972 KB Output is correct
82 Correct 436 ms 114512 KB Output is correct
83 Correct 386 ms 116308 KB Output is correct
84 Execution timed out 1026 ms 149760 KB Time limit exceeded
85 Halted 0 ms 0 KB -