답안 #672020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672020 2022-12-14T15:50:03 Z alvingogo Flight to the Ford (BOI22_communication) C++17
컴파일 오류
0 ms 0 KB
vector<int> use(vector<int> a,vector<int> b,int x,int t){
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a.size()+b.size()<=2){
        vector<int> z;
        for(auto h:a){
            z.push_back(h);
        }
        for(auto h:b){
            z.push_back(h);
        }
        if(z.size()==1){
            z.push_back(z[0]);
        }
        return z;
    }
    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());
        int u=-1;
        for(int i=0;i<3;i++){
            if(g[i]==x){
                u=i;
            }
        }
        if(t==0){
            return g;
        }
        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=i;
                                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'));
                }
                return vector<int>();
            }   
        }
    }
    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){
        return use(la,lb,x,t);
    }
    else{
        return use(ra,rb,x,t);
    }
}
const int n=1e9+7;
const int B=31898;
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()==3 && f.size()==3);
    vector<int> z;
    for(auto h:e){
        for(auto y:f){
            if(h*B+y<=0 || h*B+y>N){
                continue;
            }
            z.push_back(h*B+y);
        }
    }
    auto t=use(z,vector<int>(),x,1);
    assert(t.size()==0); 
    for(int i=0;i<z.size();i++){
        if(z[i]==x){
            break;
        }
    }
}

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){
            if(h*B+y<=0 || h*B+y>N){
                continue;
            }
            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:1:1: error: 'vector' does not name a type
    1 | vector<int> use(vector<int> a,vector<int> b,int x,int t){
      | ^~~~~~
communication.cpp: In function 'void encode(int, int)':
communication.cpp:125:5: error: 'vector' was not declared in this scope
  125 |     vector<int> v(n/B+1);
      |     ^~~~~~
communication.cpp:125:12: error: expected primary-expression before 'int'
  125 |     vector<int> v(n/B+1);
      |            ^~~
communication.cpp:126:10: error: 'v' was not declared in this scope
  126 |     iota(v.begin(),v.end(),0);
      |          ^
communication.cpp:126:5: error: 'iota' was not declared in this scope
  126 |     iota(v.begin(),v.end(),0);
      |     ^~~~
communication.cpp:127:25: error: expected primary-expression before 'int'
  127 |     auto e=use(v,vector<int>(),a,0);
      |                         ^~~
communication.cpp:127:12: error: 'use' was not declared in this scope
  127 |     auto e=use(v,vector<int>(),a,0);
      |            ^~~
communication.cpp:128:12: error: expected primary-expression before 'int'
  128 |     vector<int> w(B);
      |            ^~~
communication.cpp:129:10: error: 'w' was not declared in this scope
  129 |     iota(w.begin(),w.end(),0);
      |          ^
communication.cpp:130:25: error: expected primary-expression before 'int'
  130 |     auto f=use(w,vector<int>(),c,0);
      |                         ^~~
communication.cpp:131:5: error: 'assert' was not declared in this scope
  131 |     assert(e.size()==3 && f.size()==3);
      |     ^~~~~~
communication.cpp:1:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
  +++ |+#include <cassert>
    1 | vector<int> use(vector<int> a,vector<int> b,int x,int t){
communication.cpp:132:12: error: expected primary-expression before 'int'
  132 |     vector<int> z;
      |            ^~~
communication.cpp:138:13: error: 'z' was not declared in this scope
  138 |             z.push_back(h*B+y);
      |             ^
communication.cpp:141:16: error: 'z' was not declared in this scope
  141 |     auto t=use(z,vector<int>(),x,1);
      |                ^
communication.cpp:141:25: error: expected primary-expression before 'int'
  141 |     auto t=use(z,vector<int>(),x,1);
      |                         ^~~
communication.cpp: At global scope:
communication.cpp:150:1: error: 'pair' does not name a type
  150 | pair<int,int> decode(int N){
      | ^~~~