# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
629852 | 2022-08-15T09:14:10 Z | Vovamatrix | 메기 농장 (IOI22_fish) | C++17 | 188 ms | 26952 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[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; } 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; } 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 14020 KB | Output is correct |
2 | Correct | 56 ms | 15912 KB | Output is correct |
3 | Correct | 20 ms | 11944 KB | Output is correct |
4 | Correct | 22 ms | 12032 KB | Output is correct |
5 | Correct | 144 ms | 23788 KB | Output is correct |
6 | Correct | 155 ms | 26444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 86 ms | 17224 KB | Output is correct |
3 | Correct | 95 ms | 19872 KB | Output is correct |
4 | Correct | 65 ms | 14016 KB | Output is correct |
5 | Correct | 68 ms | 15932 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 | 20 ms | 11988 KB | Output is correct |
11 | Correct | 20 ms | 12028 KB | Output is correct |
12 | Correct | 53 ms | 14044 KB | Output is correct |
13 | Correct | 73 ms | 15868 KB | Output is correct |
14 | Correct | 50 ms | 14044 KB | Output is correct |
15 | Correct | 53 ms | 15560 KB | Output is correct |
16 | Correct | 50 ms | 14056 KB | Output is correct |
17 | Correct | 54 ms | 15556 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 11988 KB | Output is correct |
2 | Correct | 23 ms | 11972 KB | Output is correct |
3 | Correct | 43 ms | 14248 KB | Output is correct |
4 | Correct | 36 ms | 14292 KB | Output is correct |
5 | Correct | 64 ms | 18112 KB | Output is correct |
6 | Correct | 54 ms | 18216 KB | Output is correct |
7 | Correct | 65 ms | 18208 KB | Output is correct |
8 | Correct | 65 ms | 18216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 420 KB | Output is correct |
17 | Correct | 17 ms | 2260 KB | Output is correct |
18 | Correct | 16 ms | 2888 KB | Output is correct |
19 | Correct | 18 ms | 2760 KB | Output is correct |
20 | Correct | 16 ms | 2632 KB | Output is correct |
21 | Correct | 15 ms | 2644 KB | Output is correct |
22 | Correct | 32 ms | 5188 KB | Output is correct |
23 | Correct | 4 ms | 724 KB | Output is correct |
24 | Correct | 12 ms | 1668 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 5 ms | 724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 420 KB | Output is correct |
17 | Correct | 17 ms | 2260 KB | Output is correct |
18 | Correct | 16 ms | 2888 KB | Output is correct |
19 | Correct | 18 ms | 2760 KB | Output is correct |
20 | Correct | 16 ms | 2632 KB | Output is correct |
21 | Correct | 15 ms | 2644 KB | Output is correct |
22 | Correct | 32 ms | 5188 KB | Output is correct |
23 | Correct | 4 ms | 724 KB | Output is correct |
24 | Correct | 12 ms | 1668 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 5 ms | 724 KB | Output is correct |
27 | Correct | 2 ms | 724 KB | Output is correct |
28 | Correct | 74 ms | 11276 KB | Output is correct |
29 | Correct | 111 ms | 14704 KB | Output is correct |
30 | Correct | 123 ms | 14156 KB | Output is correct |
31 | Correct | 124 ms | 14252 KB | Output is correct |
32 | Correct | 99 ms | 15948 KB | Output is correct |
33 | Correct | 117 ms | 14184 KB | Output is correct |
34 | Correct | 124 ms | 14340 KB | Output is correct |
35 | Correct | 57 ms | 6292 KB | Output is correct |
36 | Correct | 151 ms | 16248 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 11988 KB | Output is correct |
2 | Correct | 23 ms | 11972 KB | Output is correct |
3 | Correct | 43 ms | 14248 KB | Output is correct |
4 | Correct | 36 ms | 14292 KB | Output is correct |
5 | Correct | 64 ms | 18112 KB | Output is correct |
6 | Correct | 54 ms | 18216 KB | Output is correct |
7 | Correct | 65 ms | 18208 KB | Output is correct |
8 | Correct | 65 ms | 18216 KB | Output is correct |
9 | Correct | 62 ms | 18244 KB | Output is correct |
10 | Correct | 45 ms | 10700 KB | Output is correct |
11 | Correct | 105 ms | 21088 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 | 20 ms | 12008 KB | Output is correct |
19 | Correct | 20 ms | 11932 KB | Output is correct |
20 | Correct | 24 ms | 11916 KB | Output is correct |
21 | Correct | 21 ms | 11976 KB | Output is correct |
22 | Correct | 65 ms | 16828 KB | Output is correct |
23 | Correct | 117 ms | 21072 KB | Output is correct |
24 | Correct | 109 ms | 21100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 14020 KB | Output is correct |
2 | Correct | 56 ms | 15912 KB | Output is correct |
3 | Correct | 20 ms | 11944 KB | Output is correct |
4 | Correct | 22 ms | 12032 KB | Output is correct |
5 | Correct | 144 ms | 23788 KB | Output is correct |
6 | Correct | 155 ms | 26444 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 86 ms | 17224 KB | Output is correct |
9 | Correct | 95 ms | 19872 KB | Output is correct |
10 | Correct | 65 ms | 14016 KB | Output is correct |
11 | Correct | 68 ms | 15932 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 | 20 ms | 11988 KB | Output is correct |
17 | Correct | 20 ms | 12028 KB | Output is correct |
18 | Correct | 53 ms | 14044 KB | Output is correct |
19 | Correct | 73 ms | 15868 KB | Output is correct |
20 | Correct | 50 ms | 14044 KB | Output is correct |
21 | Correct | 53 ms | 15560 KB | Output is correct |
22 | Correct | 50 ms | 14056 KB | Output is correct |
23 | Correct | 54 ms | 15556 KB | Output is correct |
24 | Correct | 22 ms | 11988 KB | Output is correct |
25 | Correct | 23 ms | 11972 KB | Output is correct |
26 | Correct | 43 ms | 14248 KB | Output is correct |
27 | Correct | 36 ms | 14292 KB | Output is correct |
28 | Correct | 64 ms | 18112 KB | Output is correct |
29 | Correct | 54 ms | 18216 KB | Output is correct |
30 | Correct | 65 ms | 18208 KB | Output is correct |
31 | Correct | 65 ms | 18216 KB | Output is correct |
32 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
45 | Correct | 1 ms | 340 KB | Output is correct |
46 | Correct | 0 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 420 KB | Output is correct |
48 | Correct | 17 ms | 2260 KB | Output is correct |
49 | Correct | 16 ms | 2888 KB | Output is correct |
50 | Correct | 18 ms | 2760 KB | Output is correct |
51 | Correct | 16 ms | 2632 KB | Output is correct |
52 | Correct | 15 ms | 2644 KB | Output is correct |
53 | Correct | 32 ms | 5188 KB | Output is correct |
54 | Correct | 4 ms | 724 KB | Output is correct |
55 | Correct | 12 ms | 1668 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 5 ms | 724 KB | Output is correct |
58 | Correct | 2 ms | 724 KB | Output is correct |
59 | Correct | 74 ms | 11276 KB | Output is correct |
60 | Correct | 111 ms | 14704 KB | Output is correct |
61 | Correct | 123 ms | 14156 KB | Output is correct |
62 | Correct | 124 ms | 14252 KB | Output is correct |
63 | Correct | 99 ms | 15948 KB | Output is correct |
64 | Correct | 117 ms | 14184 KB | Output is correct |
65 | Correct | 124 ms | 14340 KB | Output is correct |
66 | Correct | 57 ms | 6292 KB | Output is correct |
67 | Correct | 151 ms | 16248 KB | Output is correct |
68 | Correct | 62 ms | 18244 KB | Output is correct |
69 | Correct | 45 ms | 10700 KB | Output is correct |
70 | Correct | 105 ms | 21088 KB | Output is correct |
71 | Correct | 0 ms | 212 KB | Output is correct |
72 | Correct | 1 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 | 12008 KB | Output is correct |
78 | Correct | 20 ms | 11932 KB | Output is correct |
79 | Correct | 24 ms | 11916 KB | Output is correct |
80 | Correct | 21 ms | 11976 KB | Output is correct |
81 | Correct | 65 ms | 16828 KB | Output is correct |
82 | Correct | 117 ms | 21072 KB | Output is correct |
83 | Correct | 109 ms | 21100 KB | Output is correct |
84 | Correct | 142 ms | 22888 KB | Output is correct |
85 | Correct | 144 ms | 23932 KB | Output is correct |
86 | Correct | 188 ms | 25936 KB | Output is correct |
87 | Correct | 172 ms | 26828 KB | Output is correct |
88 | Correct | 0 ms | 212 KB | Output is correct |
89 | Correct | 172 ms | 26952 KB | Output is correct |
90 | Correct | 168 ms | 26084 KB | Output is correct |
91 | Correct | 134 ms | 26184 KB | Output is correct |