Submission #672075

# Submission time Handle Problem Language Result Execution time Memory
672075 2022-12-14T16:55:26 Z alvingogo Flight to the Ford (BOI22_communication) C++17
15 / 100
7998 ms 21780 KB
#include <bits/stdc++.h>
#include "communication.h"
using namespace std;

typedef long long ll;
vector<ll> use(vector<ll> a,vector<ll> b,ll x,ll t){
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll as=a.size();
    ll bs=b.size();
    vector<ll> la,ra,lb,rb;
    if(as+bs<=2){
        vector<ll> z;
        for(auto h:a){
            z.push_back(h);
        }
        for(auto h:b){
            z.push_back(h);
        }
        assert(z.size());
        if(z.size()==1){
            z.push_back(z[0]);
        }
        return z;
    }
    else if(as+bs==3){
        vector<ll> g;
        for(auto h:a){
            g.push_back(h);
        }
        for(auto h:b){
            g.push_back(h);
        }
        sort(g.begin(),g.end());
        ll u=-1;
        for(ll 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(ll j=0;j<4;j++){
                    z+=char('0'+receive());
                }
                ll flag=-1;
                for(ll i=0;i<3;i++){
                    ll lst=0;
                    for(ll 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<ll> ret;
                for(ll i=0;i<3;i++){
                    if(i!=flag){
                        ret.push_back(g[i]);
                    }
                }
                return ret;
            }
            else{
                for(ll i=0;i<4;i++){
                    send(ll(s[u][i]-'0'));
                }
                return vector<ll>();
            }   
        }
    }
    ll nxt=-1;
    for(ll i=0;i<as/2;i++){
        if(a[i]==x){
            nxt=0;
        }
        la.push_back(a[i]);
        rb.push_back(a[i]);
    }
    for(ll i=as/2;i<as;i++){
        if(a[i]==x){
            nxt=1;
        }
        ra.push_back(a[i]);
        lb.push_back(a[i]);
    }
    for(ll i=0;i<(bs+1)/2;i++){
        if(b[i]==x){
            nxt=0;
        }
        la.push_back(b[i]);
    }
    for(ll i=(bs+1)/2;i<bs;i++){
        if(b[i]==x){
            nxt=1;
        }
        ra.push_back(b[i]);
    }
    ll 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 ll Bd=31647;
void encode(int N,int X){
    ll a=X/Bd;
    ll c=X%Bd;
    vector<ll> v(max(3ll,N/Bd+2));
    iota(v.begin(),v.end(),0);
    auto e=use(v,vector<ll>(),a,0);
    vector<ll> w(Bd);
    iota(w.begin(),w.end(),0);
    auto f=use(w,vector<ll>(),c,0);
    assert(e.size()==3 && f.size()==3);
    vector<ll> z;
    for(auto h:e){
        for(auto y:f){
            if(h*Bd+y<=0 || h*Bd+y>N){
                continue;
            }
            z.push_back(h*Bd+y);
        }
    }
    use(z,vector<ll>(),X,1);
}

pair<int,int> decode(int N){
    vector<ll> v(max(3ll,N/Bd+2));
    iota(v.begin(),v.end(),0);
    auto e=use(v,vector<ll>(),-1,0);
    vector<ll> w(Bd);
    iota(w.begin(),w.end(),0);
    auto f=use(w,vector<ll>(),-1,0);
    assert(e.size()==3 && f.size()==3);
    vector<ll> z;
    for(auto h:e){
        for(auto y:f){
            if(h*Bd+y<=0 || h*Bd+y>N){
                continue;
            }
            z.push_back(h*Bd+y);
        }
    }
    auto j=use(z,vector<ll>(),-1,1);
    return {j[0],j[1]}; 
}
# Verdict Execution time Memory Grader output
1 Correct 490 ms 11568 KB Output is correct
2 Correct 643 ms 11728 KB Output is correct
3 Correct 924 ms 11608 KB Output is correct
4 Correct 506 ms 11600 KB Output is correct
5 Correct 656 ms 11592 KB Output is correct
6 Correct 1754 ms 21780 KB Output is correct
7 Correct 3269 ms 11732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 5716 ms 12392 KB Output is partially correct
2 Partially correct 3657 ms 12148 KB Output is partially correct
3 Partially correct 4576 ms 12140 KB Output is partially correct
4 Partially correct 7998 ms 12028 KB Output is partially correct
5 Partially correct 6994 ms 12124 KB Output is partially correct
6 Correct 5927 ms 12240 KB Output is correct
7 Incorrect 5937 ms 5580 KB Security violation!
8 Halted 0 ms 0 KB -