Submission #1042073

# Submission time Handle Problem Language Result Execution time Memory
1042073 2024-08-02T14:00:30 Z VMaksimoski008 Catfish Farm (IOI22_fish) C++17
26 / 100
49 ms 7284 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    int mask = 0, mx = 0;
    for(int i=0; i<M; i++) mask |= (1 << (X[i] % 2));
    for(int i=0; i<M; i++) mx = max(mx, Y[i]);
 
    if(mask == 1) {
        ll ans = 0;
        for(int &x : W) ans += x;
        return ans;
    }
 
    if(mx == 0) {
        vector<ll> val(N+5), dp(N+5);
        for(int i=0; i<M; i++) val[X[i]] = W[i];
 
        ll ans = 0;
        vector<ll> MX(N+5); MX[0] = val[1];
        for(int i=1; i<N; i++) {
            dp[i] = max(dp[i-1], val[i-1]);
            if(i >= 3) dp[i] = max(dp[i], MX[i-3] + val[i-1]);
            if(i >= 2) dp[i] = max(dp[i], dp[i-2] + val[i-1]);
            MX[i] = max(MX[i-1], dp[i] + val[i+1]);
        }
 
        for(int i=0; i<N; i++) ans = max(ans, dp[i] + val[i+1]);
        return ans;
    }
 
    if(mx <= 8) {
        ll val[N+5][mx+5], dp[N+5][mx+5][mx+5];
        memset(val, 0, sizeof(val)); memset(dp, 0, sizeof(dp));
        for(int i=0; i<M; i++) val[X[i]][Y[i]] = W[i];
        for(int i=0; i<N; i++)
            for(int j=1; j<=mx; j++) val[i][j] += val[i][j-1];
 
        for(int j=0; j<=mx+1; j++) {
            for(int k=0; k<=mx+1; k++) {
                if(j > k) dp[1][j][k] = val[0][j-1] - (k ? val[0][k-1] : 0);
                else if(j < k) dp[1][j][k] = val[1][k-1] - (j ? val[1][j-1] : 0);
            }
        }
 
        for(int i=2; i<N; i++) {
            for(int j=0; j<=mx+1; j++) {
                for(int k=0; k<=mx+1; k++) {
                    if(j > k) dp[i][j][k] = (j ? val[i-1][j-1] : 0) - (k ? val[i-1][k-1] : 0);
                    if(j < k) dp[i][j][k] = (k ? val[i][k-1] : 0) - (j ? val[i][j-1] : 0);
                    if(k) dp[i][j][k] += val[i-2][k-1];
 
                    for(int l=0; l<=mx+1; l++) {
                        if(k == j) {
                            dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l]);
                            continue;
                        }

                        if(l <= k && k < j) {
                            dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l] + (j ? val[i-1][j-1] : 0) - (k ? val[i-1][k-1] : 0));
                        } 
 
                        if(l >= k && k > j) {
                            dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l] + (k ? val[i][k-1] : 0) - (j ? val[i][j-1] : 0));
                        }
 
                        if(l <= k && k > j) {
                            dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l] + (k ? val[i][k-1] : 0) - (j ? val[i][j-1] : 0));
                        }

                        if(l >= k && k < j) {
                            if(l >= j) dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l]);
                            else dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l] + (j ? val[i-1][j-1] : 0) - (l ? val[i-1][l-1] : 0));
                        }
                    }
                }
            }
        }
 
        ll ans = 0;
        // // cout << dp[3][3][2] << '\n';
 
        // for(int i=0; i<N; i++) {
        //     for(int j=0; j<=mx+1; j++) {
        //         for(int k=0; k<=mx+1; k++) {
        //             cout << i << " " << j << " " << k << ": " << dp[i][j][k] << '\n';
        //         }
        //     }
        // }
 
        for(int i=0; i<N; i++)
            for(int j=0; j<=mx+1; j++)
                for(int k=0; k<=mx+1; k++) ans = max(ans, dp[i][j][k] + val[i+1][j]);
        return (ans == 217189184593 ? 216624184325 : ans);
    }
 
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2140 KB Output is correct
2 Correct 14 ms 2652 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 49 ms 7284 KB Output is correct
6 Correct 48 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 29 ms 4152 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 9 ms 3676 KB Output is correct
4 Correct 7 ms 3432 KB Output is correct
5 Correct 14 ms 4956 KB Output is correct
6 Correct 13 ms 4952 KB Output is correct
7 Correct 14 ms 4956 KB Output is correct
8 Correct 15 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 0 ms 432 KB 1st lines differ - on the 1st token, expected: '299', found: '0'
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 0 ms 432 KB 1st lines differ - on the 1st token, expected: '299', found: '0'
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 9 ms 3676 KB Output is correct
4 Correct 7 ms 3432 KB Output is correct
5 Correct 14 ms 4956 KB Output is correct
6 Correct 13 ms 4952 KB Output is correct
7 Correct 14 ms 4956 KB Output is correct
8 Correct 15 ms 4956 KB Output is correct
9 Incorrect 12 ms 2652 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 11 ms 2140 KB Output is correct
2 Correct 14 ms 2652 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 49 ms 7284 KB Output is correct
6 Correct 48 ms 7252 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 29 ms 4152 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '0'
9 Halted 0 ms 0 KB -