# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
629850 | 2022-08-15T09:12:16 Z | Vovamatrix | Catfish Farm (IOI22_fish) | C++17 | 186 ms | 28204 KB |
//https://oj.uz/problem/view/IOI22_fish //#include "fish.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define sc second #define th third #define fo fourth #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double #define endl "\n" #define all(data) data.begin(),data.end() #define TYPEMAX(type) std::numeric_limits<type>::max() #define TYPEMIN(type) std::numeric_limits<type>::min() #define ima_li_te(D,d) find(all(D),d) ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) { vector<pair<int,ll>> v[n]; ll dp[2][3][n+2],cnt=0,k,l,p; memset(dp,0,sizeof dp); for(int i=0;i<m;i++) y[i]++; for(int i=0;i<m;i++) v[x[i]].pb(mp(y[i],w[i])); for(int i=0;i<n;i++) { v[i].pb(mp(0,0)); sort(all(v[i])); v[i].pb(mp(n+2,0)); for(int j=1;j<v[i].size();j++) v[i][j].sc+=v[i][j-1].sc; } k=0; for(int i=0;i<v[0].size();i++) { while(k+1<v[1].size() && v[0][i].fi>v[1][k+1].fi) k++; dp[1][0][i]=v[1][k].sc; } k=0; for(int i=0;i<v[1].size();i++) { while(k+1<v[0].size() && v[1][i].fi>v[0][k+1].fi) k++; dp[1][2][i]=v[1].back().sc-v[1][max(i-1,0)].sc; dp[1][1][i]=v[0][k].sc; } for(int i=2;i<n;i++) { for(int j=0;j<3;j++) { for(int k=0;k<max(v[i-1].size(),v[i].size());k++) dp[i&1][j][k]=0; } k=0; for(int j=0;j<v[i-1].size();j++) { while(k+1<v[i].size() && v[i-1][j].fi>v[i][k+1].fi) k++; dp[i&1][0][j]=max(dp[(i&1)^1][1][j],dp[(i&1)^1][2][j])+v[i][k].sc; } cnt=-1; k=l=p=0; for(int j=0;j<v[i].size();j++) { while(k<v[i-2].size() && v[i][j].fi>v[i-2][k].fi) { while(l<v[i-1].size()-1 && v[i-2][k].fi>v[i-1][l+1].fi) l++; cnt=max(cnt,dp[(i&1)^1][0][k]+v[i-1][l].sc); k++; } while(p<v[i-1].size()-1 && v[i][j].fi>v[i-1][p+1].fi) p++; dp[i&1][1][j]=max(dp[i&1][1][j],cnt-v[i-1][p].sc); } cnt=-1; k=v[i-2].size()-1; for(int j=v[i].size()-1;j>=0;j--) { while(k>=0 && v[i][j].fi<=v[i-2][k].fi) { cnt=max(cnt,dp[(i&1)^1][0][k]); k--; } dp[i&1][1][j]=max(dp[i&1][1][j],cnt); } cnt=-1; k=l=0; for(int j=0;j<v[i].size();j++) { while(k<v[i-1].size() && v[i][j].fi>=v[i-1][k].fi) { cnt=max(cnt, dp[(i&1)^1][1][k]-v[i-1][max(k-1,0ll)].sc); k++; } while(l<v[i-1].size()-1 && v[i][j].fi > v[i-1][l].fi) l++; dp[i&1][1][j]=max(dp[i&1][1][j],cnt+v[i-1][max(l-1,0ll)].sc); } cnt=-1; k=v[i-1].size()-1,l=v[i].size()-1; for(int j=v[i].size()-1;j>=0;j--) { while(k>=0 && v[i][j].fi<v[i-1][k].fi) { while(l>0 && v[i-1][k].fi<=v[i][l].fi) l--; cnt=max(cnt,max(dp[(i&1)^1][1][k],dp[(i&1)^1][2][k])+v[i][l].sc); k--; } dp[i&1][2][j]=max(dp[i&1][2][j],cnt-v[i][max(j-1,0)].sc); } } ll rez=0; for(int i=0;i<v[n-2].size();i++) rez=max(rez,dp[(n-1)&1][0][i]); for(int i=1;i<3;i++) { for(int j=0;j<v[n-1].size();j++) rez=max(rez,dp[(n-1)&1][i][j]); } return rez; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 13944 KB | Output is correct |
2 | Correct | 55 ms | 15932 KB | Output is correct |
3 | Correct | 20 ms | 11920 KB | Output is correct |
4 | Correct | 24 ms | 11988 KB | Output is correct |
5 | Correct | 168 ms | 23748 KB | Output is correct |
6 | Correct | 150 ms | 26316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 88 ms | 17228 KB | Output is correct |
3 | Correct | 91 ms | 19780 KB | Output is correct |
4 | Correct | 48 ms | 14044 KB | Output is correct |
5 | Correct | 57 ms | 15928 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 19 ms | 11988 KB | Output is correct |
11 | Correct | 23 ms | 12116 KB | Output is correct |
12 | Correct | 48 ms | 14044 KB | Output is correct |
13 | Correct | 55 ms | 15896 KB | Output is correct |
14 | Correct | 60 ms | 14048 KB | Output is correct |
15 | Correct | 60 ms | 15556 KB | Output is correct |
16 | Correct | 48 ms | 14012 KB | Output is correct |
17 | Correct | 51 ms | 15548 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 11988 KB | Output is correct |
2 | Correct | 20 ms | 12016 KB | Output is correct |
3 | Correct | 40 ms | 14244 KB | Output is correct |
4 | Correct | 33 ms | 14292 KB | Output is correct |
5 | Correct | 76 ms | 18124 KB | Output is correct |
6 | Correct | 59 ms | 18204 KB | Output is correct |
7 | Correct | 57 ms | 18208 KB | Output is correct |
8 | Correct | 59 ms | 18120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 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 | 1 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 | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 16 ms | 2260 KB | Output is correct |
18 | Correct | 20 ms | 2900 KB | Output is correct |
19 | Correct | 15 ms | 2760 KB | Output is correct |
20 | Correct | 15 ms | 2664 KB | Output is correct |
21 | Correct | 18 ms | 2644 KB | Output is correct |
22 | Correct | 32 ms | 5212 KB | Output is correct |
23 | Correct | 4 ms | 724 KB | Output is correct |
24 | Correct | 15 ms | 1672 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 4 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 16 ms | 2260 KB | Output is correct |
18 | Correct | 20 ms | 2900 KB | Output is correct |
19 | Correct | 15 ms | 2760 KB | Output is correct |
20 | Correct | 15 ms | 2664 KB | Output is correct |
21 | Correct | 18 ms | 2644 KB | Output is correct |
22 | Correct | 32 ms | 5212 KB | Output is correct |
23 | Correct | 4 ms | 724 KB | Output is correct |
24 | Correct | 15 ms | 1672 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 4 ms | 724 KB | Output is correct |
27 | Correct | 2 ms | 724 KB | Output is correct |
28 | Correct | 76 ms | 11312 KB | Output is correct |
29 | Correct | 107 ms | 14692 KB | Output is correct |
30 | Correct | 118 ms | 14188 KB | Output is correct |
31 | Correct | 121 ms | 14156 KB | Output is correct |
32 | Correct | 102 ms | 15968 KB | Output is correct |
33 | Correct | 121 ms | 14260 KB | Output is correct |
34 | Correct | 118 ms | 14180 KB | Output is correct |
35 | Correct | 48 ms | 6412 KB | Output is correct |
36 | Correct | 127 ms | 16140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 11988 KB | Output is correct |
2 | Correct | 20 ms | 12016 KB | Output is correct |
3 | Correct | 40 ms | 14244 KB | Output is correct |
4 | Correct | 33 ms | 14292 KB | Output is correct |
5 | Correct | 76 ms | 18124 KB | Output is correct |
6 | Correct | 59 ms | 18204 KB | Output is correct |
7 | Correct | 57 ms | 18208 KB | Output is correct |
8 | Correct | 59 ms | 18120 KB | Output is correct |
9 | Correct | 58 ms | 18120 KB | Output is correct |
10 | Correct | 48 ms | 10708 KB | Output is correct |
11 | Correct | 106 ms | 21084 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 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 | 20 ms | 11988 KB | Output is correct |
19 | Correct | 21 ms | 12036 KB | Output is correct |
20 | Correct | 20 ms | 11988 KB | Output is correct |
21 | Correct | 20 ms | 11964 KB | Output is correct |
22 | Correct | 66 ms | 16860 KB | Output is correct |
23 | Correct | 102 ms | 21088 KB | Output is correct |
24 | Correct | 103 ms | 21084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 13944 KB | Output is correct |
2 | Correct | 55 ms | 15932 KB | Output is correct |
3 | Correct | 20 ms | 11920 KB | Output is correct |
4 | Correct | 24 ms | 11988 KB | Output is correct |
5 | Correct | 168 ms | 23748 KB | Output is correct |
6 | Correct | 150 ms | 26316 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 88 ms | 17228 KB | Output is correct |
9 | Correct | 91 ms | 19780 KB | Output is correct |
10 | Correct | 48 ms | 14044 KB | Output is correct |
11 | Correct | 57 ms | 15928 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 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 | 19 ms | 11988 KB | Output is correct |
17 | Correct | 23 ms | 12116 KB | Output is correct |
18 | Correct | 48 ms | 14044 KB | Output is correct |
19 | Correct | 55 ms | 15896 KB | Output is correct |
20 | Correct | 60 ms | 14048 KB | Output is correct |
21 | Correct | 60 ms | 15556 KB | Output is correct |
22 | Correct | 48 ms | 14012 KB | Output is correct |
23 | Correct | 51 ms | 15548 KB | Output is correct |
24 | Correct | 20 ms | 11988 KB | Output is correct |
25 | Correct | 20 ms | 12016 KB | Output is correct |
26 | Correct | 40 ms | 14244 KB | Output is correct |
27 | Correct | 33 ms | 14292 KB | Output is correct |
28 | Correct | 76 ms | 18124 KB | Output is correct |
29 | Correct | 59 ms | 18204 KB | Output is correct |
30 | Correct | 57 ms | 18208 KB | Output is correct |
31 | Correct | 59 ms | 18120 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 0 ms | 212 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 0 ms | 212 KB | Output is correct |
40 | Correct | 1 ms | 340 KB | Output is correct |
41 | Correct | 1 ms | 468 KB | Output is correct |
42 | Correct | 1 ms | 340 KB | Output is correct |
43 | Correct | 1 ms | 340 KB | Output is correct |
44 | Correct | 0 ms | 212 KB | Output is correct |
45 | Correct | 1 ms | 340 KB | Output is correct |
46 | Correct | 1 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 340 KB | Output is correct |
48 | Correct | 16 ms | 2260 KB | Output is correct |
49 | Correct | 20 ms | 2900 KB | Output is correct |
50 | Correct | 15 ms | 2760 KB | Output is correct |
51 | Correct | 15 ms | 2664 KB | Output is correct |
52 | Correct | 18 ms | 2644 KB | Output is correct |
53 | Correct | 32 ms | 5212 KB | Output is correct |
54 | Correct | 4 ms | 724 KB | Output is correct |
55 | Correct | 15 ms | 1672 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 4 ms | 724 KB | Output is correct |
58 | Correct | 2 ms | 724 KB | Output is correct |
59 | Correct | 76 ms | 11312 KB | Output is correct |
60 | Correct | 107 ms | 14692 KB | Output is correct |
61 | Correct | 118 ms | 14188 KB | Output is correct |
62 | Correct | 121 ms | 14156 KB | Output is correct |
63 | Correct | 102 ms | 15968 KB | Output is correct |
64 | Correct | 121 ms | 14260 KB | Output is correct |
65 | Correct | 118 ms | 14180 KB | Output is correct |
66 | Correct | 48 ms | 6412 KB | Output is correct |
67 | Correct | 127 ms | 16140 KB | Output is correct |
68 | Correct | 58 ms | 18120 KB | Output is correct |
69 | Correct | 48 ms | 10708 KB | Output is correct |
70 | Correct | 106 ms | 21084 KB | Output is correct |
71 | Correct | 0 ms | 212 KB | Output is correct |
72 | Correct | 0 ms | 212 KB | Output is correct |
73 | Correct | 0 ms | 212 KB | Output is correct |
74 | Correct | 0 ms | 212 KB | Output is correct |
75 | Correct | 0 ms | 212 KB | Output is correct |
76 | Correct | 0 ms | 212 KB | Output is correct |
77 | Correct | 20 ms | 11988 KB | Output is correct |
78 | Correct | 21 ms | 12036 KB | Output is correct |
79 | Correct | 20 ms | 11988 KB | Output is correct |
80 | Correct | 20 ms | 11964 KB | Output is correct |
81 | Correct | 66 ms | 16860 KB | Output is correct |
82 | Correct | 102 ms | 21088 KB | Output is correct |
83 | Correct | 103 ms | 21084 KB | Output is correct |
84 | Correct | 144 ms | 25764 KB | Output is correct |
85 | Correct | 144 ms | 26584 KB | Output is correct |
86 | Correct | 176 ms | 27132 KB | Output is correct |
87 | Correct | 186 ms | 27436 KB | Output is correct |
88 | Correct | 1 ms | 212 KB | Output is correct |
89 | Correct | 173 ms | 28204 KB | Output is correct |
90 | Correct | 161 ms | 26344 KB | Output is correct |
91 | Correct | 142 ms | 26588 KB | Output is correct |