답안 #671997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671997 2022-12-14T15:19:56 Z alvingogo Flight to the Ford (BOI22_communication) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
//#include "communication.h"
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

const int B=32000;
vector<int> use(vector<int> a,vector<int> b,int x,int t){
    vector<int> la,ra,lb,rb;
    if(a.size()+b.size()<=3){
        vector<int> g;
        for(auto h:a){
            g.push_back(h);
        }
        for(auto h:b){
            g.push_back(h);
        }
        sort(g.begin(),g.end());
        assert(g.size()==3);
        int u=-1;
        for(int i=0;i<3;i++){
            if(g[i]==x){
                u=i;
            }
        }
        if(t==0){
            if(u==-1){
                return g;
            }
            return vector<int>(1,u);
        }
        else{
            string s[3]={"1111","0001","1000"};
            if(u==-1){
                string z;
                for(int j=0;j<4;j++){
                    z+=char('0'+receive());
                }
                int flag=-1;
                for(int i=0;i<3;i++){
                    int lst=0;
                    for(int j=0;j<4;j++){
                        if(s[i][j]!=z[j]){
                            if(lst){
                                flag=1;
                                break;
                            }
                            else{
                                lst=1;
                            }
                        }
                        else{
                            lst=0;
                        }
                    }
                }
                assert(flag>=0);
                vector<int> ret;
                for(int i=0;i<3;i++){
                    if(i!=flag){
                        ret.push_back(g[i]);
                    }
                }
                return ret;
            }
            else{
                for(int i=0;i<4;i++){
                    send(int(s[u][i]-'0'));
                }
            }   
        }
    }
    int as=a.size(),bs=b.size();
    int nxt=-1;
    for(int i=0;i<as/2;i++){
        if(a[i]==x){
            nxt=0;
        }
        la.push_back(a[i]);
        rb.push_back(a[i]);
    }
    for(int i=as/2;i<as;i++){
        if(a[i]==x){
            nxt=1;
        }
        ra.push_back(a[i]);
        lb.push_back(a[i]);
    }
    for(int i=0;i<(bs+1)/2;i++){
        if(b[i]==x){
            nxt=0;
        }
        la.push_back(b[i]);
    }
    for(int i=(bs+1)/2;i<bs;i++){
        if(b[i]==x){
            nxt=1;
        }
        ra.push_back(b[i]);
    }
    int dd;
    if(nxt==-1){
        dd=receive();
    }
    else{
        dd=send(nxt);
    }
    if(dd==0){
        use(la,lb,x,t);
    }
    else{
        use(la,lb,x,t);
    }
}
const int n=1e9;
void encode(int N,int x){
    int a=x/B;
    int c=x%B;
    vector<int> v(n/B+1);
    iota(v.begin(),v.end(),0);
    auto e=use(v,vector<int>(),a,0);
    vector<int> w(B);
    iota(w.begin(),w.end(),0);
    auto f=use(w,vector<int>(),c,0);
    assert(e.size()==1 && f.size()==1);
    vector<int> z(9);
    iota(z.begin(),z.end(),0);
    auto t=use(z,vector<int>(),3*e[0]+f[0],1);
    assert(t.size()==0); 
}

pair<int,int> decode(int n){
    vector<int> v(n/B+1);
    iota(v.begin(),v.end(),0);
    auto e=use(v,vector<int>(),-1,0);
    vector<int> w(B);
    iota(w.begin(),w.end(),0);
    auto f=use(w,vector<int>(),-1,0);
    assert(e.size()==3 && f.size()==3);
    vector<int> z;
    for(auto h:e){
        for(auto y:f){
            z.push_back(h*B+y);
        }
    }
    auto j=use(z,vector<int>(),-1,1);
    assert(j.size()==2);
    return {j[0],j[1]}; 
}

Compilation message

communication.cpp: In function 'std::vector<int> use(std::vector<int>, std::vector<int>, int, int)':
communication.cpp:40:33: error: 'receive' was not declared in this scope
   40 |                     z+=char('0'+receive());
      |                                 ^~~~~~~
communication.cpp:71:21: error: 'send' was not declared in this scope
   71 |                     send(int(s[u][i]-'0'));
      |                     ^~~~
communication.cpp:106:12: error: 'receive' was not declared in this scope
  106 |         dd=receive();
      |            ^~~~~~~
communication.cpp:109:12: error: 'send' was not declared in this scope
  109 |         dd=send(nxt);
      |            ^~~~
communication.cpp:12:17: warning: control reaches end of non-void function [-Wreturn-type]
   12 |     vector<int> la,ra,lb,rb;
      |                 ^~