제출 #1337166

#제출 시각아이디문제언어결과실행 시간메모리
1337166SulA메시지 (IOI24_message)C++20
컴파일 에러
0 ms0 KiB
#include "message.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>

namespace {
    const int PACKET_SIZE = 31;
    const int CALLS_CNT_LIMIT = 100;

    int calls_cnt;
    std::vector<bool> C(PACKET_SIZE);
    std::vector<std::vector<bool>> R;

    void quit(const char* message) {
        printf("%s\n", message);
        exit(0);
    }

    void run_scenario() {
        R.clear();
        calls_cnt = 0;

        int S;
        assert(1 == scanf("%d", &S));
        std::vector<bool> M(S);
        for (int i = 0; i < S; i++) {
            int bit;
            assert(1 == scanf("%d", &bit));
            assert((bit == 0) || (bit == 1));
            M[i] = bit;
        }

        for (int i = 0; i < PACKET_SIZE; i++) {
            int bit;
            assert(1 == scanf("%d", &bit));
            assert((bit == 0) || (bit == 1));
            C[i] = bit;
        }

        send_message(M, C);
        std::vector<bool> D = receive_message(R);

        int K = (int)R.size();
        int L = (int)D.size();
        printf("%d %d\n", K, L);
        for (int i = 0; i < L; i++)
            printf("%s%d", (i == 0 ? "" : " "), (D[i] ? 1 : 0));
        printf("\n");
    }

    std::vector<bool> taint(const std::vector<bool>& A) {
        std::vector<bool> B = A;
        bool bit = 0;
        for (int i = 0; i < PACKET_SIZE; i++)
            if (C[i] == 1) {
                B[i] = bit;
                bit = !bit;
            }
        return B;
    }

} // namespace

std::vector<bool> send_packet(std::vector<bool> A) {
    calls_cnt++;
    if (calls_cnt > CALLS_CNT_LIMIT)
        quit("Too many calls");
    if ((int)A.size() != PACKET_SIZE)
        quit("Invalid argument");

    std::vector<bool> B = taint(A);
    R.push_back(B);
    return B;
}

int main() {
    int T;
    assert(1 == scanf("%d", &T));
    for (int i = 1; i <= T; i++)
        run_scenario();
//    for (int x = 16; x <= 30; x++) {
//        int rem = 30 - x;
//        printf("%d %d %d\n", x, x + (rem-1)/(x-15) + 1, rem % (x - 15) == 0);
//    }
}

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

/usr/bin/ld: /tmp/ccdcw2Us.o: in function `send_packet(std::vector<bool, std::allocator<bool> >)':
stub.cpp:(.text+0x240): multiple definition of `send_packet(std::vector<bool, std::allocator<bool> >)'; /tmp/ccfD39Ll.o:message.cpp:(.text+0x610): first defined here
/usr/bin/ld: /tmp/ccdcw2Us.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccfD39Ll.o:message.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccfD39Ll.o: in function `(anonymous namespace)::run_scenario()':
message.cpp:(.text+0x16e): undefined reference to `send_message(std::vector<bool, std::allocator<bool> >, std::vector<bool, std::allocator<bool> >)'
/usr/bin/ld: message.cpp:(.text+0x24e): 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/ccdcw2Us.o: in function `(anonymous namespace)::run_decoder()':
stub.cpp:(.text+0x65c): 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/ccdcw2Us.o: in function `(anonymous namespace)::run_encoder()':
stub.cpp:(.text+0xbf8): undefined reference to `send_message(std::vector<bool, std::allocator<bool> >, std::vector<bool, std::allocator<bool> >)'
collect2: error: ld returned 1 exit status