답안 #601710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601710 2022-07-22T09:21:34 Z 반딧불(#8472) Flight to the Ford (BOI22_communication) C++17
46.6667 / 100
4614 ms 2096 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()+1)%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()+1)%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 1748 KB Output is correct
2 Correct 16 ms 1808 KB Output is correct
3 Correct 11 ms 1768 KB Output is correct
4 Correct 11 ms 1768 KB Output is correct
5 Correct 15 ms 1788 KB Output is correct
6 Correct 26 ms 1888 KB Output is correct
7 Correct 41 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 921 ms 1712 KB Output is partially correct
2 Partially correct 451 ms 1820 KB Output is partially correct
3 Partially correct 555 ms 1764 KB Output is partially correct
4 Partially correct 1084 ms 1696 KB Output is partially correct
5 Partially correct 926 ms 1688 KB Output is partially correct
6 Partially correct 845 ms 1712 KB Output is partially correct
7 Partially correct 2651 ms 1840 KB Output is partially correct
8 Partially correct 4614 ms 2016 KB Output is partially correct
9 Partially correct 3320 ms 1912 KB Output is partially correct
10 Partially correct 3902 ms 1908 KB Output is partially correct
11 Partially correct 3558 ms 1976 KB Output is partially correct
12 Partially correct 3778 ms 2040 KB Output is partially correct
13 Partially correct 3776 ms 1944 KB Output is partially correct
14 Partially correct 3815 ms 2020 KB Output is partially correct
15 Partially correct 2047 ms 1944 KB Output is partially correct
16 Partially correct 4342 ms 1968 KB Output is partially correct
17 Partially correct 1063 ms 1856 KB Output is partially correct
18 Partially correct 1076 ms 1884 KB Output is partially correct
19 Partially correct 1091 ms 1784 KB Output is partially correct
20 Partially correct 1157 ms 1812 KB Output is partially correct
21 Partially correct 985 ms 1884 KB Output is partially correct
22 Partially correct 1204 ms 1992 KB Output is partially correct
23 Partially correct 1721 ms 1736 KB Output is partially correct
24 Correct 11 ms 1776 KB Output is correct
25 Correct 14 ms 1748 KB Output is correct
26 Correct 16 ms 1764 KB Output is correct
27 Correct 13 ms 1760 KB Output is correct
28 Correct 12 ms 1832 KB Output is correct
29 Correct 23 ms 2096 KB Output is correct
30 Correct 49 ms 1756 KB Output is correct