답안 #1079432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079432 2024-08-28T14:36:04 Z asdasdqwer 메기 농장 (IOI22_fish) C++17
18 / 100
778 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] + s[i-1][k] - 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 3676 KB Output is correct
2 Correct 27 ms 4436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 60 ms 13672 KB Output is correct
6 Correct 56 ms 14032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 30 ms 8480 KB Output is correct
3 Correct 37 ms 10072 KB Output is correct
4 Correct 14 ms 3672 KB Output is correct
5 Correct 17 ms 4444 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 440 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 19 ms 5104 KB Output is correct
13 Correct 18 ms 6080 KB Output is correct
14 Correct 16 ms 4956 KB Output is correct
15 Correct 17 ms 5724 KB Output is correct
16 Correct 16 ms 4972 KB Output is correct
17 Correct 17 ms 5572 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 11 ms 5048 KB Output is correct
4 Correct 8 ms 4568 KB Output is correct
5 Correct 21 ms 7360 KB Output is correct
6 Correct 16 ms 6488 KB Output is correct
7 Correct 18 ms 6852 KB Output is correct
8 Correct 21 ms 7112 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 432 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 4 ms 860 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '218495453137'
10 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 432 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 4 ms 860 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '218495453137'
10 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 432 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 4 ms 860 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '218495453137'
10 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 11 ms 5048 KB Output is correct
4 Correct 8 ms 4568 KB Output is correct
5 Correct 21 ms 7360 KB Output is correct
6 Correct 16 ms 6488 KB Output is correct
7 Correct 18 ms 6852 KB Output is correct
8 Correct 21 ms 7112 KB Output is correct
9 Runtime error 778 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3676 KB Output is correct
2 Correct 27 ms 4436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 60 ms 13672 KB Output is correct
6 Correct 56 ms 14032 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 30 ms 8480 KB Output is correct
9 Correct 37 ms 10072 KB Output is correct
10 Correct 14 ms 3672 KB Output is correct
11 Correct 17 ms 4444 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 440 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 19 ms 5104 KB Output is correct
19 Correct 18 ms 6080 KB Output is correct
20 Correct 16 ms 4956 KB Output is correct
21 Correct 17 ms 5724 KB Output is correct
22 Correct 16 ms 4972 KB Output is correct
23 Correct 17 ms 5572 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 3164 KB Output is correct
26 Correct 11 ms 5048 KB Output is correct
27 Correct 8 ms 4568 KB Output is correct
28 Correct 21 ms 7360 KB Output is correct
29 Correct 16 ms 6488 KB Output is correct
30 Correct 18 ms 6852 KB Output is correct
31 Correct 21 ms 7112 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 432 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 436 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Incorrect 4 ms 860 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '218495453137'
41 Halted 0 ms 0 KB -