Submission #629346

# Submission time Handle Problem Language Result Execution time Memory
629346 2022-08-14T11:41:53 Z jeff252 Catfish Farm (IOI22_fish) C++17
100 / 100
341 ms 23800 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=3e5+10;
const int SS=1<<17;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
vector<pair<int,int> > t[N];
struct tr{
    ll seg[(SS<<1)+10];
    void upd(int a,int b,ll x){
        for(a+=SS-1,b+=SS+1;(a>>1)!=(b>>1);a>>=1,b>>=1){
            if(!(a&1)) seg[a+1]=max(seg[a+1],x);
            if(b&1) seg[b-1]=max(seg[b-1],x);
        }
    }
    ll Query(int a){
        ll res=0;
        for(a+=SS;a>0;a>>=1) res=max(res,seg[a]);
        return res;
    }
};
tr dp1,dp2;
ll max_weights(int n,int m,vi x,vi y,vi w){
    for(int i=1;i<=(SS<<1);i++) dp1.seg[i]=0,dp2.seg[i]=0;
    for(int i=0;i<m;i++) t[x[i]+1].push_back({y[i]+1,w[i]});
    for(int i=1;i<=n;i++) sort(t[i].begin(),t[i].end());
    ll sum=0;
    for(int i=1;i<=n;i++){
        ll val=dp1.Query(n);
        dp1.upd(0,0,dp2.Query(1));
        int pop=0;
        for(auto [u,c]:t[i]){
            if(pop!=u-1) dp1.upd(pop+1,u-1,dp1.Query(pop));
            dp1.upd(u,u,dp1.Query(u-1)+(ll)c);
            pop=u;
            sum+=(ll)c;
        } 
        if(pop!=n) dp1.upd(pop+1,n,dp1.Query(pop));
        pop=n+1;
        reverse(t[i].begin(),t[i].end());
        if(i==1) continue;
        for(auto [u,c]:t[i]){
            if(pop!=u+1) dp2.upd(u+1,pop-1,dp2.Query(pop));
            dp2.upd(u,u,dp2.Query(u+1)+(ll)c);
            pop=u;
        } 
        if(pop!=1) dp2.upd(1,pop-1,dp2.Query(pop));
        dp2.upd(1,n+1,val);
    }
    return dp2.Query(1);
}
/*int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int n,m;
    cin>>n>>m;
    vi x,y,w;
    for(int i=1;i<=m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        x.push_back(a),y.push_back(b),w.push_back(c);
    } 
    cout<<max_weights(n,m,x,y,w)<<"\n";
}*/
# Verdict Execution time Memory Grader output
1 Correct 57 ms 14404 KB Output is correct
2 Correct 83 ms 15044 KB Output is correct
3 Correct 43 ms 11432 KB Output is correct
4 Correct 30 ms 11348 KB Output is correct
5 Correct 163 ms 21120 KB Output is correct
6 Correct 303 ms 23380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11348 KB Output is correct
2 Correct 113 ms 16832 KB Output is correct
3 Correct 157 ms 18244 KB Output is correct
4 Correct 66 ms 14764 KB Output is correct
5 Correct 85 ms 15300 KB Output is correct
6 Correct 9 ms 11348 KB Output is correct
7 Correct 6 ms 11476 KB Output is correct
8 Correct 6 ms 11348 KB Output is correct
9 Correct 6 ms 11428 KB Output is correct
10 Correct 30 ms 11428 KB Output is correct
11 Correct 27 ms 11348 KB Output is correct
12 Correct 58 ms 14900 KB Output is correct
13 Correct 89 ms 15300 KB Output is correct
14 Correct 61 ms 14652 KB Output is correct
15 Correct 82 ms 14864 KB Output is correct
16 Correct 76 ms 14680 KB Output is correct
17 Correct 91 ms 14992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 11348 KB Output is correct
2 Correct 35 ms 11440 KB Output is correct
3 Correct 48 ms 14264 KB Output is correct
4 Correct 40 ms 13652 KB Output is correct
5 Correct 88 ms 17068 KB Output is correct
6 Correct 86 ms 17308 KB Output is correct
7 Correct 80 ms 17340 KB Output is correct
8 Correct 102 ms 17204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11348 KB Output is correct
2 Correct 6 ms 11348 KB Output is correct
3 Correct 5 ms 11348 KB Output is correct
4 Correct 8 ms 11452 KB Output is correct
5 Correct 5 ms 11348 KB Output is correct
6 Correct 6 ms 11348 KB Output is correct
7 Correct 6 ms 11348 KB Output is correct
8 Correct 6 ms 11348 KB Output is correct
9 Correct 6 ms 11348 KB Output is correct
10 Correct 7 ms 11536 KB Output is correct
11 Correct 6 ms 11476 KB Output is correct
12 Correct 6 ms 11476 KB Output is correct
13 Correct 6 ms 11448 KB Output is correct
14 Correct 6 ms 11476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11348 KB Output is correct
2 Correct 6 ms 11348 KB Output is correct
3 Correct 5 ms 11348 KB Output is correct
4 Correct 8 ms 11452 KB Output is correct
5 Correct 5 ms 11348 KB Output is correct
6 Correct 6 ms 11348 KB Output is correct
7 Correct 6 ms 11348 KB Output is correct
8 Correct 6 ms 11348 KB Output is correct
9 Correct 6 ms 11348 KB Output is correct
10 Correct 7 ms 11536 KB Output is correct
11 Correct 6 ms 11476 KB Output is correct
12 Correct 6 ms 11476 KB Output is correct
13 Correct 6 ms 11448 KB Output is correct
14 Correct 6 ms 11476 KB Output is correct
15 Correct 8 ms 11348 KB Output is correct
16 Correct 7 ms 11476 KB Output is correct
17 Correct 25 ms 13056 KB Output is correct
18 Correct 25 ms 13260 KB Output is correct
19 Correct 23 ms 13140 KB Output is correct
20 Correct 27 ms 13144 KB Output is correct
21 Correct 30 ms 13140 KB Output is correct
22 Correct 41 ms 14924 KB Output is correct
23 Correct 11 ms 11732 KB Output is correct
24 Correct 23 ms 12500 KB Output is correct
25 Correct 7 ms 11476 KB Output is correct
26 Correct 10 ms 11680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11348 KB Output is correct
2 Correct 6 ms 11348 KB Output is correct
3 Correct 5 ms 11348 KB Output is correct
4 Correct 8 ms 11452 KB Output is correct
5 Correct 5 ms 11348 KB Output is correct
6 Correct 6 ms 11348 KB Output is correct
7 Correct 6 ms 11348 KB Output is correct
8 Correct 6 ms 11348 KB Output is correct
9 Correct 6 ms 11348 KB Output is correct
10 Correct 7 ms 11536 KB Output is correct
11 Correct 6 ms 11476 KB Output is correct
12 Correct 6 ms 11476 KB Output is correct
13 Correct 6 ms 11448 KB Output is correct
14 Correct 6 ms 11476 KB Output is correct
15 Correct 8 ms 11348 KB Output is correct
16 Correct 7 ms 11476 KB Output is correct
17 Correct 25 ms 13056 KB Output is correct
18 Correct 25 ms 13260 KB Output is correct
19 Correct 23 ms 13140 KB Output is correct
20 Correct 27 ms 13144 KB Output is correct
21 Correct 30 ms 13140 KB Output is correct
22 Correct 41 ms 14924 KB Output is correct
23 Correct 11 ms 11732 KB Output is correct
24 Correct 23 ms 12500 KB Output is correct
25 Correct 7 ms 11476 KB Output is correct
26 Correct 10 ms 11680 KB Output is correct
27 Correct 9 ms 11612 KB Output is correct
28 Correct 86 ms 19788 KB Output is correct
29 Correct 125 ms 22424 KB Output is correct
30 Correct 159 ms 21876 KB Output is correct
31 Correct 193 ms 22140 KB Output is correct
32 Correct 156 ms 23608 KB Output is correct
33 Correct 179 ms 22068 KB Output is correct
34 Correct 180 ms 22136 KB Output is correct
35 Correct 67 ms 15984 KB Output is correct
36 Correct 173 ms 23032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 11348 KB Output is correct
2 Correct 35 ms 11440 KB Output is correct
3 Correct 48 ms 14264 KB Output is correct
4 Correct 40 ms 13652 KB Output is correct
5 Correct 88 ms 17068 KB Output is correct
6 Correct 86 ms 17308 KB Output is correct
7 Correct 80 ms 17340 KB Output is correct
8 Correct 102 ms 17204 KB Output is correct
9 Correct 101 ms 17244 KB Output is correct
10 Correct 74 ms 15820 KB Output is correct
11 Correct 159 ms 19576 KB Output is correct
12 Correct 6 ms 11348 KB Output is correct
13 Correct 6 ms 11332 KB Output is correct
14 Correct 7 ms 11348 KB Output is correct
15 Correct 6 ms 11348 KB Output is correct
16 Correct 6 ms 11348 KB Output is correct
17 Correct 6 ms 11412 KB Output is correct
18 Correct 28 ms 11348 KB Output is correct
19 Correct 29 ms 11448 KB Output is correct
20 Correct 42 ms 11348 KB Output is correct
21 Correct 37 ms 11448 KB Output is correct
22 Correct 119 ms 16080 KB Output is correct
23 Correct 126 ms 19532 KB Output is correct
24 Correct 193 ms 19660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 14404 KB Output is correct
2 Correct 83 ms 15044 KB Output is correct
3 Correct 43 ms 11432 KB Output is correct
4 Correct 30 ms 11348 KB Output is correct
5 Correct 163 ms 21120 KB Output is correct
6 Correct 303 ms 23380 KB Output is correct
7 Correct 8 ms 11348 KB Output is correct
8 Correct 113 ms 16832 KB Output is correct
9 Correct 157 ms 18244 KB Output is correct
10 Correct 66 ms 14764 KB Output is correct
11 Correct 85 ms 15300 KB Output is correct
12 Correct 9 ms 11348 KB Output is correct
13 Correct 6 ms 11476 KB Output is correct
14 Correct 6 ms 11348 KB Output is correct
15 Correct 6 ms 11428 KB Output is correct
16 Correct 30 ms 11428 KB Output is correct
17 Correct 27 ms 11348 KB Output is correct
18 Correct 58 ms 14900 KB Output is correct
19 Correct 89 ms 15300 KB Output is correct
20 Correct 61 ms 14652 KB Output is correct
21 Correct 82 ms 14864 KB Output is correct
22 Correct 76 ms 14680 KB Output is correct
23 Correct 91 ms 14992 KB Output is correct
24 Correct 29 ms 11348 KB Output is correct
25 Correct 35 ms 11440 KB Output is correct
26 Correct 48 ms 14264 KB Output is correct
27 Correct 40 ms 13652 KB Output is correct
28 Correct 88 ms 17068 KB Output is correct
29 Correct 86 ms 17308 KB Output is correct
30 Correct 80 ms 17340 KB Output is correct
31 Correct 102 ms 17204 KB Output is correct
32 Correct 8 ms 11348 KB Output is correct
33 Correct 6 ms 11348 KB Output is correct
34 Correct 5 ms 11348 KB Output is correct
35 Correct 8 ms 11452 KB Output is correct
36 Correct 5 ms 11348 KB Output is correct
37 Correct 6 ms 11348 KB Output is correct
38 Correct 6 ms 11348 KB Output is correct
39 Correct 6 ms 11348 KB Output is correct
40 Correct 6 ms 11348 KB Output is correct
41 Correct 7 ms 11536 KB Output is correct
42 Correct 6 ms 11476 KB Output is correct
43 Correct 6 ms 11476 KB Output is correct
44 Correct 6 ms 11448 KB Output is correct
45 Correct 6 ms 11476 KB Output is correct
46 Correct 8 ms 11348 KB Output is correct
47 Correct 7 ms 11476 KB Output is correct
48 Correct 25 ms 13056 KB Output is correct
49 Correct 25 ms 13260 KB Output is correct
50 Correct 23 ms 13140 KB Output is correct
51 Correct 27 ms 13144 KB Output is correct
52 Correct 30 ms 13140 KB Output is correct
53 Correct 41 ms 14924 KB Output is correct
54 Correct 11 ms 11732 KB Output is correct
55 Correct 23 ms 12500 KB Output is correct
56 Correct 7 ms 11476 KB Output is correct
57 Correct 10 ms 11680 KB Output is correct
58 Correct 9 ms 11612 KB Output is correct
59 Correct 86 ms 19788 KB Output is correct
60 Correct 125 ms 22424 KB Output is correct
61 Correct 159 ms 21876 KB Output is correct
62 Correct 193 ms 22140 KB Output is correct
63 Correct 156 ms 23608 KB Output is correct
64 Correct 179 ms 22068 KB Output is correct
65 Correct 180 ms 22136 KB Output is correct
66 Correct 67 ms 15984 KB Output is correct
67 Correct 173 ms 23032 KB Output is correct
68 Correct 101 ms 17244 KB Output is correct
69 Correct 74 ms 15820 KB Output is correct
70 Correct 159 ms 19576 KB Output is correct
71 Correct 6 ms 11348 KB Output is correct
72 Correct 6 ms 11332 KB Output is correct
73 Correct 7 ms 11348 KB Output is correct
74 Correct 6 ms 11348 KB Output is correct
75 Correct 6 ms 11348 KB Output is correct
76 Correct 6 ms 11412 KB Output is correct
77 Correct 28 ms 11348 KB Output is correct
78 Correct 29 ms 11448 KB Output is correct
79 Correct 42 ms 11348 KB Output is correct
80 Correct 37 ms 11448 KB Output is correct
81 Correct 119 ms 16080 KB Output is correct
82 Correct 126 ms 19532 KB Output is correct
83 Correct 193 ms 19660 KB Output is correct
84 Correct 185 ms 21920 KB Output is correct
85 Correct 172 ms 21676 KB Output is correct
86 Correct 319 ms 23508 KB Output is correct
87 Correct 341 ms 23800 KB Output is correct
88 Correct 8 ms 11348 KB Output is correct
89 Correct 282 ms 23672 KB Output is correct
90 Correct 194 ms 22948 KB Output is correct
91 Correct 188 ms 22820 KB Output is correct