답안 #729772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729772 2023-04-24T14:19:06 Z Nahian9696 메기 농장 (IOI22_fish) C++17
18 / 100
1000 ms 2097152 KB
#include "fish.h"

#include <vector>
#include <bits/stdc++.h>

using namespace std;


#define f0(i, n) for(int i = 0; i <  (n); i++)
#define f1(i, n) for(int i = 1; i <= (n); i++)
#define pb push_back
#define ff first
#define ss second

typedef vector<int> vi;
typedef long long ll;



long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    bool allxeven = true;
    bool allxleq1 = true;
    bool ally0 = true;

    f0(i, M) {
        if(X[i] % 2 == 1) allxeven = false;
        if(X[i] > 1) allxleq1 = false;
        if(Y[i] != 0) ally0 = false;
    }


    if (allxeven) {
        ll ret = 0;
        f0(i, M) ret += W[i];
        return ret;
    } 
    if(allxleq1) {
        ll ret = 0;
        ll ans = 0;
        int arr[N][2];
        f0(i, N) arr[i][0] = 0, arr[i][1] = 0;
        f0(i, M) {
            arr[Y[i]][X[i]] = W[i];
        }

        if(N == 2) {
            return max(arr[0][0] + arr[1][0], arr[0][1] + arr[1][1]);
        }

        f0(i, N) {
            ans += arr[i][1];
        }
        ret = ans;
        f0(i, N) {
            ans -= arr[i][1];
            ans += arr[i][0];
            ret = max(ret, ans);
        }
        return ret;
    }
    if(ally0) {
        int arr[N];
        f0(i, N) arr[i] = 0;
        f0(i, M) arr[X[i]] = W[i];
        ll dp[N][4];
        dp[0][0] = -1e18;
        dp[0][1] = -1e18;
        dp[0][2] = 0;
        dp[0][3] = arr[0];

        dp[1][0] = 0;
        dp[1][1] = arr[1];
        dp[1][2] = arr[0];
        dp[1][3] = -1e18;


        f1(i, N-2) {
            dp[i+1][0] = max(dp[i][0], dp[i][2]);
            dp[i+1][1] = max(dp[i][0], dp[i][2]) + arr[i+1];
            dp[i+1][2] = max(dp[i][1], dp[i][3]);
            dp[i+1][3] = dp[i][1] + arr[i+1];
        }
        return max({
            dp[N-1][0],
            dp[N-1][1],
            dp[N-1][2]
        });
    }


    ll arr[N][N];
    f0(i, N) f0(j, N) arr[i][j] = 0;


    f0(i, M) {
        arr[X[i]][Y[i]+1] = W[i];
    }

    ll prefarr[N][N];
    f0(i, N) prefarr[i][0] = 0;

    f0(i, N) f1(j, N-1) {
        prefarr[i][j] = prefarr[i][j-1] + arr[i][j];
    }

    ll dp[N][N][N][N];
    ll mxdp[N][N][N];

    f0(i, N) f0(j, N) {
        f0(k, N) dp[0][i][j][k] = 0;
        mxdp[0][i][j] = 0;
    }


    f0(i, N) f0(j, N) {
        ll val = 0;
        if(i > j) {
            for(int x = j+1; x <= i; x++) val += arr[0][x];
        } else {
            for(int x = i+1; x <= j; x++) val += arr[1][x];
        }
        mxdp[1][i][j] = val;
        f0(k, N) {
            dp[1][i][j][k] = val;
        }
    }


    f1(col, N-2) {
        f0(i, N) f0(j, N) {
            ll mx = 0;
            f0(k, N) {
                dp[col+1][i][j][k] = mxdp[col][j][k];
                if(max(j, k) <= i) {
                    dp[col+1][i][j][k] += prefarr[col][i] - prefarr[col][max(j, k)];
                }
                if(j >= i) dp[col+1][i][j][k] += prefarr[col+1][j] - prefarr[col+1][i];
                mx = max(mx, dp[col+1][i][j][k]);
            }
            mxdp[col+1][i][j] = mx;
            // cout << mx << endl;
        }
    }

    ll ans = 0;
    f0(i, N) f0(j, N) ans = max(ans, mxdp[N-1][i][j]);

    return ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3404 KB Output is correct
2 Correct 33 ms 4140 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 8804 KB Output is correct
6 Correct 95 ms 8800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 54 ms 6328 KB Output is correct
3 Correct 74 ms 6484 KB Output is correct
4 Correct 37 ms 2844 KB Output is correct
5 Correct 42 ms 3384 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 27 ms 3684 KB Output is correct
13 Correct 34 ms 4152 KB Output is correct
14 Correct 28 ms 3636 KB Output is correct
15 Correct 29 ms 3916 KB Output is correct
16 Correct 28 ms 3588 KB Output is correct
17 Correct 30 ms 3940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 19 ms 5492 KB Output is correct
4 Correct 14 ms 5200 KB Output is correct
5 Correct 32 ms 7620 KB Output is correct
6 Correct 25 ms 6984 KB Output is correct
7 Correct 31 ms 7580 KB Output is correct
8 Correct 34 ms 7520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Execution timed out 1135 ms 2097152 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Execution timed out 1135 ms 2097152 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Execution timed out 1135 ms 2097152 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 19 ms 5492 KB Output is correct
4 Correct 14 ms 5200 KB Output is correct
5 Correct 32 ms 7620 KB Output is correct
6 Correct 25 ms 6984 KB Output is correct
7 Correct 31 ms 7580 KB Output is correct
8 Correct 34 ms 7520 KB Output is correct
9 Execution timed out 1121 ms 2097152 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3404 KB Output is correct
2 Correct 33 ms 4140 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 8804 KB Output is correct
6 Correct 95 ms 8800 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 54 ms 6328 KB Output is correct
9 Correct 74 ms 6484 KB Output is correct
10 Correct 37 ms 2844 KB Output is correct
11 Correct 42 ms 3384 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 27 ms 3684 KB Output is correct
19 Correct 34 ms 4152 KB Output is correct
20 Correct 28 ms 3636 KB Output is correct
21 Correct 29 ms 3916 KB Output is correct
22 Correct 28 ms 3588 KB Output is correct
23 Correct 30 ms 3940 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 3796 KB Output is correct
26 Correct 19 ms 5492 KB Output is correct
27 Correct 14 ms 5200 KB Output is correct
28 Correct 32 ms 7620 KB Output is correct
29 Correct 25 ms 6984 KB Output is correct
30 Correct 31 ms 7580 KB Output is correct
31 Correct 34 ms 7520 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Execution timed out 1135 ms 2097152 KB Time limit exceeded
41 Halted 0 ms 0 KB -