답안 #729769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729769 2023-04-24T14:18:02 Z Nahian9696 메기 농장 (IOI22_fish) C++17
18 / 100
1000 ms 1727664 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, 9) {
        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 9;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 3148 KB Output is correct
2 Correct 39 ms 3572 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 118 ms 8308 KB Output is correct
6 Correct 104 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 79 ms 5744 KB Output is correct
3 Correct 67 ms 6236 KB Output is correct
4 Correct 27 ms 2692 KB Output is correct
5 Correct 32 ms 3136 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 33 ms 3304 KB Output is correct
13 Correct 55 ms 3896 KB Output is correct
14 Correct 37 ms 3348 KB Output is correct
15 Correct 31 ms 3664 KB Output is correct
16 Correct 28 ms 3304 KB Output is correct
17 Correct 42 ms 3652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 3756 KB Output is correct
3 Correct 27 ms 5248 KB Output is correct
4 Correct 15 ms 5084 KB Output is correct
5 Correct 48 ms 7092 KB Output is correct
6 Correct 27 ms 6700 KB Output is correct
7 Correct 36 ms 7100 KB Output is correct
8 Correct 32 ms 7136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '562886921452394'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '562886921452394'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '562886921452394'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 3756 KB Output is correct
3 Correct 27 ms 5248 KB Output is correct
4 Correct 15 ms 5084 KB Output is correct
5 Correct 48 ms 7092 KB Output is correct
6 Correct 27 ms 6700 KB Output is correct
7 Correct 36 ms 7100 KB Output is correct
8 Correct 32 ms 7136 KB Output is correct
9 Execution timed out 1154 ms 1727664 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 3148 KB Output is correct
2 Correct 39 ms 3572 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 118 ms 8308 KB Output is correct
6 Correct 104 ms 8284 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 79 ms 5744 KB Output is correct
9 Correct 67 ms 6236 KB Output is correct
10 Correct 27 ms 2692 KB Output is correct
11 Correct 32 ms 3136 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 33 ms 3304 KB Output is correct
19 Correct 55 ms 3896 KB Output is correct
20 Correct 37 ms 3348 KB Output is correct
21 Correct 31 ms 3664 KB Output is correct
22 Correct 28 ms 3304 KB Output is correct
23 Correct 42 ms 3652 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 4 ms 3756 KB Output is correct
26 Correct 27 ms 5248 KB Output is correct
27 Correct 15 ms 5084 KB Output is correct
28 Correct 48 ms 7092 KB Output is correct
29 Correct 27 ms 6700 KB Output is correct
30 Correct 36 ms 7100 KB Output is correct
31 Correct 32 ms 7136 KB Output is correct
32 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '562886921452394'
33 Halted 0 ms 0 KB -