답안 #1079444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079444 2024-08-28T14:45:51 Z asdasdqwer 메기 농장 (IOI22_fish) C++17
53 / 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) {
    // first subtask
    bool s1 = true, s2=true, s3 = true;
    for (int i=0;i<M;i++) {
        if (X[i] % 2 != 0) s1=false;
        if (X[i] > 1) s2=false;
        if (Y[i] != 0) s3 = false;
    }
    if (s1) {
        long long sm = 0;
        for (int i=0;i<M;i++) sm += W[i];
        return sm;
    }


    if (s2) {
        long long sm1=0,sm2=0;
        for (int i=0;i<M;i++) {
            if (X[i] == 0) sm1 += W[i];
            else sm2 += W[i];
        }
        if (N == 2) return max(sm1, sm2);

        vector<long long> p(N, 0), s(N, 0);
        for (int i=0;i<M;i++) {
            if (X[i] == 0) p[Y[i]] += W[i];
            else s[Y[i]] += W[i];
        }

        for (int i=1;i<N;i++) p[i]+=p[i-1];
        for (int i=N-2;i>=0;i--) s[i] += s[i+1];

        long long mx = max(p[N-1], s[0]);
        for (int i=1;i<N;i++) {
            mx = max(mx, p[i-1]+s[i]);
        }

        return mx;
    }

    if (s3) {
        vector<int> w(N,0);
        for (int i=0;i<M;i++) {
            w[X[i]] = W[i];
        }

        vector<long long> dp1(N, 0), dp2(N, 0), dp3(N, 0);
        dp1[0] = dp2[0] = dp3[0] = 0;
        for (int i=1;i<N;i++) {
            // build smt
            dp1[i] = max(dp1[i-1], max(dp2[i-1], dp3[i-1] + w[i-1]));
            dp2[i] = max(dp1[i-1] + w[i], max(dp2[i-1], dp3[i-1]));
            dp3[i] = max(dp3[i-1], dp2[i-1]);
        }

        return max(dp1.back(), max(dp2.back(), dp3.back()));
    }
    
    vector<vector<long long>> dp1(N, vector<long long>(N+1, 0)), dp2(N, vector<long long>(N+1, 0));
    // dp1[i][j] : maximum number of fish such that row i has pier with height j
    // dp2[i][j] : maximum number of fish such that row i has pier with height j and row i-1 has pier with height no greater than j

    vector<vector<long long>> s(N, vector<long long>(N+1, 0));
    for (int i=0;i<M;i++) {
        s[X[i]][Y[i]+1] = W[i];
    }

    for (int i=N-1;i>=0;i--) {
        for (int j=N-1;j>=0;j--) {
            s[i][j] += s[i][j+1];
        }
    }

    long long mx = 0;

    for (int i=1;i<N;i++) {
        for (int j=0;j<=N;j++) {
            long long sub = (j == N ? 0 : s[i-1][j+1]);
            for (int k=0;k<=j;k++) {
                dp1[i][j] = max(dp1[i][j], max(dp2[i-1][k] + (k == N ? 0 : s[i-1][k+1]) - sub, dp1[i-1][k]));
            }
            dp2[i][j] = dp1[i][j];
            sub = (j == N ? 0 : s[i][j+1]);
            for (int k=j+1;k<=N;k++) {
                dp1[i][j] = max(dp1[i][j], max(dp1[i-1][k], dp2[i-1][k]) + sub - (k == N ? 0 : s[i][k+1]));
            }

            mx = max(mx, max(dp1[i][j], dp2[i][j]));
        }
    }

    return mx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3164 KB Output is correct
2 Correct 17 ms 3676 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 57 ms 10580 KB Output is correct
6 Correct 55 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 33 ms 6960 KB Output is correct
3 Correct 41 ms 8528 KB Output is correct
4 Correct 14 ms 3164 KB Output is correct
5 Correct 17 ms 3684 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 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 19 ms 5208 KB Output is correct
14 Correct 17 ms 4716 KB Output is correct
15 Correct 17 ms 4956 KB Output is correct
16 Correct 17 ms 4712 KB Output is correct
17 Correct 19 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 12 ms 4780 KB Output is correct
4 Correct 8 ms 4572 KB Output is correct
5 Correct 19 ms 6492 KB Output is correct
6 Correct 17 ms 6232 KB Output is correct
7 Correct 20 ms 6484 KB Output is correct
8 Correct 20 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 5 ms 856 KB Output is correct
10 Correct 31 ms 2652 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 31 ms 2396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 31 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 5 ms 856 KB Output is correct
10 Correct 31 ms 2652 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 31 ms 2396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 31 ms 2396 KB Output is correct
15 Correct 33 ms 2396 KB Output is correct
16 Correct 1 ms 496 KB Output is correct
17 Correct 39 ms 4184 KB Output is correct
18 Correct 44 ms 4184 KB Output is correct
19 Correct 39 ms 4188 KB Output is correct
20 Correct 46 ms 4188 KB Output is correct
21 Correct 39 ms 4188 KB Output is correct
22 Correct 46 ms 5980 KB Output is correct
23 Correct 31 ms 2904 KB Output is correct
24 Correct 36 ms 3676 KB Output is correct
25 Correct 29 ms 2392 KB Output is correct
26 Correct 32 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 5 ms 856 KB Output is correct
10 Correct 31 ms 2652 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 31 ms 2396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 31 ms 2396 KB Output is correct
15 Correct 33 ms 2396 KB Output is correct
16 Correct 1 ms 496 KB Output is correct
17 Correct 39 ms 4184 KB Output is correct
18 Correct 44 ms 4184 KB Output is correct
19 Correct 39 ms 4188 KB Output is correct
20 Correct 46 ms 4188 KB Output is correct
21 Correct 39 ms 4188 KB Output is correct
22 Correct 46 ms 5980 KB Output is correct
23 Correct 31 ms 2904 KB Output is correct
24 Correct 36 ms 3676 KB Output is correct
25 Correct 29 ms 2392 KB Output is correct
26 Correct 32 ms 2908 KB Output is correct
27 Execution timed out 1071 ms 212052 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 12 ms 4780 KB Output is correct
4 Correct 8 ms 4572 KB Output is correct
5 Correct 19 ms 6492 KB Output is correct
6 Correct 17 ms 6232 KB Output is correct
7 Correct 20 ms 6484 KB Output is correct
8 Correct 20 ms 6484 KB Output is correct
9 Runtime error 822 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3164 KB Output is correct
2 Correct 17 ms 3676 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 57 ms 10580 KB Output is correct
6 Correct 55 ms 10836 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 33 ms 6960 KB Output is correct
9 Correct 41 ms 8528 KB Output is correct
10 Correct 14 ms 3164 KB Output is correct
11 Correct 17 ms 3684 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 16 ms 4700 KB Output is correct
19 Correct 19 ms 5208 KB Output is correct
20 Correct 17 ms 4716 KB Output is correct
21 Correct 17 ms 4956 KB Output is correct
22 Correct 17 ms 4712 KB Output is correct
23 Correct 19 ms 4956 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 3164 KB Output is correct
26 Correct 12 ms 4780 KB Output is correct
27 Correct 8 ms 4572 KB Output is correct
28 Correct 19 ms 6492 KB Output is correct
29 Correct 17 ms 6232 KB Output is correct
30 Correct 20 ms 6484 KB Output is correct
31 Correct 20 ms 6484 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 432 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 856 KB Output is correct
41 Correct 31 ms 2652 KB Output is correct
42 Correct 5 ms 860 KB Output is correct
43 Correct 31 ms 2396 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 31 ms 2396 KB Output is correct
46 Correct 33 ms 2396 KB Output is correct
47 Correct 1 ms 496 KB Output is correct
48 Correct 39 ms 4184 KB Output is correct
49 Correct 44 ms 4184 KB Output is correct
50 Correct 39 ms 4188 KB Output is correct
51 Correct 46 ms 4188 KB Output is correct
52 Correct 39 ms 4188 KB Output is correct
53 Correct 46 ms 5980 KB Output is correct
54 Correct 31 ms 2904 KB Output is correct
55 Correct 36 ms 3676 KB Output is correct
56 Correct 29 ms 2392 KB Output is correct
57 Correct 32 ms 2908 KB Output is correct
58 Execution timed out 1071 ms 212052 KB Time limit exceeded
59 Halted 0 ms 0 KB -