Submission #1022974

# Submission time Handle Problem Language Result Execution time Memory
1022974 2024-07-14T08:08:49 Z vjudge1 Catfish Farm (IOI22_fish) C++17
70 / 100
283 ms 298576 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second

const int MAXN = 300100;
int n, w[MAXN], m;
pii a[MAXN];

namespace A{
    ll solve(){
        ll ans = 0;
        for(int i=1; i<=m; i++){
            ans += w[i];
        }
        return ans;
    }
}

namespace B{
    ll d[3001][3001];
    ll dp[3001][3001];
    ll pref[3001][3001];
    ll ddp[3001][3001];
    ll suf[3001];
    ll solve(){
        for(int i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
        }
        for(int i=1; i<=n; i++){
            dp[0][i] = -1e18;
            ddp[0][i] = -1e18;
        }
        dp[0][0] = 0;
        ddp[0][0] = 0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                pref[i][j] = pref[i][j - 1] + d[i][j];
            }
            ll mx = -1e18;
            for(int j=n; j>=0; j--){
                mx = max(mx, dp[i-1][j] + pref[i][j]);
                suf[j] = mx;
            }
            ll pddp = -1e18, pdp = -1e18;
            mx = -1e18;
            for(int j=0; j<=n; j++) mx = max(mx, dp[i-1][j]);
            for(int j=0; j<=n; j++){
                ddp[i][j] = mx;
                dp[i][j] = 0;
                pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
                ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
                dp[i][j] = ddp[i][j];
                dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
                pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
            }
        }
        //for(int i=1; i<=n; i++){
        //    for(int j=0; j<=n; j++){
        //        cout<<dp[i][j]<<' ';
        //    }
        //    cout<<'\n';
        //}
        ll ans = 0;
        for(int i=0; i<=n; i++) ans = max(ans, dp[n][i]);
        return ans;
    }
}

namespace C{
    ll d[5][100100];
    ll dp[5][100100];
    ll pref[5][100100];
    ll ddp[5][100100];
    ll suf[100100];
    ll solve(){
        for(int i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
        }
        for(int i=1; i<=n; i++){
            dp[0][i] = -1e18;
            ddp[0][i] = -1e18;
        }
        dp[0][0] = 0;
        ddp[0][0] = 0;
        for(int i=1; i<=3; i++){
            for(int j=1; j<=n; j++){
                pref[i][j] = pref[i][j - 1] + d[i][j];
            }
            ll mx = -1e18;
            for(int j=n; j>=0; j--){
                mx = max(mx, dp[i-1][j] + pref[i][j]);
                suf[j] = mx;
            }
            ll pddp = -1e18, pdp = -1e18;
            mx = -1e18;
            for(int j=0; j<=n; j++) mx = max(mx, dp[i-1][j]);
            for(int j=0; j<=n; j++){
                ddp[i][j] = mx;
                dp[i][j] = 0;
                pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
                ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
                dp[i][j] = ddp[i][j];
                dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
                pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
            }
        }
        //for(int i=1; i<=n; i++){
        //    for(int j=0; j<=n; j++){
        //        cout<<dp[i][j]<<' ';
        //    }
        //    cout<<'\n';
        //}
        ll ans = 0;
        for(int i=0; i<=n; i++) ans = max(ans, dp[3][i]);
        return ans;
    }
}


namespace D{
    ll d[100100][10];
    ll dp[100100][10];
    ll pref[100100][10];
    ll ddp[100100][10];
    ll suf[10];
    ll solve(){
        for(int i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
        }
        for(int i=1; i<=5; i++){
            dp[0][i] = -1e18;
            ddp[0][i] = -1e18;
        }
        dp[0][0] = 0;
        ddp[0][0] = 0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=5; j++){
                pref[i][j] = pref[i][j - 1] + d[i][j];
            }
            ll mx = -1e18;
            for(int j=5; j>=0; j--){
                mx = max(mx, dp[i-1][j] + pref[i][j]);
                suf[j] = mx;
            }
            ll pddp = -1e18, pdp = -1e18;
            mx = -1e18;
            for(int j=0; j<=5; j++) mx = max(mx, dp[i-1][j]);
            for(int j=0; j<=5; j++){
                ddp[i][j] = mx;
                dp[i][j] = 0;
                pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
                ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
                dp[i][j] = ddp[i][j];
                dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
                pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
            }
        }
        //for(int i=1; i<=n; i++){
        //    for(int j=0; j<=n; j++){
        //        cout<<dp[i][j]<<' ';
        //    }
        //    cout<<'\n';
        //}
        ll ans = 0;
        for(int i=0; i<=5; i++) ans = max(ans, dp[n][i]);
        return ans;
    }
}



long long max_weights(int N, int M, vector<int> X, vector<int> Y,
                      vector<int> W) {
    n = N;
    m = M;
    for(int i=1; i<=m; i++){
        a[i] = {X[i-1]+1, Y[i-1]+1};
    }
    for(int i=1; i<=m; i++){
        w[i] = W[i-1];
    }
    int ok1 = 1;
    int ok2 = 1, ok3 = 1;
    for(int i=1; i<=m; i++){
        ok1 &= (a[i].ff % 2 == 1);
        ok2 &= (a[i].ff <= 2);
        ok3 &= (a[i].ss == 1);
    }
    if(ok1) return A::solve();
    if(n <= 3000) return B::solve();
    if(ok2) return C::solve();
    if(ok3) return D::solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4584 KB Output is correct
2 Correct 29 ms 5580 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 120 ms 17248 KB Output is correct
6 Correct 67 ms 17488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 55 ms 18772 KB Output is correct
3 Correct 66 ms 21864 KB Output is correct
4 Correct 18 ms 4688 KB Output is correct
5 Correct 20 ms 5720 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 25 ms 13752 KB Output is correct
13 Correct 47 ms 15696 KB Output is correct
14 Correct 24 ms 13904 KB Output is correct
15 Correct 34 ms 15184 KB Output is correct
16 Correct 22 ms 13916 KB Output is correct
17 Correct 23 ms 15196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 20 ms 23900 KB Output is correct
3 Correct 24 ms 29304 KB Output is correct
4 Correct 21 ms 30556 KB Output is correct
5 Correct 35 ms 36692 KB Output is correct
6 Correct 39 ms 36172 KB Output is correct
7 Correct 35 ms 36760 KB Output is correct
8 Correct 37 ms 36700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 3252 KB Output is correct
10 Correct 4 ms 7416 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 1624 KB Output is correct
14 Correct 4 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 3252 KB Output is correct
10 Correct 4 ms 7416 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 1624 KB Output is correct
14 Correct 4 ms 7260 KB Output is correct
15 Correct 4 ms 7260 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 19 ms 9820 KB Output is correct
18 Correct 14 ms 9664 KB Output is correct
19 Correct 13 ms 10184 KB Output is correct
20 Correct 12 ms 10076 KB Output is correct
21 Correct 13 ms 9932 KB Output is correct
22 Correct 23 ms 12628 KB Output is correct
23 Correct 8 ms 8536 KB Output is correct
24 Correct 10 ms 9516 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 7 ms 8080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 3252 KB Output is correct
10 Correct 4 ms 7416 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 1624 KB Output is correct
14 Correct 4 ms 7260 KB Output is correct
15 Correct 4 ms 7260 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 19 ms 9820 KB Output is correct
18 Correct 14 ms 9664 KB Output is correct
19 Correct 13 ms 10184 KB Output is correct
20 Correct 12 ms 10076 KB Output is correct
21 Correct 13 ms 9932 KB Output is correct
22 Correct 23 ms 12628 KB Output is correct
23 Correct 8 ms 8536 KB Output is correct
24 Correct 10 ms 9516 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 7 ms 8080 KB Output is correct
27 Correct 132 ms 224044 KB Output is correct
28 Correct 54 ms 37460 KB Output is correct
29 Correct 189 ms 231012 KB Output is correct
30 Correct 202 ms 274000 KB Output is correct
31 Correct 215 ms 274516 KB Output is correct
32 Correct 71 ms 34384 KB Output is correct
33 Correct 263 ms 298576 KB Output is correct
34 Correct 283 ms 298576 KB Output is correct
35 Correct 152 ms 232812 KB Output is correct
36 Correct 188 ms 244392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 20 ms 23900 KB Output is correct
3 Correct 24 ms 29304 KB Output is correct
4 Correct 21 ms 30556 KB Output is correct
5 Correct 35 ms 36692 KB Output is correct
6 Correct 39 ms 36172 KB Output is correct
7 Correct 35 ms 36760 KB Output is correct
8 Correct 37 ms 36700 KB Output is correct
9 Incorrect 21 ms 5200 KB 1st lines differ - on the 1st token, expected: '99999', found: '0'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4584 KB Output is correct
2 Correct 29 ms 5580 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 120 ms 17248 KB Output is correct
6 Correct 67 ms 17488 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 55 ms 18772 KB Output is correct
9 Correct 66 ms 21864 KB Output is correct
10 Correct 18 ms 4688 KB Output is correct
11 Correct 20 ms 5720 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 25 ms 13752 KB Output is correct
19 Correct 47 ms 15696 KB Output is correct
20 Correct 24 ms 13904 KB Output is correct
21 Correct 34 ms 15184 KB Output is correct
22 Correct 22 ms 13916 KB Output is correct
23 Correct 23 ms 15196 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 20 ms 23900 KB Output is correct
26 Correct 24 ms 29304 KB Output is correct
27 Correct 21 ms 30556 KB Output is correct
28 Correct 35 ms 36692 KB Output is correct
29 Correct 39 ms 36172 KB Output is correct
30 Correct 35 ms 36760 KB Output is correct
31 Correct 37 ms 36700 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 3252 KB Output is correct
41 Correct 4 ms 7416 KB Output is correct
42 Correct 2 ms 3420 KB Output is correct
43 Correct 3 ms 7516 KB Output is correct
44 Correct 2 ms 1624 KB Output is correct
45 Correct 4 ms 7260 KB Output is correct
46 Correct 4 ms 7260 KB Output is correct
47 Correct 1 ms 1628 KB Output is correct
48 Correct 19 ms 9820 KB Output is correct
49 Correct 14 ms 9664 KB Output is correct
50 Correct 13 ms 10184 KB Output is correct
51 Correct 12 ms 10076 KB Output is correct
52 Correct 13 ms 9932 KB Output is correct
53 Correct 23 ms 12628 KB Output is correct
54 Correct 8 ms 8536 KB Output is correct
55 Correct 10 ms 9516 KB Output is correct
56 Correct 4 ms 7516 KB Output is correct
57 Correct 7 ms 8080 KB Output is correct
58 Correct 132 ms 224044 KB Output is correct
59 Correct 54 ms 37460 KB Output is correct
60 Correct 189 ms 231012 KB Output is correct
61 Correct 202 ms 274000 KB Output is correct
62 Correct 215 ms 274516 KB Output is correct
63 Correct 71 ms 34384 KB Output is correct
64 Correct 263 ms 298576 KB Output is correct
65 Correct 283 ms 298576 KB Output is correct
66 Correct 152 ms 232812 KB Output is correct
67 Correct 188 ms 244392 KB Output is correct
68 Incorrect 21 ms 5200 KB 1st lines differ - on the 1st token, expected: '99999', found: '0'
69 Halted 0 ms 0 KB -