답안 #723121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723121 2023-04-13T09:00:40 Z sunnat Flight to the Ford (BOI22_communication) C++17
컴파일 오류
0 ms 0 KB
#include"communication.h"
//
// --- Sample implementation for the task communication ---
//
// To compile this program with the sample grader, place:
//     communication.h communication_sample.cpp sample_grader.cpp
// in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory,
// left click on "Open in terminal") and enter e.g.:
//     g++ -std=c++17 communication_sample.cpp sample_grader.cpp
// in this folder. This will create a file a.out in the current directory which you can execute from the terminal
// as ./a.out
// See task statement or sample_grader.cpp for the input specification
//
void encode(int N, int X) {
    while(N > 0){
        N /= 2;
        send(x%2);
        send(x%2);
        send(x%2);
        x /= 2;        
    }
}
vector<int> a, res;
void brute_force(int x, int i, bool f){
    if(i*3 == a.size()){
        res.push_back(x);
        return;
    }int j = i*3;
    if(f){
        if(a[j] != a[j+1] && a[j] != a[j+2])
            return;
        brute_force(x * 2 + a[i*3], i+1, a[i*3] == a[i*3+2]);
        return;
    }
    
    if(a[j] == a[j+1])
        brute_force(x * 2 + a[j], i+1, a[j] == a[j+2]);
    else if(a[j+1] == a[j+2])
        brute_force(x * 2 + a[j+1], i+1, true);
    else{
        brute_force(x*2+a[j], i+1, a[j] == a[j+2]);
        brute_force(x*2+a[j+1], i+1, a[j+1] == a[j+2]);
    }
}
std::pair<int, int> decode(int N) {
    a.clear();
    while(N > 0){
        N /= 2;
        a.push_back(receive());
        a.push_back(receive());
        a.push_back(receive());
    }
    res.clear();
    brute_force(0, 0, 0);
    sort(res.begin(), res.end());
    
    if(res[0] == 0) res.erase(res.begin());
    if(res.size() == 1) return {res[0], res[0]};
    int i = rnd() % res.size();
    while((j = rnd() % res.size()) != i);
    return {res[i], res[j]};
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:17:14: error: 'x' was not declared in this scope
   17 |         send(x%2);
      |              ^
communication.cpp: At global scope:
communication.cpp:23:1: error: 'vector' does not name a type
   23 | vector<int> a, res;
      | ^~~~~~
communication.cpp: In function 'void brute_force(int, int, bool)':
communication.cpp:25:15: error: 'a' was not declared in this scope
   25 |     if(i*3 == a.size()){
      |               ^
communication.cpp:26:9: error: 'res' was not declared in this scope
   26 |         res.push_back(x);
      |         ^~~
communication.cpp:30:12: error: 'a' was not declared in this scope
   30 |         if(a[j] != a[j+1] && a[j] != a[j+2])
      |            ^
communication.cpp:32:29: error: 'a' was not declared in this scope
   32 |         brute_force(x * 2 + a[i*3], i+1, a[i*3] == a[i*3+2]);
      |                             ^
communication.cpp:36:8: error: 'a' was not declared in this scope
   36 |     if(a[j] == a[j+1])
      |        ^
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:46:5: error: 'a' was not declared in this scope
   46 |     a.clear();
      |     ^
communication.cpp:53:5: error: 'res' was not declared in this scope
   53 |     res.clear();
      |     ^~~
communication.cpp:55:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   55 |     sort(res.begin(), res.end());
      |     ^~~~
      |     short
communication.cpp:58:47: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<int, int>'
   58 |     if(res.size() == 1) return {res[0], res[0]};
      |                                               ^
      |                                               |
      |                                               <brace-enclosed initializer list>
communication.cpp:59:13: error: 'rnd' was not declared in this scope
   59 |     int i = rnd() % res.size();
      |             ^~~
communication.cpp:60:12: error: 'j' was not declared in this scope
   60 |     while((j = rnd() % res.size()) != i);
      |            ^
communication.cpp:61:25: error: 'j' was not declared in this scope
   61 |     return {res[i], res[j]};
      |                         ^
communication.cpp:61:27: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<int, int>'
   61 |     return {res[i], res[j]};
      |                           ^
      |                           |
      |                           <brace-enclosed initializer list>