제출 #1221513

#제출 시각아이디문제언어결과실행 시간메모리
1221513nibert메시지 (IOI24_message)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> ucs(vector<int> A, vector<int> B) {
    int N = A.size(), M = B.size();
    vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));
    
    for (int i = N - 1; i >= 0; --i) {
        for (int j = M - 1; j >= 0; --j) {
            if (A[i] == B[j]) {
                dp[i][j] = 1 + dp[i + 1][j + 1];
            } else {
                dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }

    vector<int> lcs;
    int i = 0, j = 0;
    bool multiple = false;

    while (i < N && j < M) {
        if (A[i] == B[j]) {
            lcs.push_back(A[i]);
            i++;
            j++;
        } else if (dp[i + 1][j] == dp[i][j] && dp[i][j + 1] == dp[i][j]) {
            multiple = true;
            break;
        } else if (dp[i + 1][j] == dp[i][j]) {
            i++;
        } else {
            j++;
        }
    }

    if (multiple) return {-1};
    return lcs;
}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");  
    int N, M;
    input >> N >> M;
    vector<int> A(N), B(M);
    for (int i = 0; i < N; ++i) input >> A[i];
    for (int i = 0; i < M; ++i) input >> B[i];
    vector<int> result = ucs(A, B);
    output << result.size() << "\n";
    for (int value : result) {
        output << value << " ";
    }
    output << "\n";
    input.close();
    output.close(); 
    return 0;
}

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

/usr/bin/ld: /tmp/ccDjLngY.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccox6Wn3.o:message.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccDjLngY.o: in function `(anonymous namespace)::run_decoder()':
stub.cpp:(.text+0x6a1): undefined reference to `receive_message(std::vector<std::vector<bool, std::allocator<bool> >, std::allocator<std::vector<bool, std::allocator<bool> > > >)'
/usr/bin/ld: /tmp/ccDjLngY.o: in function `(anonymous namespace)::run_encoder()':
stub.cpp:(.text+0xc33): undefined reference to `send_message(std::vector<bool, std::allocator<bool> >, std::vector<bool, std::allocator<bool> >)'
collect2: error: ld returned 1 exit status