Submission #635505

# Submission time Handle Problem Language Result Execution time Memory
635505 2022-08-26T10:49:49 Z OttoTheDino Catfish Farm (IOI22_fish) C++17
100 / 100
926 ms 132092 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,s,e)              for (ll i = s; i <= e; ++i)
#define rrep(i,s,e)             for (ll i = s; i >= e; --i)
#define len(v)                  (ll)v.size()
#define pb                      push_back
#define all(v)                  v.begin(), v.end()
#define fi                      first
#define se                      second
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
typedef pair<ll,ll> pll;
 
ll max_weights(int n, int m, vi X, vi Y, vi W) {
    bool done[n+5] = {};
    vector<ll> check[n+5], fish[n+5];
    unordered_map<ll,ll> w[n+5], dp[n+5][2];
 
    rep (i,0,m-1) {
        fish[X[i]+1].pb(Y[i]+1);
        w[X[i]+1][Y[i]+1] = W[i];
        check[X[i]+1].pb(Y[i]);
        if (Y[i]==0) done[X[i]+1] = 1;
    }
 
    rep (i,0,n) {
        if (i) check[i].pb(n);
        if (!done[i]) check[i].pb(0);
    }
 
    rep (i,1,n) {
 
        ll sth = 0;
        {
            //go bigger
            vector<pll> upd;
            set<ll> st;
            for (ll el : check[i]) upd.pb({el,1});
            for (ll el : fish[i-1]) upd.pb({el,0});
            for (ll el : check[i-1]) upd.pb({el,2});
            sort (all(upd));
            ll sum = 0;
            for (pll el : upd) {
                ll y = el.fi, tp = el.se;
                if (tp==0) {
                    sum += w[i-1][y]; 
                }
                if (tp==1) {
                    ll res;
                    if (len(st)) {
                        res = sum+*st.rbegin();
                    }
                    else res = 0;
                    dp[i][0][y] = max(dp[i][0][y], res);
                    if (y==n) sth = res;
                    //cout << "1: " << i << " " << y << " " << dp[i][0][y] << endl;
                }
                if (tp==2) {
                    st.insert(dp[i-1][0][y]-sum);
                }
            }
        }
 
        {
            //go smaller
            vector<pll> upd;
            ll sum = 0, cur = 0;
            for (ll el : check[i]) upd.pb({el,3});
            for (ll el : fish[i+1]) {
                upd.pb({el, 0});
                sum += w[i+1][el]; 
            }
            for (ll el : fish[i]) {
                upd.pb({el, 1});
                cur += w[i][el];
            }
            for (ll el : check[i-1]) upd.pb ({el, 2});
            sort (all(upd));
            reverse(all(upd));
            set<ll> st;
            for (pll el : upd) {
                ll y = el.fi, tp = el.se;
                if (tp==0) sum -= w[i+1][y]; 
                if (tp==1) cur -= w[i][y];
                if (tp==2) st.insert({dp[i-1][1][y]});
                if (tp==3) {
                    ll res = dp[i-1][0][n]+cur;
                    if (len(st)) res = max(res, *st.rbegin());
                    if (y==n) res = max(res, sth+cur);
                    dp[i][1][y] = res-cur+sum;
                    ////cout << "2: " << i << " " << y << " " << dp[i][1][y] << endl;
                    dp[i+1][0][y] = dp[i][1][y];
                }
            }
        }
    }
 
    ll ans = 0;
    for (ll y : check[n]) {
        ans = max(ans, dp[n][0][y]);
        ans = max(ans, dp[n][1][y]);
    }
 
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 239 ms 69132 KB Output is correct
2 Correct 281 ms 80876 KB Output is correct
3 Correct 125 ms 58988 KB Output is correct
4 Correct 112 ms 59084 KB Output is correct
5 Correct 847 ms 132092 KB Output is correct
6 Correct 745 ms 117240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 446 ms 84124 KB Output is correct
3 Correct 572 ms 99924 KB Output is correct
4 Correct 274 ms 69152 KB Output is correct
5 Correct 292 ms 80924 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 119 ms 59040 KB Output is correct
11 Correct 116 ms 58992 KB Output is correct
12 Correct 263 ms 69144 KB Output is correct
13 Correct 298 ms 80876 KB Output is correct
14 Correct 242 ms 69144 KB Output is correct
15 Correct 298 ms 78068 KB Output is correct
16 Correct 240 ms 69204 KB Output is correct
17 Correct 285 ms 79248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 59060 KB Output is correct
2 Correct 115 ms 59000 KB Output is correct
3 Correct 182 ms 63572 KB Output is correct
4 Correct 225 ms 66208 KB Output is correct
5 Correct 280 ms 78592 KB Output is correct
6 Correct 290 ms 79356 KB Output is correct
7 Correct 344 ms 79928 KB Output is correct
8 Correct 282 ms 79956 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 468 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 468 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 86 ms 9516 KB Output is correct
18 Correct 73 ms 10432 KB Output is correct
19 Correct 68 ms 9884 KB Output is correct
20 Correct 91 ms 9760 KB Output is correct
21 Correct 84 ms 9676 KB Output is correct
22 Correct 142 ms 19452 KB Output is correct
23 Correct 17 ms 2460 KB Output is correct
24 Correct 51 ms 6960 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 15 ms 2260 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 468 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 86 ms 9516 KB Output is correct
18 Correct 73 ms 10432 KB Output is correct
19 Correct 68 ms 9884 KB Output is correct
20 Correct 91 ms 9760 KB Output is correct
21 Correct 84 ms 9676 KB Output is correct
22 Correct 142 ms 19452 KB Output is correct
23 Correct 17 ms 2460 KB Output is correct
24 Correct 51 ms 6960 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 15 ms 2260 KB Output is correct
27 Correct 10 ms 2900 KB Output is correct
28 Correct 426 ms 48216 KB Output is correct
29 Correct 620 ms 69276 KB Output is correct
30 Correct 610 ms 69592 KB Output is correct
31 Correct 613 ms 69664 KB Output is correct
32 Correct 539 ms 65744 KB Output is correct
33 Correct 643 ms 70020 KB Output is correct
34 Correct 650 ms 69964 KB Output is correct
35 Correct 206 ms 27908 KB Output is correct
36 Correct 656 ms 70672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 59060 KB Output is correct
2 Correct 115 ms 59000 KB Output is correct
3 Correct 182 ms 63572 KB Output is correct
4 Correct 225 ms 66208 KB Output is correct
5 Correct 280 ms 78592 KB Output is correct
6 Correct 290 ms 79356 KB Output is correct
7 Correct 344 ms 79928 KB Output is correct
8 Correct 282 ms 79956 KB Output is correct
9 Correct 380 ms 90188 KB Output is correct
10 Correct 200 ms 47428 KB Output is correct
11 Correct 444 ms 94928 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 107 ms 59080 KB Output is correct
19 Correct 108 ms 59084 KB Output is correct
20 Correct 113 ms 58992 KB Output is correct
21 Correct 118 ms 59012 KB Output is correct
22 Correct 321 ms 85876 KB Output is correct
23 Correct 511 ms 102268 KB Output is correct
24 Correct 473 ms 104580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 69132 KB Output is correct
2 Correct 281 ms 80876 KB Output is correct
3 Correct 125 ms 58988 KB Output is correct
4 Correct 112 ms 59084 KB Output is correct
5 Correct 847 ms 132092 KB Output is correct
6 Correct 745 ms 117240 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 446 ms 84124 KB Output is correct
9 Correct 572 ms 99924 KB Output is correct
10 Correct 274 ms 69152 KB Output is correct
11 Correct 292 ms 80924 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 119 ms 59040 KB Output is correct
17 Correct 116 ms 58992 KB Output is correct
18 Correct 263 ms 69144 KB Output is correct
19 Correct 298 ms 80876 KB Output is correct
20 Correct 242 ms 69144 KB Output is correct
21 Correct 298 ms 78068 KB Output is correct
22 Correct 240 ms 69204 KB Output is correct
23 Correct 285 ms 79248 KB Output is correct
24 Correct 221 ms 59060 KB Output is correct
25 Correct 115 ms 59000 KB Output is correct
26 Correct 182 ms 63572 KB Output is correct
27 Correct 225 ms 66208 KB Output is correct
28 Correct 280 ms 78592 KB Output is correct
29 Correct 290 ms 79356 KB Output is correct
30 Correct 344 ms 79928 KB Output is correct
31 Correct 282 ms 79956 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 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 86 ms 9516 KB Output is correct
49 Correct 73 ms 10432 KB Output is correct
50 Correct 68 ms 9884 KB Output is correct
51 Correct 91 ms 9760 KB Output is correct
52 Correct 84 ms 9676 KB Output is correct
53 Correct 142 ms 19452 KB Output is correct
54 Correct 17 ms 2460 KB Output is correct
55 Correct 51 ms 6960 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 15 ms 2260 KB Output is correct
58 Correct 10 ms 2900 KB Output is correct
59 Correct 426 ms 48216 KB Output is correct
60 Correct 620 ms 69276 KB Output is correct
61 Correct 610 ms 69592 KB Output is correct
62 Correct 613 ms 69664 KB Output is correct
63 Correct 539 ms 65744 KB Output is correct
64 Correct 643 ms 70020 KB Output is correct
65 Correct 650 ms 69964 KB Output is correct
66 Correct 206 ms 27908 KB Output is correct
67 Correct 656 ms 70672 KB Output is correct
68 Correct 380 ms 90188 KB Output is correct
69 Correct 200 ms 47428 KB Output is correct
70 Correct 444 ms 94928 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 300 KB Output is correct
74 Correct 1 ms 296 KB Output is correct
75 Correct 1 ms 300 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 107 ms 59080 KB Output is correct
78 Correct 108 ms 59084 KB Output is correct
79 Correct 113 ms 58992 KB Output is correct
80 Correct 118 ms 59012 KB Output is correct
81 Correct 321 ms 85876 KB Output is correct
82 Correct 511 ms 102268 KB Output is correct
83 Correct 473 ms 104580 KB Output is correct
84 Correct 926 ms 118436 KB Output is correct
85 Correct 904 ms 121592 KB Output is correct
86 Correct 724 ms 116312 KB Output is correct
87 Correct 765 ms 122880 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 757 ms 123632 KB Output is correct
90 Correct 664 ms 115632 KB Output is correct
91 Correct 670 ms 110672 KB Output is correct