Submission #1067391

# Submission time Handle Problem Language Result Execution time Memory
1067391 2024-08-20T16:17:04 Z hotboy2703 Catfish Farm (IOI22_fish) C++17
100 / 100
181 ms 31988 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MP make_pair
#define fi first
#define se second
#define pll pair <ll,ll>
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL<<(i)) 
ll n,m;
const ll MAXN = 1e5+100;
vector <pll> all[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    n=N,m=M;
    ll bot1,bot2,top;
    bot1 = bot2 = top = 0;
    map <ll,ll> mp1,mp2;
    ll sum1=0,sum2=0;
    mp1[0] = mp2[0] = 0;
    for (ll i = 0;i < m;i ++){
        all[X[i]].push_back(MP(Y[i],W[i]));
    }

    for (ll i = 0;i < n;i ++)sort(all[i].begin(),all[i].end());
    for (ll i = 1;i < n;i ++){
        // cout<<i<<endl;
        while ((*mp1.begin()).se<bot2){
            ll x = (*mp1.begin()).se;
            sum1 -= x;
            mp1.erase(mp1.begin());
            if (!mp1.empty()){
                (*mp1.begin()).se += x;
                sum1 += x;
            }
            else break;
        }
        if (!mp1.empty())(*mp1.begin()).se -= bot2;
        else sum1 = bot2;
        mp1[-1] = bot2;
        for (auto x:all[i-1]){
            mp1[x.fi] -= x.se;
            sum1 -= x.se;
            auto cur = mp1.find(x.fi);
            while ((*cur).se < 0){
                ll z = (*cur).se;
                cur = mp1.erase(cur);
                sum1 -= z;
                if (cur==mp1.end())break;
                (*cur).se+=z;
                sum1 += z;
            }
        }
        // cout<<i<<endl;
        for (auto x:all[i-1]){
            mp1[x.fi] += x.se;
            sum1 += x.se;
        }

        mp1.erase(mp1.begin());
        mp1[0] += bot2;

        mp2[n-1] = top - sum2;
        sum2 = top;
        auto sus = [&](auto tmp){
            while ((*tmp).se > 0){
                if (tmp==mp2.begin())break;
                auto pre = prev(tmp);
                (*pre).se += (*tmp).se;
                mp2.erase(tmp);
                tmp = pre;
            }
        };
        sus(mp2.find(n-1));
        for (auto x:all[i]){
            mp2[x.fi]+=x.se;
            sus(mp2.find(x.fi));
        }
        // cout<<"OK"<<endl;
        // return 0;
        ll nw_bot1 = mp2[0];
        for (auto x:all[i]){
            mp2[x.fi]-=x.se;
        }
        sum2 -= mp2[n-1];
        mp2.erase(mp2.find(n-1));
        top = max({top,bot1,sum1});
        bot2 = bot1;
        bot1 = nw_bot1;
        // cout<<endl;
        // cout<<bot1<<' '<<bot2<<' '<<top<<endl;
        // cout<<"MP1\n";
        // for (auto x:mp1)cout<<x.fi<<' '<<x.se<<'\n';
        // cout<<"MP2\n";
        // for (auto x:mp2)cout<<x.fi<<' '<<x.se<<'\n';
    }
    return max({bot1,bot2,top});
}
# Verdict Execution time Memory Grader output
1 Correct 41 ms 10944 KB Output is correct
2 Correct 50 ms 14532 KB Output is correct
3 Correct 7 ms 2652 KB Output is correct
4 Correct 7 ms 2788 KB Output is correct
5 Correct 181 ms 31988 KB Output is correct
6 Correct 130 ms 24152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 93 ms 19060 KB Output is correct
3 Correct 117 ms 26552 KB Output is correct
4 Correct 41 ms 12236 KB Output is correct
5 Correct 50 ms 14528 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 7 ms 2792 KB Output is correct
11 Correct 7 ms 2652 KB Output is correct
12 Correct 57 ms 17324 KB Output is correct
13 Correct 75 ms 20804 KB Output is correct
14 Correct 48 ms 12256 KB Output is correct
15 Correct 54 ms 13500 KB Output is correct
16 Correct 63 ms 14764 KB Output is correct
17 Correct 62 ms 16320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2652 KB Output is correct
2 Correct 7 ms 2664 KB Output is correct
3 Correct 24 ms 5724 KB Output is correct
4 Correct 18 ms 5212 KB Output is correct
5 Correct 41 ms 9892 KB Output is correct
6 Correct 36 ms 9048 KB Output is correct
7 Correct 45 ms 9808 KB Output is correct
8 Correct 37 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2592 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2592 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2844 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 19 ms 5464 KB Output is correct
18 Correct 19 ms 5980 KB Output is correct
19 Correct 18 ms 5784 KB Output is correct
20 Correct 18 ms 5976 KB Output is correct
21 Correct 19 ms 5976 KB Output is correct
22 Correct 37 ms 9048 KB Output is correct
23 Correct 6 ms 3160 KB Output is correct
24 Correct 13 ms 4696 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 5 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2592 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2844 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 19 ms 5464 KB Output is correct
18 Correct 19 ms 5980 KB Output is correct
19 Correct 18 ms 5784 KB Output is correct
20 Correct 18 ms 5976 KB Output is correct
21 Correct 19 ms 5976 KB Output is correct
22 Correct 37 ms 9048 KB Output is correct
23 Correct 6 ms 3160 KB Output is correct
24 Correct 13 ms 4696 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 5 ms 3164 KB Output is correct
27 Correct 2 ms 2904 KB Output is correct
28 Correct 87 ms 17340 KB Output is correct
29 Correct 136 ms 22620 KB Output is correct
30 Correct 140 ms 22036 KB Output is correct
31 Correct 121 ms 21904 KB Output is correct
32 Correct 118 ms 23380 KB Output is correct
33 Correct 127 ms 22100 KB Output is correct
34 Correct 120 ms 22112 KB Output is correct
35 Correct 46 ms 10584 KB Output is correct
36 Correct 122 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2652 KB Output is correct
2 Correct 7 ms 2664 KB Output is correct
3 Correct 24 ms 5724 KB Output is correct
4 Correct 18 ms 5212 KB Output is correct
5 Correct 41 ms 9892 KB Output is correct
6 Correct 36 ms 9048 KB Output is correct
7 Correct 45 ms 9808 KB Output is correct
8 Correct 37 ms 9708 KB Output is correct
9 Correct 52 ms 9604 KB Output is correct
10 Correct 46 ms 9484 KB Output is correct
11 Correct 81 ms 15952 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2604 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 8 ms 2652 KB Output is correct
19 Correct 7 ms 2788 KB Output is correct
20 Correct 8 ms 2652 KB Output is correct
21 Correct 10 ms 2720 KB Output is correct
22 Correct 66 ms 9972 KB Output is correct
23 Correct 88 ms 15952 KB Output is correct
24 Correct 88 ms 16656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 10944 KB Output is correct
2 Correct 50 ms 14532 KB Output is correct
3 Correct 7 ms 2652 KB Output is correct
4 Correct 7 ms 2788 KB Output is correct
5 Correct 181 ms 31988 KB Output is correct
6 Correct 130 ms 24152 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 93 ms 19060 KB Output is correct
9 Correct 117 ms 26552 KB Output is correct
10 Correct 41 ms 12236 KB Output is correct
11 Correct 50 ms 14528 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 7 ms 2792 KB Output is correct
17 Correct 7 ms 2652 KB Output is correct
18 Correct 57 ms 17324 KB Output is correct
19 Correct 75 ms 20804 KB Output is correct
20 Correct 48 ms 12256 KB Output is correct
21 Correct 54 ms 13500 KB Output is correct
22 Correct 63 ms 14764 KB Output is correct
23 Correct 62 ms 16320 KB Output is correct
24 Correct 7 ms 2652 KB Output is correct
25 Correct 7 ms 2664 KB Output is correct
26 Correct 24 ms 5724 KB Output is correct
27 Correct 18 ms 5212 KB Output is correct
28 Correct 41 ms 9892 KB Output is correct
29 Correct 36 ms 9048 KB Output is correct
30 Correct 45 ms 9808 KB Output is correct
31 Correct 37 ms 9708 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2592 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2648 KB Output is correct
41 Correct 2 ms 2908 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 2 ms 2844 KB Output is correct
46 Correct 1 ms 2648 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 19 ms 5464 KB Output is correct
49 Correct 19 ms 5980 KB Output is correct
50 Correct 18 ms 5784 KB Output is correct
51 Correct 18 ms 5976 KB Output is correct
52 Correct 19 ms 5976 KB Output is correct
53 Correct 37 ms 9048 KB Output is correct
54 Correct 6 ms 3160 KB Output is correct
55 Correct 13 ms 4696 KB Output is correct
56 Correct 2 ms 2652 KB Output is correct
57 Correct 5 ms 3164 KB Output is correct
58 Correct 2 ms 2904 KB Output is correct
59 Correct 87 ms 17340 KB Output is correct
60 Correct 136 ms 22620 KB Output is correct
61 Correct 140 ms 22036 KB Output is correct
62 Correct 121 ms 21904 KB Output is correct
63 Correct 118 ms 23380 KB Output is correct
64 Correct 127 ms 22100 KB Output is correct
65 Correct 120 ms 22112 KB Output is correct
66 Correct 46 ms 10584 KB Output is correct
67 Correct 122 ms 23832 KB Output is correct
68 Correct 52 ms 9604 KB Output is correct
69 Correct 46 ms 9484 KB Output is correct
70 Correct 81 ms 15952 KB Output is correct
71 Correct 2 ms 2648 KB Output is correct
72 Correct 1 ms 2652 KB Output is correct
73 Correct 1 ms 2652 KB Output is correct
74 Correct 1 ms 2604 KB Output is correct
75 Correct 1 ms 2652 KB Output is correct
76 Correct 1 ms 2652 KB Output is correct
77 Correct 8 ms 2652 KB Output is correct
78 Correct 7 ms 2788 KB Output is correct
79 Correct 8 ms 2652 KB Output is correct
80 Correct 10 ms 2720 KB Output is correct
81 Correct 66 ms 9972 KB Output is correct
82 Correct 88 ms 15952 KB Output is correct
83 Correct 88 ms 16656 KB Output is correct
84 Correct 158 ms 22984 KB Output is correct
85 Correct 153 ms 22604 KB Output is correct
86 Correct 140 ms 23636 KB Output is correct
87 Correct 151 ms 23832 KB Output is correct
88 Correct 1 ms 2652 KB Output is correct
89 Correct 152 ms 23960 KB Output is correct
90 Correct 132 ms 22940 KB Output is correct
91 Correct 122 ms 22552 KB Output is correct