Submission #1059103

# Submission time Handle Problem Language Result Execution time Memory
1059103 2024-08-14T17:15:35 Z underwaterkillerwhale Catfish Farm (IOI22_fish) C++17
100 / 100
298 ms 141432 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 1e5 + 7;
const int Mod = 1e9 + 7;
const ll INF = 2e9 + 7;
const ll BASE = 137;
const int szBL = 320;

void inline maximize (ll &A, ll B) { if (A < B) A = B; }

struct Fish {
    int fs, se;
    ll W;
};

int n, m;
vector<ll> pcur[N], dp[N], fsuf[N], f[N], fpre[N], dppre[N], Left[N], Right[N];

vector<int> high[N];
Fish a[(int)3e5 + 7];
vector<pll> vec[N];

void init (int j, int m) {
    pcur[j].resize(m + 2, 0);
    Left[j].resize(m + 2, 0);
    Right[j].resize(m + 2, 0);
    fpre[j].resize(m + 2, 0);
    dppre[j].resize(m + 2, 0);
    f[j].resize(m + 2, 0);
    fsuf[j].resize(m + 2, 0);
    dp[j].resize(m + 2, 0); ///sửa ik
}

//void solution () {
ll max_weights(int _n, int _m, vector<int> X, vector<int> Y, vector<int> W) {
//    cin >> n >> m;
//    n = 1e5;
//    m = Rand(1, (n - 1) / 2);
//    m = min(1LL * n * n - Rand(1, n * n), (ll)3e5);
    n = _n;
    m = _m;
//    vector<ll> val;
//    rep (i, 0, (n - 1) / 2) val.pb(i * 2);
//    random_shuffle(ALL(val));
    rep (j, 0, n) high[j] = {0};
    rep (i, 1, m) {
//        cin >> a[i].fs >> a[i].se >> a[i].W;
//        a[i].fs = val[i - 1].fs;
//        a[i].se = val[i - 1].se;
//        a[i].W = Rand(1, 100000);
//            a[i].fs = val[i];
//            a[i].se = Rand(0, n - 1);
//            a[i].W = 1e9;
        a[i].fs = X[i - 1];
        a[i].se = Y[i - 1];
        a[i].W = W[i - 1];
        ++a[i].fs;
        ++a[i].se;
//        cout << a[i].fs<<","<<a[i].se<<"\n";
        vec[a[i].fs].pb(MP(a[i].se, a[i].W));
        high[a[i].fs].pb(a[i].se);
    }
    init(0, 5);
    rep (j, 1, n) {
        iter (&id, vec[j + 1])
            high[j].pb(id.fs);
        iter (&id, vec[j - 1])
            high[j].pb(id.fs);
        sort (ALL(high[j]));
        high[j].resize(unique(ALL(high[j])) - high[j].begin());
        int m = SZ(high[j]);
        init(j, m);
        iter (&id, vec[j]) pcur[j][lower_bound(ALL(high[j]), id.fs) - high[j].begin()] = id.se;
        rep (i, 1, m){
            pcur[j][i] += pcur[j][i - 1];
        }
        rep (i, 1, m - 1) {
            int pos = upper_bound(ALL(high[j - 1]), high[j][i]) - high[j - 1].begin() - 1;
            Left[j][i] = pcur[j - 1][pos];
//            if (j == 2) cout << i<<" "<<<pcur[j][i] <<".\n";
        }
    }
    rep (j, 1, n - 1) {
        int m = SZ(high[j]);
        rep (i, 1, m - 1) {
            int pos = upper_bound(ALL(high[j + 1]), high[j][i]) - high[j + 1].begin() - 1;
            Right[j][i] = pcur[j + 1][pos];
        }
    }
//    return;
    rep (j, 1, n) {
        int m = SZ(high[j]);
        vector<int> &ch = high[j];
        if (j >= 2) {
            ll prem = *max_element(ALL(dp[j - 2]));
            rep (i, 0, m - 1) {
                int pos = upper_bound(ALL(high[j - 1]), ch[i]) - high[j - 1].begin();
//                if (j == 3 && high[j][i] == 4) {
//                    cout << dp[j][i] <<" "<<Left[j][i]<<"hihih\n";
//                }
                maximize(f[j][i], fpre[j - 1][pos - 1] + Left[j][i]);
                maximize(dp[j][i], prem + Left[j][i]);
                maximize(dp[j][i], fsuf[j - 1][pos] - pcur[j][i]);
                maximize(dp[j][i], f[j][i]);
            }
            rep (i, 0, m - 1) {
                int pos = upper_bound(ALL(high[j - 2]), ch[i]) - high[j - 2].begin();
//                if (j == 3 && high[j][i] == 4) {
//                    cout << dp[j][i] <<" "<<Left[j][i]<<"hihih\n";
//                }
                maximize(f[j][i], dppre[j - 2][pos - 1] + Left[j][i]);
                maximize(f[j][i], fsuf[j - 2][pos]);
                maximize(dp[j][i], f[j][i]);
            }
        }
        if (j > 3) {
            ll prem = 0;
            rep (i, 0, SZ(high[j - 3]) - 1) {
                prem = max(prem, dp[j - 3][i] + Right[j - 3][i]);
            }
            rep (i, 0, m - 1) {
                maximize(dp[j][i], Left[j][i] + prem);
                maximize(f[j][i], Left[j][i] + prem);
            }
        }
        fpre[j][0] = f[j][0];
        dppre[j][0] = dp[j][0];
        rep (i, 1, m - 1) {
            fpre[j][i] = max(fpre[j][i - 1], f[j][i] - pcur[j][i]);
            dppre[j][i] = max(dppre[j][i - 1], dp[j][i]);
        }
        reb (i, m, 0) {
            fsuf[j][i] = max(fsuf[j][i + 1], dp[j][i] + Right[j][i]);
        }
//        rep (i, 0, m - 1) {
//            cout << j <<  " "<<high[j][i] <<" "<< dp[j][i] <<"\n";
//        }
    }
//    cout << *max_element(ALL(dp[n])) <<"\n";
    return *max_element(ALL(dp[n]));
}
//
//#define file(name) freopen(name".inp","r",stdin); \
//freopen(name".out","w",stdout);
//int main () {
////    file("c");
////    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    int num_Test = 1;
////    cin >> num_Test;
//    while (num_Test--)
////        solution();
//        cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3});
//}
/*
no bug challenge +2
2 + 8 * 2 - 9
7 7
0 2 5
0 1 1
2 1 2
2 2 1
4 4 1
4 6 2
6 3 3
*/

Compilation message

fish.cpp:161:1: warning: multi-line comment [-Wcomment]
  161 | //#define file(name) freopen(name".inp","r",stdin); \
      | ^
# Verdict Execution time Memory Grader output
1 Correct 81 ms 66752 KB Output is correct
2 Correct 93 ms 72776 KB Output is correct
3 Correct 36 ms 54576 KB Output is correct
4 Correct 47 ms 54968 KB Output is correct
5 Correct 249 ms 131740 KB Output is correct
6 Correct 298 ms 137756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 26460 KB Output is correct
2 Correct 139 ms 79752 KB Output is correct
3 Correct 152 ms 87328 KB Output is correct
4 Correct 76 ms 66748 KB Output is correct
5 Correct 98 ms 72776 KB Output is correct
6 Correct 4 ms 26460 KB Output is correct
7 Correct 4 ms 26548 KB Output is correct
8 Correct 3 ms 26460 KB Output is correct
9 Correct 4 ms 26456 KB Output is correct
10 Correct 34 ms 54736 KB Output is correct
11 Correct 35 ms 54608 KB Output is correct
12 Correct 94 ms 72124 KB Output is correct
13 Correct 115 ms 79628 KB Output is correct
14 Correct 86 ms 69420 KB Output is correct
15 Correct 90 ms 69140 KB Output is correct
16 Correct 85 ms 69672 KB Output is correct
17 Correct 95 ms 74260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 54620 KB Output is correct
2 Correct 35 ms 54500 KB Output is correct
3 Correct 56 ms 62804 KB Output is correct
4 Correct 52 ms 62800 KB Output is correct
5 Correct 74 ms 74068 KB Output is correct
6 Correct 73 ms 73228 KB Output is correct
7 Correct 70 ms 73904 KB Output is correct
8 Correct 72 ms 74036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 26460 KB Output is correct
2 Correct 3 ms 26460 KB Output is correct
3 Correct 4 ms 26456 KB Output is correct
4 Correct 3 ms 26460 KB Output is correct
5 Correct 3 ms 26460 KB Output is correct
6 Correct 4 ms 26460 KB Output is correct
7 Correct 4 ms 26460 KB Output is correct
8 Correct 3 ms 26460 KB Output is correct
9 Correct 4 ms 26460 KB Output is correct
10 Correct 6 ms 26940 KB Output is correct
11 Correct 4 ms 26716 KB Output is correct
12 Correct 5 ms 26716 KB Output is correct
13 Correct 4 ms 26376 KB Output is correct
14 Correct 4 ms 26716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 26460 KB Output is correct
2 Correct 3 ms 26460 KB Output is correct
3 Correct 4 ms 26456 KB Output is correct
4 Correct 3 ms 26460 KB Output is correct
5 Correct 3 ms 26460 KB Output is correct
6 Correct 4 ms 26460 KB Output is correct
7 Correct 4 ms 26460 KB Output is correct
8 Correct 3 ms 26460 KB Output is correct
9 Correct 4 ms 26460 KB Output is correct
10 Correct 6 ms 26940 KB Output is correct
11 Correct 4 ms 26716 KB Output is correct
12 Correct 5 ms 26716 KB Output is correct
13 Correct 4 ms 26376 KB Output is correct
14 Correct 4 ms 26716 KB Output is correct
15 Correct 4 ms 26716 KB Output is correct
16 Correct 4 ms 26716 KB Output is correct
17 Correct 22 ms 33516 KB Output is correct
18 Correct 20 ms 33588 KB Output is correct
19 Correct 21 ms 33372 KB Output is correct
20 Correct 20 ms 32884 KB Output is correct
21 Correct 20 ms 32860 KB Output is correct
22 Correct 37 ms 39132 KB Output is correct
23 Correct 8 ms 28764 KB Output is correct
24 Correct 20 ms 33076 KB Output is correct
25 Correct 4 ms 26716 KB Output is correct
26 Correct 7 ms 28648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 26460 KB Output is correct
2 Correct 3 ms 26460 KB Output is correct
3 Correct 4 ms 26456 KB Output is correct
4 Correct 3 ms 26460 KB Output is correct
5 Correct 3 ms 26460 KB Output is correct
6 Correct 4 ms 26460 KB Output is correct
7 Correct 4 ms 26460 KB Output is correct
8 Correct 3 ms 26460 KB Output is correct
9 Correct 4 ms 26460 KB Output is correct
10 Correct 6 ms 26940 KB Output is correct
11 Correct 4 ms 26716 KB Output is correct
12 Correct 5 ms 26716 KB Output is correct
13 Correct 4 ms 26376 KB Output is correct
14 Correct 4 ms 26716 KB Output is correct
15 Correct 4 ms 26716 KB Output is correct
16 Correct 4 ms 26716 KB Output is correct
17 Correct 22 ms 33516 KB Output is correct
18 Correct 20 ms 33588 KB Output is correct
19 Correct 21 ms 33372 KB Output is correct
20 Correct 20 ms 32884 KB Output is correct
21 Correct 20 ms 32860 KB Output is correct
22 Correct 37 ms 39132 KB Output is correct
23 Correct 8 ms 28764 KB Output is correct
24 Correct 20 ms 33076 KB Output is correct
25 Correct 4 ms 26716 KB Output is correct
26 Correct 7 ms 28648 KB Output is correct
27 Correct 6 ms 28252 KB Output is correct
28 Correct 93 ms 61408 KB Output is correct
29 Correct 175 ms 80468 KB Output is correct
30 Correct 175 ms 105644 KB Output is correct
31 Correct 169 ms 107860 KB Output is correct
32 Correct 114 ms 72484 KB Output is correct
33 Correct 178 ms 109572 KB Output is correct
34 Correct 174 ms 109552 KB Output is correct
35 Correct 56 ms 52816 KB Output is correct
36 Correct 171 ms 100180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 54620 KB Output is correct
2 Correct 35 ms 54500 KB Output is correct
3 Correct 56 ms 62804 KB Output is correct
4 Correct 52 ms 62800 KB Output is correct
5 Correct 74 ms 74068 KB Output is correct
6 Correct 73 ms 73228 KB Output is correct
7 Correct 70 ms 73904 KB Output is correct
8 Correct 72 ms 74036 KB Output is correct
9 Correct 93 ms 86360 KB Output is correct
10 Correct 55 ms 54352 KB Output is correct
11 Correct 112 ms 83792 KB Output is correct
12 Correct 4 ms 26460 KB Output is correct
13 Correct 3 ms 26460 KB Output is correct
14 Correct 3 ms 26460 KB Output is correct
15 Correct 4 ms 26460 KB Output is correct
16 Correct 4 ms 26460 KB Output is correct
17 Correct 3 ms 26360 KB Output is correct
18 Correct 35 ms 54616 KB Output is correct
19 Correct 38 ms 54748 KB Output is correct
20 Correct 42 ms 54508 KB Output is correct
21 Correct 35 ms 54620 KB Output is correct
22 Correct 127 ms 83664 KB Output is correct
23 Correct 146 ms 97884 KB Output is correct
24 Correct 155 ms 100832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 66752 KB Output is correct
2 Correct 93 ms 72776 KB Output is correct
3 Correct 36 ms 54576 KB Output is correct
4 Correct 47 ms 54968 KB Output is correct
5 Correct 249 ms 131740 KB Output is correct
6 Correct 298 ms 137756 KB Output is correct
7 Correct 4 ms 26460 KB Output is correct
8 Correct 139 ms 79752 KB Output is correct
9 Correct 152 ms 87328 KB Output is correct
10 Correct 76 ms 66748 KB Output is correct
11 Correct 98 ms 72776 KB Output is correct
12 Correct 4 ms 26460 KB Output is correct
13 Correct 4 ms 26548 KB Output is correct
14 Correct 3 ms 26460 KB Output is correct
15 Correct 4 ms 26456 KB Output is correct
16 Correct 34 ms 54736 KB Output is correct
17 Correct 35 ms 54608 KB Output is correct
18 Correct 94 ms 72124 KB Output is correct
19 Correct 115 ms 79628 KB Output is correct
20 Correct 86 ms 69420 KB Output is correct
21 Correct 90 ms 69140 KB Output is correct
22 Correct 85 ms 69672 KB Output is correct
23 Correct 95 ms 74260 KB Output is correct
24 Correct 38 ms 54620 KB Output is correct
25 Correct 35 ms 54500 KB Output is correct
26 Correct 56 ms 62804 KB Output is correct
27 Correct 52 ms 62800 KB Output is correct
28 Correct 74 ms 74068 KB Output is correct
29 Correct 73 ms 73228 KB Output is correct
30 Correct 70 ms 73904 KB Output is correct
31 Correct 72 ms 74036 KB Output is correct
32 Correct 3 ms 26460 KB Output is correct
33 Correct 3 ms 26460 KB Output is correct
34 Correct 4 ms 26456 KB Output is correct
35 Correct 3 ms 26460 KB Output is correct
36 Correct 3 ms 26460 KB Output is correct
37 Correct 4 ms 26460 KB Output is correct
38 Correct 4 ms 26460 KB Output is correct
39 Correct 3 ms 26460 KB Output is correct
40 Correct 4 ms 26460 KB Output is correct
41 Correct 6 ms 26940 KB Output is correct
42 Correct 4 ms 26716 KB Output is correct
43 Correct 5 ms 26716 KB Output is correct
44 Correct 4 ms 26376 KB Output is correct
45 Correct 4 ms 26716 KB Output is correct
46 Correct 4 ms 26716 KB Output is correct
47 Correct 4 ms 26716 KB Output is correct
48 Correct 22 ms 33516 KB Output is correct
49 Correct 20 ms 33588 KB Output is correct
50 Correct 21 ms 33372 KB Output is correct
51 Correct 20 ms 32884 KB Output is correct
52 Correct 20 ms 32860 KB Output is correct
53 Correct 37 ms 39132 KB Output is correct
54 Correct 8 ms 28764 KB Output is correct
55 Correct 20 ms 33076 KB Output is correct
56 Correct 4 ms 26716 KB Output is correct
57 Correct 7 ms 28648 KB Output is correct
58 Correct 6 ms 28252 KB Output is correct
59 Correct 93 ms 61408 KB Output is correct
60 Correct 175 ms 80468 KB Output is correct
61 Correct 175 ms 105644 KB Output is correct
62 Correct 169 ms 107860 KB Output is correct
63 Correct 114 ms 72484 KB Output is correct
64 Correct 178 ms 109572 KB Output is correct
65 Correct 174 ms 109552 KB Output is correct
66 Correct 56 ms 52816 KB Output is correct
67 Correct 171 ms 100180 KB Output is correct
68 Correct 93 ms 86360 KB Output is correct
69 Correct 55 ms 54352 KB Output is correct
70 Correct 112 ms 83792 KB Output is correct
71 Correct 4 ms 26460 KB Output is correct
72 Correct 3 ms 26460 KB Output is correct
73 Correct 3 ms 26460 KB Output is correct
74 Correct 4 ms 26460 KB Output is correct
75 Correct 4 ms 26460 KB Output is correct
76 Correct 3 ms 26360 KB Output is correct
77 Correct 35 ms 54616 KB Output is correct
78 Correct 38 ms 54748 KB Output is correct
79 Correct 42 ms 54508 KB Output is correct
80 Correct 35 ms 54620 KB Output is correct
81 Correct 127 ms 83664 KB Output is correct
82 Correct 146 ms 97884 KB Output is correct
83 Correct 155 ms 100832 KB Output is correct
84 Correct 254 ms 124704 KB Output is correct
85 Correct 259 ms 126732 KB Output is correct
86 Correct 252 ms 137892 KB Output is correct
87 Correct 258 ms 141396 KB Output is correct
88 Correct 4 ms 26460 KB Output is correct
89 Correct 260 ms 141432 KB Output is correct
90 Correct 225 ms 123772 KB Output is correct
91 Correct 178 ms 105812 KB Output is correct