답안 #969628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969628 2024-04-25T11:32:46 Z vjudge1 메기 농장 (IOI22_fish) C++17
52 / 100
1000 ms 2097152 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    vector<vector<int64_t>> pref(N, vector<int64_t>(N + 1));
    vector<vector<int>> a(N, vector<int>(N));

    for (int i = 0; i < M; i++) {
        a[X[i]][Y[i]] = W[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) pref[i][j + 1] = pref[i][j] + a[i][j];
    }
    const int64_t inf = 1e18;
    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(2, -inf));
    dp[0][0] = 0;
    dp[N][1] = 0;
    for (int i = 0; i < N; i++) {
        vector<vector<int64_t>> ndp(N + 1, vector<int64_t>(2, -inf));
        if (i + 1 < N) {
            for (int j = 0; j < N; j++) {
                dp[j + 1][0] = max(dp[j + 1][0], dp[j][0] + a[i][j]);
            }
        }
        for (int j = N - 1; j > 0; j--) {
            dp[j - 1][1] = max(dp[j - 1][1], dp[j][1] + a[i][j - 1]);
        }
        if (i == 1) dp[0][0] = max(dp[0][0], pref[0][N]);
        if (i + 2 < N) dp[0][0] = max(dp[0][0], dp[0][1]);
        if (i == N - 1) break;
        for (int j = 0; j <= N; j++) {
            ndp[j][0] = max(ndp[j][0], dp[j][0]);
            if (j == N) ndp[N][1] = max(ndp[N][1], dp[j][0]);
            if (j == 0) ndp[N][1] = max(ndp[N][1], dp[j][0]);
            if (j == 0 && i + 1 == N - 1) ndp[N][0] = max(ndp[N][0], dp[0][0] + pref[N - 1][N]);
        }
        for (int j = 0; j <= N; j++) {
            ndp[j][1] = max(ndp[j][1], dp[j][1]);
            if (j == N) ndp[N - 1][1] = max(ndp[N - 1][1], dp[j][1] + a[i + 1][N - 1]);
            if (i + 2 < N && j == 0) ndp[0][0] = max(ndp[0][0], dp[j][1]);
            if (j == 0) ndp[0][0] = max(ndp[0][0], dp[j][1]);
        }
        ndp.swap(dp);
    }

    return max(dp[0][1], max(dp[N][0], dp[N][1]));
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1117 ms 2067000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 781 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 731 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 2 ms 604 KB Output is correct
10 Correct 5 ms 1628 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 2 ms 604 KB Output is correct
10 Correct 5 ms 1628 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1584 KB Output is correct
15 Correct 5 ms 1368 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 17 ms 3532 KB Output is correct
18 Correct 15 ms 3136 KB Output is correct
19 Correct 15 ms 3128 KB Output is correct
20 Correct 18 ms 3272 KB Output is correct
21 Correct 15 ms 3320 KB Output is correct
22 Correct 25 ms 4952 KB Output is correct
23 Correct 6 ms 1880 KB Output is correct
24 Correct 11 ms 2652 KB Output is correct
25 Correct 5 ms 1368 KB Output is correct
26 Correct 6 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 2 ms 604 KB Output is correct
10 Correct 5 ms 1628 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1584 KB Output is correct
15 Correct 5 ms 1368 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 17 ms 3532 KB Output is correct
18 Correct 15 ms 3136 KB Output is correct
19 Correct 15 ms 3128 KB Output is correct
20 Correct 18 ms 3272 KB Output is correct
21 Correct 15 ms 3320 KB Output is correct
22 Correct 25 ms 4952 KB Output is correct
23 Correct 6 ms 1880 KB Output is correct
24 Correct 11 ms 2652 KB Output is correct
25 Correct 5 ms 1368 KB Output is correct
26 Correct 6 ms 1880 KB Output is correct
27 Correct 411 ms 106580 KB Output is correct
28 Correct 73 ms 15888 KB Output is correct
29 Correct 473 ms 119392 KB Output is correct
30 Correct 484 ms 119380 KB Output is correct
31 Correct 479 ms 119328 KB Output is correct
32 Correct 82 ms 16212 KB Output is correct
33 Correct 470 ms 119124 KB Output is correct
34 Correct 499 ms 119320 KB Output is correct
35 Correct 426 ms 111352 KB Output is correct
36 Correct 478 ms 119432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 731 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1117 ms 2067000 KB Time limit exceeded
2 Halted 0 ms 0 KB -