Submission #601606

# Submission time Handle Problem Language Result Execution time Memory
601606 2022-07-22T08:33:47 Z 반딧불(#8472) Flight to the Ford (BOI22_communication) C++17
46.6667 / 100
3794 ms 2072 KB
#include "communication.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<int> vec;
int mySend(int x){
    vec.push_back(send(x));
    return vec.back();
}

int getBack(int A, int B, int C){
    return vector<int> {0, 0, 1, 2, 2, 2, 1, 1} [A*4+B*2+C];
}

int anna(int X){
    vec.clear();
    if(X==0){
        int tmp = mySend(0);
        if(!tmp){
            tmp = mySend(0);
            if(tmp) mySend(1);
        }
        else mySend(0);
    }
    else if(X==1){
        int tmp = mySend(0);
        if(!tmp){
            tmp = mySend(0);
            if(tmp) mySend(0);
        }
        else mySend(1);
    }
    else{
        int tmp = mySend(1);
        if(tmp){
            tmp = mySend(1);
        }
        else mySend(1), mySend(0);
    }
    return getBack(vec[0], vec[1], vec.size() == 2 ? 0 : vec[2]);
}

void encode(int N, int X){
    X--;
    ll L = 0, R = N-1;
    while(R-L>1){
        ll P = (L+L+R)/3, Q = (L+R+R)/3; /// [0, P], (P, Q], (Q, R]
        ll toSend = (X<=P ? 0 : X<=Q ? 1 : 2);
        ll gone = anna(toSend);
//        printf("Gone: %d\n", gone);
        if(gone == 0) R = Q;
        else if(gone == 1) R -= P+1, X -= P+1;
        else if(toSend == 2) R -= Q+1, R += P+1, X -= Q+1;
        else{
            X += R+1, X -= Q+1;
            R -= Q+1, R += P+1;
        }
    }
}

struct dat{
    ll lim, a, b; /// lim ���ϸ� +a, �ʰ��� +b
    dat(){}
    dat(ll lim, ll a, ll b): lim(lim), a(a), b(b){}

    ll calc(ll x){
        return (x<=lim) ? x+a : x+b;
    }
};

pair<int, int> decode(int N){
    ll L = 0, R = N-1;
    vector<dat> vec;
    while(R-L>1){
        ll P = (L+L+R)/3, Q = (L+R+R)/3; /// [0, P], (P, Q], (Q, R]
        ll A = receive();
        ll B = receive();
        ll C = 0;
        if(A==0 && B==1) C = receive();
        ll gone = getBack(A, B, C);
//        printf("Received: %d\n", gone);
        if(gone == 0) R = Q;
        else if(gone == 1) vec.push_back(dat(LLONG_MAX, P+1, P+1)), R -= P+1;
        else{
            vec.push_back(dat(R-Q-1, Q+1, -R+Q));
            R -= Q+1, R += P+1;
        }
    }
    pair<int, int> ret (L, R);
    for(int i=(int)vec.size()-1; i>=0; i--){
        ret.first = vec[i].calc(ret.first);
        ret.second = vec[i].calc(ret.second);
    }
    ret.first++, ret.second++;
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1720 KB Output is correct
2 Correct 10 ms 1684 KB Output is correct
3 Correct 13 ms 1776 KB Output is correct
4 Correct 10 ms 1780 KB Output is correct
5 Correct 9 ms 1684 KB Output is correct
6 Correct 16 ms 1704 KB Output is correct
7 Correct 40 ms 1668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 788 ms 1700 KB Output is partially correct
2 Partially correct 512 ms 1884 KB Output is partially correct
3 Partially correct 531 ms 1716 KB Output is partially correct
4 Partially correct 891 ms 1804 KB Output is partially correct
5 Partially correct 834 ms 1696 KB Output is partially correct
6 Partially correct 662 ms 1740 KB Output is partially correct
7 Partially correct 2529 ms 1892 KB Output is partially correct
8 Partially correct 3794 ms 2032 KB Output is partially correct
9 Partially correct 3574 ms 2072 KB Output is partially correct
10 Partially correct 3323 ms 1884 KB Output is partially correct
11 Partially correct 3761 ms 1924 KB Output is partially correct
12 Partially correct 3714 ms 1864 KB Output is partially correct
13 Partially correct 3485 ms 1836 KB Output is partially correct
14 Partially correct 3488 ms 1856 KB Output is partially correct
15 Partially correct 1860 ms 1980 KB Output is partially correct
16 Partially correct 3572 ms 1724 KB Output is partially correct
17 Partially correct 895 ms 1876 KB Output is partially correct
18 Partially correct 1013 ms 1748 KB Output is partially correct
19 Partially correct 1081 ms 1872 KB Output is partially correct
20 Partially correct 984 ms 1908 KB Output is partially correct
21 Partially correct 1005 ms 1812 KB Output is partially correct
22 Partially correct 991 ms 1752 KB Output is partially correct
23 Partially correct 1723 ms 1860 KB Output is partially correct
24 Correct 3 ms 1744 KB Output is correct
25 Correct 11 ms 1736 KB Output is correct
26 Correct 12 ms 1680 KB Output is correct
27 Correct 8 ms 1620 KB Output is correct
28 Correct 15 ms 1740 KB Output is correct
29 Correct 17 ms 1688 KB Output is correct
30 Correct 28 ms 1680 KB Output is correct