Submission #843970

# Submission time Handle Problem Language Result Execution time Memory
843970 2023-09-04T18:21:24 Z Dextar Catfish Farm (IOI22_fish) C++17
70 / 100
891 ms 2097152 KB
#include <cstdio>
#ifdef DEBUG
    #define D(X) X
#else
    #define D(X)
#endif
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pi 3.14159265359
#define pub push_back
#define pob pop_back
#define pari pair<int,int>
#define parli pair<long, long>

using namespace std;
/*
4 8
1 1 1 1 0 0 0 0
0 1 2 3 0 1 2 3
1 3 1 4 2 5 1 1
*/

const int INF = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
    vector<vector<ll>> cnt2(3, vector<ll>(n+1, 0));
    vector<vector<ll>> cnt3(n+1, vector<ll>(3, 0));
    int odd = 0, mx = 0, mxy = 0;
    ll all = 0;
    for(int i=0; i<m; i++) {
        if(x[i]%2==1) {
            odd = 1;
        }
        if(x[i]<=1)
        cnt2[x[i]][y[i]+1] += w[i];
        if(y[i]==0) {
            cnt3[x[i]][y[i]+1] += w[i];
        }
        all += w[i];
        mx = max(mx, x[i]);
        mxy = max(mxy, y[i]);
    }
    if(!odd) {
        return all;
    }
    for(int i=0; i<2; i++) {
        for(int j=1; j<=n; j++) {
            cnt2[i][j] += cnt2[i][j-1];
        }
    }
    /*
    for(int i=0; i<2; i++) {
        for(int j=0; j<=n; j++) {
            cout<<cnt2[i][j]<<" ";
        }
        cout<<endl;
    } */
    if(mx<=1) {
        if(n==2) {
            return max(cnt2[0][n], cnt2[1][n]);
        } else
        {
            ll res = cnt2[1][n], best = res;
            for(int j=1; j<=n; j++) {
                best = max(best, res+cnt2[0][j]-cnt2[1][j]);
                //cout<<res<<" "<<cnt2[0][j]<<" "<<
            }
            return best;
        }
    }
    if(mxy==0) {
        vector<vector<ll>> dp(n+7, vector<ll>(2,0));
        for(int i=n-2; i>=0; i--) {
            dp[i][0] = max(dp[i+1][0], dp[i+1][1] + cnt3[i][1]);
            dp[i][1] = max(dp[i+1][1], max(dp[i+1][0], dp[i+2][0]+cnt3[i+1][1]));
        }
        return max(dp[0][0], dp[0][1]);
    }
    vector<vector<ll>> cnt(n + 1, vector<ll>(n+1, 0));
    for(int i=0; i<m; i++) {
        cnt[x[i]][y[i]+1] += w[i];
    }
    for(int i=0; i<n; i++) {
        for(int j=1; j<=n; j++) {
            cnt[i][j] += cnt[i][j-1];
        }
    }
    vector<vector<ll>> pref(n+1, vector<ll>(n+1, 0));
    vector<vector<ll>> suf(n+1, vector<ll>(n+1, 0));
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(n+1, vector<ll>(2, 0)));
    ll res = 0;
    for(int i=1; i<n; i++) {
        if(i==1) {
            pref[i-1][0] = 0;
        } else
        {
            pref[i-1][0] = dp[i-2][0][0];
        }
        for(int j=1; j<=n; j++) {
            pref[i-1][j] = max(pref[i-1][j-1], dp[i-1][j][1] - cnt[i-1][j]);
        }
        suf[i-1][n] = cnt[i][n] + max(dp[i-1][n][0], dp[i-1][n][1]);
        for(int j=n-1; j>=1; j--) {
            suf[i-1][j] = max(suf[i-1][j+1], max(dp[i-1][j][0], dp[i-1][j][1]) + cnt[i][j]);
        }
        dp[i][0][0] = dp[i][0][1] = max(suf[i-1][1], dp[i-1][0][0]);
        for(int j=1; j<=n; j++) {
            dp[i][j][0] = suf[i-1][j] - cnt[i][j];
            dp[i][j][1] = cnt[i-1][j] + pref[i-1][j];
            if(i>1) {
                dp[i][j][1] = max(dp[i][j][1], cnt[i-1][j]+pref[i-2][j]);
                dp[i][j][1] = max(dp[i][j][1], suf[i-2][j]);
            }
            //res = max(res, max(dp[i][j][0], dp[i][j][1]));
        }
    }
    for(int i=0; i<n; i++)
    for(int j=0; j<=n; j++) {
        for(int bin=0; bin<2; bin++)
            res = max(res, dp[i][j][bin]);
    }
    return res;
}

/*
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    D(freopen("input.txt","r",stdin);)
    //D(freopen("ouput.txt","w",stdout);)
    int t = 1;
    //cin >> t;
    loop:
    while(t--)
    {
        int n, m;
        cin >> n >> m;
        vector<int> x(m), y(m), w(m);
        for(int i=0; i<m; i++) {
            cin >> x[i];
        }
        for(int i=0; i<m; i++) {
            cin >> y[i];
        }
        for(int i=0; i<m; i++) {
            cin >> w[i];
        }
        ll res = max_weights(n, m, x, y, w);
        cout << res;
    }
    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 23 ms 9368 KB Output is correct
2 Correct 28 ms 10568 KB Output is correct
3 Correct 6 ms 8268 KB Output is correct
4 Correct 6 ms 8268 KB Output is correct
5 Correct 73 ms 15168 KB Output is correct
6 Correct 73 ms 15168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 43 ms 11152 KB Output is correct
3 Correct 53 ms 12864 KB Output is correct
4 Correct 23 ms 9360 KB Output is correct
5 Correct 29 ms 10560 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 6 ms 8264 KB Output is correct
11 Correct 6 ms 8268 KB Output is correct
12 Correct 24 ms 9364 KB Output is correct
13 Correct 28 ms 10568 KB Output is correct
14 Correct 24 ms 9368 KB Output is correct
15 Correct 26 ms 10192 KB Output is correct
16 Correct 24 ms 9360 KB Output is correct
17 Correct 26 ms 10156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8264 KB Output is correct
2 Correct 12 ms 13640 KB Output is correct
3 Correct 23 ms 13456 KB Output is correct
4 Correct 20 ms 14400 KB Output is correct
5 Correct 34 ms 15944 KB Output is correct
6 Correct 31 ms 16960 KB Output is correct
7 Correct 34 ms 17484 KB Output is correct
8 Correct 35 ms 17472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 2 ms 2136 KB Output is correct
10 Correct 8 ms 7512 KB Output is correct
11 Correct 2 ms 2140 KB Output is correct
12 Correct 7 ms 7512 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 7 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 2 ms 2136 KB Output is correct
10 Correct 8 ms 7512 KB Output is correct
11 Correct 2 ms 2140 KB Output is correct
12 Correct 7 ms 7512 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 7 ms 7512 KB Output is correct
15 Correct 7 ms 7512 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 17 ms 8536 KB Output is correct
18 Correct 17 ms 8540 KB Output is correct
19 Correct 17 ms 8540 KB Output is correct
20 Correct 16 ms 8536 KB Output is correct
21 Correct 16 ms 8540 KB Output is correct
22 Correct 26 ms 9556 KB Output is correct
23 Correct 8 ms 7772 KB Output is correct
24 Correct 13 ms 8536 KB Output is correct
25 Correct 7 ms 7516 KB Output is correct
26 Correct 9 ms 7772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 2 ms 2136 KB Output is correct
10 Correct 8 ms 7512 KB Output is correct
11 Correct 2 ms 2140 KB Output is correct
12 Correct 7 ms 7512 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 7 ms 7512 KB Output is correct
15 Correct 7 ms 7512 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 17 ms 8536 KB Output is correct
18 Correct 17 ms 8540 KB Output is correct
19 Correct 17 ms 8540 KB Output is correct
20 Correct 16 ms 8536 KB Output is correct
21 Correct 16 ms 8540 KB Output is correct
22 Correct 26 ms 9556 KB Output is correct
23 Correct 8 ms 7772 KB Output is correct
24 Correct 13 ms 8536 KB Output is correct
25 Correct 7 ms 7516 KB Output is correct
26 Correct 9 ms 7772 KB Output is correct
27 Correct 670 ms 706064 KB Output is correct
28 Correct 94 ms 49932 KB Output is correct
29 Correct 735 ms 713040 KB Output is correct
30 Correct 738 ms 713212 KB Output is correct
31 Correct 733 ms 713296 KB Output is correct
32 Correct 87 ms 31056 KB Output is correct
33 Correct 745 ms 713212 KB Output is correct
34 Correct 736 ms 713204 KB Output is correct
35 Correct 697 ms 708688 KB Output is correct
36 Correct 726 ms 713208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8264 KB Output is correct
2 Correct 12 ms 13640 KB Output is correct
3 Correct 23 ms 13456 KB Output is correct
4 Correct 20 ms 14400 KB Output is correct
5 Correct 34 ms 15944 KB Output is correct
6 Correct 31 ms 16960 KB Output is correct
7 Correct 34 ms 17484 KB Output is correct
8 Correct 35 ms 17472 KB Output is correct
9 Runtime error 891 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 9368 KB Output is correct
2 Correct 28 ms 10568 KB Output is correct
3 Correct 6 ms 8268 KB Output is correct
4 Correct 6 ms 8268 KB Output is correct
5 Correct 73 ms 15168 KB Output is correct
6 Correct 73 ms 15168 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 43 ms 11152 KB Output is correct
9 Correct 53 ms 12864 KB Output is correct
10 Correct 23 ms 9360 KB Output is correct
11 Correct 29 ms 10560 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 8264 KB Output is correct
17 Correct 6 ms 8268 KB Output is correct
18 Correct 24 ms 9364 KB Output is correct
19 Correct 28 ms 10568 KB Output is correct
20 Correct 24 ms 9368 KB Output is correct
21 Correct 26 ms 10192 KB Output is correct
22 Correct 24 ms 9360 KB Output is correct
23 Correct 26 ms 10156 KB Output is correct
24 Correct 6 ms 8264 KB Output is correct
25 Correct 12 ms 13640 KB Output is correct
26 Correct 23 ms 13456 KB Output is correct
27 Correct 20 ms 14400 KB Output is correct
28 Correct 34 ms 15944 KB Output is correct
29 Correct 31 ms 16960 KB Output is correct
30 Correct 34 ms 17484 KB Output is correct
31 Correct 35 ms 17472 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 2 ms 2136 KB Output is correct
41 Correct 8 ms 7512 KB Output is correct
42 Correct 2 ms 2140 KB Output is correct
43 Correct 7 ms 7512 KB Output is correct
44 Correct 1 ms 856 KB Output is correct
45 Correct 7 ms 7512 KB Output is correct
46 Correct 7 ms 7512 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 17 ms 8536 KB Output is correct
49 Correct 17 ms 8540 KB Output is correct
50 Correct 17 ms 8540 KB Output is correct
51 Correct 16 ms 8536 KB Output is correct
52 Correct 16 ms 8540 KB Output is correct
53 Correct 26 ms 9556 KB Output is correct
54 Correct 8 ms 7772 KB Output is correct
55 Correct 13 ms 8536 KB Output is correct
56 Correct 7 ms 7516 KB Output is correct
57 Correct 9 ms 7772 KB Output is correct
58 Correct 670 ms 706064 KB Output is correct
59 Correct 94 ms 49932 KB Output is correct
60 Correct 735 ms 713040 KB Output is correct
61 Correct 738 ms 713212 KB Output is correct
62 Correct 733 ms 713296 KB Output is correct
63 Correct 87 ms 31056 KB Output is correct
64 Correct 745 ms 713212 KB Output is correct
65 Correct 736 ms 713204 KB Output is correct
66 Correct 697 ms 708688 KB Output is correct
67 Correct 726 ms 713208 KB Output is correct
68 Runtime error 891 ms 2097152 KB Execution killed with signal 9
69 Halted 0 ms 0 KB -