제출 #1161118

#제출 시각아이디문제언어결과실행 시간메모리
1161118jj_master메기 농장 (IOI22_fish)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int64_t max_weights(int N, int M, vector<int>& X, vector<int>& Y, vector<int>& W) {
    // Group catfish by their columns
    map<int, vector<pair<int, int>>> catfish_in_column;
    for (int i = 0; i < M; ++i) {
        catfish_in_column[X[i]].push_back({Y[i], W[i]});
    }

    // Sort the catfish in each column by their row position (Y[i])
    for (auto& entry : catfish_in_column) {
        sort(entry.second.begin(), entry.second.end());
    }

    // DP array to store maximum weight of catfish caught up to each column
    vector<int64_t> dp(N, 0);

    // Process each column
    for (int col = 0; col < N; ++col) {
        // Max weight up to column `col` without any pier in this column
        if (col > 0) {
            dp[col] = dp[col - 1];
        }

        // Catfish caught in the current column if we build a pier here
        int64_t catfish_caught = 0;
        for (auto& fish : catfish_in_column[col]) {
            int row = fish.first;
            int weight = fish.second;

            // Check if catfish is eligible to be caught
            bool can_be_caught = false;
            if (col > 0) {
                // Check if there is no catfish directly in column `col-1` at the same row
                bool caught_from_left = true;
                for (auto& left_fish : catfish_in_column[col - 1]) {
                    if (left_fish.first == row) {
                        caught_from_left = false;
                        break;
                    }
                }
                if (caught_from_left) can_be_caught = true;
            }

            if (col < N - 1) {
                // Check if there is no catfish directly in column `col+1` at the same row
                bool caught_from_right = true;
                for (auto& right_fish : catfish_in_column[col + 1]) {
                    if (right_fish.first == row) {
                        caught_from_right = false;
                        break;
                    }
                }
                if (caught_from_right) can_be_caught = true;
            }

            if (can_be_caught) {
                catfish_caught += weight;
            }
        }

        // Add the catfish caught in this column if we build a pier here
        if (col > 0) {
            dp[col] = max(dp[col], dp[col - 1] + catfish_caught);
        } else {
            dp[col] = max(dp[col], catfish_caught);
        }
    }

    // The result is the maximum weight that can be caught up to the last column
    return dp[N - 1];
}

int main() {
    // Input
    int N, M;
    cin >> N >> M;
    vector<int> X(M), Y(M), W(M);

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

    // Calculate and output the maximum weight of catfish that can be caught
    cout << max_weights(N, M, X, Y, W) << endl;

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/cczfwYNf.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccJGyrwG.o:fish.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cczfwYNf.o: in function `main':
grader.cpp:(.text.startup+0x267): undefined reference to `max_weights(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status