답안 #601647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601647 2022-07-22T08:56:36 Z 반딧불(#8472) Flight to the Ford (BOI22_communication) C++17
46.6667 / 100
3881 ms 1984 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){
//    srand(N);
//    for(int i=1; i<=10; i++) printf("%d ", rand());
//    puts("");
    X--;
    ll L = 0, R = N-1;
    srand(N);
    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);
//        printf("toSend: %lld, ", toSend);
        int tmp = rand()%3;
        ll origToSend = toSend;
        toSend = (toSend + tmp) % 3;
//        printf("adjusted: %lld\n", toSend);
        ll gone = anna(toSend);
        gone = (gone + 3 - tmp)%3;
        if(gone == 0) R = Q;
        else if(gone == 1) R -= P+1, X -= P+1;
        else if(origToSend == 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){
//    srand(N);
//    for(int i=1; i<=10; i++) printf("%d ", rand());
//    puts("");

    ll L = 0, R = N-1;
    vector<dat> vec;
    srand(N);
    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: %lld, ", gone);
        gone = (gone + 3 - rand()%3) % 3;
//        printf("Adjusted: %lld\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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1860 KB Output is correct
2 Correct 12 ms 1600 KB Output is correct
3 Correct 15 ms 1692 KB Output is correct
4 Correct 15 ms 1688 KB Output is correct
5 Correct 12 ms 1720 KB Output is correct
6 Correct 21 ms 1912 KB Output is correct
7 Correct 48 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 886 ms 1684 KB Output is partially correct
2 Partially correct 350 ms 1712 KB Output is partially correct
3 Partially correct 500 ms 1740 KB Output is partially correct
4 Partially correct 946 ms 1672 KB Output is partially correct
5 Partially correct 697 ms 1720 KB Output is partially correct
6 Partially correct 630 ms 1760 KB Output is partially correct
7 Partially correct 2726 ms 1748 KB Output is partially correct
8 Partially correct 3546 ms 1948 KB Output is partially correct
9 Partially correct 3242 ms 1828 KB Output is partially correct
10 Partially correct 3526 ms 1892 KB Output is partially correct
11 Partially correct 3881 ms 1984 KB Output is partially correct
12 Partially correct 3445 ms 1876 KB Output is partially correct
13 Partially correct 3117 ms 1912 KB Output is partially correct
14 Partially correct 3072 ms 1852 KB Output is partially correct
15 Partially correct 1361 ms 1836 KB Output is partially correct
16 Partially correct 3442 ms 1768 KB Output is partially correct
17 Partially correct 953 ms 1796 KB Output is partially correct
18 Partially correct 826 ms 1812 KB Output is partially correct
19 Partially correct 994 ms 1856 KB Output is partially correct
20 Partially correct 719 ms 1876 KB Output is partially correct
21 Partially correct 764 ms 1792 KB Output is partially correct
22 Partially correct 811 ms 1876 KB Output is partially correct
23 Partially correct 1524 ms 1764 KB Output is partially correct
24 Correct 10 ms 1736 KB Output is correct
25 Correct 11 ms 1684 KB Output is correct
26 Correct 12 ms 1820 KB Output is correct
27 Correct 9 ms 1684 KB Output is correct
28 Correct 10 ms 1700 KB Output is correct
29 Correct 28 ms 1976 KB Output is correct
30 Correct 36 ms 1724 KB Output is correct