답안 #1035761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035761 2024-07-26T14:50:03 Z Andrey 메기 농장 (IOI22_fish) C++17
52 / 100
205 ms 319348 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;

long long haha[5001][5001];
long long dp[5001][5001][3];

long long max_weights(int n, int m, vector<int> x, vector<int> y,  vector<int> w) {
    for(long long i = 0; i <= n; i++) {
        for(long long j = 0; j <= n; j++) {
            haha[i][j] = 0;
        }
    }
    for(long long i = 0; i < m; i++) {
        haha[x[i]+1][y[i]+1] = w[i];
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            haha[i][j]+=haha[i][j-1];
        }
    }
    for(long long i = 0; i <= n; i++) {
        dp[0][i][0] = -LLONG_MAX/2;
        dp[0][i][1] = -LLONG_MAX/2;
        dp[0][i][2] = -LLONG_MAX/2;
    }
    dp[0][0][0] = 0;
    for(long long i = 1; i <= n; i++) {
        long long br = 0;
        for(int j = 0; j <= n; j++) {
            dp[i][j][0] = -LLONG_MAX/2;
            dp[i][j][1] = -LLONG_MAX/2;
            dp[i][j][2] = -LLONG_MAX/2;
        }
        long long x = -LLONG_MAX/2;
        for(long long j = n; j >= 0; j--) {
            x = max(x,max(dp[i-1][j][2],dp[i-1][j][0])+haha[i][j]);
            dp[i][j][2] = x-haha[i][j];
        }
        for(long long j = 0; j <= n; j++) {
            dp[i][j][1] = max(dp[i-1][j][0],dp[i-1][j][2])+haha[i][j];
        }
        x = -LLONG_MAX/2;
        for(long long j = 0; j <= n; j++) {
            x = max(x,dp[i-1][j][1]-haha[i-1][j]);
            dp[i][j][0] = max(dp[i][j][0],x+haha[i-1][j]);
            x = max(x,dp[i-1][j][0]-haha[i-1][j]);
        }
        x = -LLONG_MAX/2;
        for(long long j = n; j >= 0; j--) {
            x = max(x,dp[i-1][j][1]);
            dp[i][j][0] = max(dp[i][j][0],x);
        }
        /*for(long long j = 0; j <= n; j++) {
            br+=haha[i][j];
            long long sb1 = br,sb2 = 0;
            dp[i][j][1] = max(dp[i][j][1],max(dp[i-1][j][0],dp[i-1][j][2])+br);
            for(int k = 0; k <= n; k++) {
                if(k > j) {
                    sb1+=haha[i-1][k];
                    sb2+=haha[i-1][k];
                }
                else {
                    sb1-=haha[i][k];
                }
                if(k <= j) {
                    dp[i][k][2] = max(dp[i][k][2],max(dp[i-1][j][2],dp[i-1][j][0])+sb1);
                }
                else {
                    dp[i][k][0] = max(dp[i][k][0],dp[i-1][j][0]+sb1);
                }
                dp[i][k][0] = max(dp[i][k][0],dp[i-1][j][1]+sb2);
            }
        }*/
    }
    long long ans = 0;
    for(long long i = 0; i <= n; i++) {
        ans = max(ans,max(dp[n][i][0],dp[n][i][1]));
        ans = max(ans,dp[n][i][2]);
    }
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:29:19: warning: unused variable 'br' [-Wunused-variable]
   29 |         long long br = 0;
      |                   ^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 147 ms 199508 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 171 ms 202788 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 158 ms 196200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 344 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 1 ms 2396 KB Output is correct
10 Correct 3 ms 5632 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 5724 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 3 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 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 344 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 1 ms 2396 KB Output is correct
10 Correct 3 ms 5632 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 5724 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 3 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 10 ms 7384 KB Output is correct
18 Correct 10 ms 7516 KB Output is correct
19 Correct 10 ms 7516 KB Output is correct
20 Correct 10 ms 7516 KB Output is correct
21 Correct 10 ms 7516 KB Output is correct
22 Correct 18 ms 9176 KB Output is correct
23 Correct 4 ms 5980 KB Output is correct
24 Correct 8 ms 6792 KB Output is correct
25 Correct 3 ms 5724 KB Output is correct
26 Correct 4 ms 6012 KB Output is correct
# 결과 실행 시간 메모리 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 344 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 1 ms 2396 KB Output is correct
10 Correct 3 ms 5632 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 5724 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 3 ms 5724 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 10 ms 7384 KB Output is correct
18 Correct 10 ms 7516 KB Output is correct
19 Correct 10 ms 7516 KB Output is correct
20 Correct 10 ms 7516 KB Output is correct
21 Correct 10 ms 7516 KB Output is correct
22 Correct 18 ms 9176 KB Output is correct
23 Correct 4 ms 5980 KB Output is correct
24 Correct 8 ms 6792 KB Output is correct
25 Correct 3 ms 5724 KB Output is correct
26 Correct 4 ms 6012 KB Output is correct
27 Correct 150 ms 306948 KB Output is correct
28 Correct 48 ms 32848 KB Output is correct
29 Correct 201 ms 319212 KB Output is correct
30 Correct 205 ms 319228 KB Output is correct
31 Correct 198 ms 319216 KB Output is correct
32 Correct 62 ms 26452 KB Output is correct
33 Correct 204 ms 319348 KB Output is correct
34 Correct 199 ms 319216 KB Output is correct
35 Correct 179 ms 311424 KB Output is correct
36 Correct 196 ms 319220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 158 ms 196200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 147 ms 199508 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -