#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, 0, 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(0);
else mySend(1);
}
else mySend(0), mySend(0);
}
else if(X==1){
int tmp = mySend(0);
if(!tmp) mySend(0), mySend(0);
else mySend(1), mySend(1);
}
else{
int tmp = mySend(1);
if(tmp){
tmp = mySend(1);
if(tmp) mySend(1);
else mySend(0);
}
else mySend(1), mySend(0);
}
return getBack(vec[0], vec[1], 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 = 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1748 KB |
Output is correct |
2 |
Correct |
13 ms |
1720 KB |
Output is correct |
3 |
Correct |
15 ms |
1832 KB |
Output is correct |
4 |
Correct |
12 ms |
1784 KB |
Output is correct |
5 |
Correct |
9 ms |
1708 KB |
Output is correct |
6 |
Correct |
23 ms |
1804 KB |
Output is correct |
7 |
Correct |
38 ms |
1660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1053 ms |
1916 KB |
Output is partially correct |
2 |
Partially correct |
529 ms |
1760 KB |
Output is partially correct |
3 |
Partially correct |
595 ms |
1700 KB |
Output is partially correct |
4 |
Partially correct |
1090 ms |
1788 KB |
Output is partially correct |
5 |
Partially correct |
1146 ms |
1780 KB |
Output is partially correct |
6 |
Partially correct |
885 ms |
1696 KB |
Output is partially correct |
7 |
Partially correct |
3565 ms |
1824 KB |
Output is partially correct |
8 |
Partially correct |
5093 ms |
1964 KB |
Output is partially correct |
9 |
Partially correct |
3557 ms |
1940 KB |
Output is partially correct |
10 |
Partially correct |
4052 ms |
1980 KB |
Output is partially correct |
11 |
Partially correct |
3699 ms |
1952 KB |
Output is partially correct |
12 |
Partially correct |
4145 ms |
1996 KB |
Output is partially correct |
13 |
Partially correct |
4064 ms |
1864 KB |
Output is partially correct |
14 |
Partially correct |
3840 ms |
1920 KB |
Output is partially correct |
15 |
Partially correct |
2355 ms |
1848 KB |
Output is partially correct |
16 |
Partially correct |
4272 ms |
1836 KB |
Output is partially correct |
17 |
Partially correct |
1051 ms |
1840 KB |
Output is partially correct |
18 |
Partially correct |
1074 ms |
1868 KB |
Output is partially correct |
19 |
Partially correct |
1020 ms |
1724 KB |
Output is partially correct |
20 |
Partially correct |
1359 ms |
1804 KB |
Output is partially correct |
21 |
Partially correct |
1172 ms |
1804 KB |
Output is partially correct |
22 |
Partially correct |
1073 ms |
1744 KB |
Output is partially correct |
23 |
Partially correct |
1855 ms |
1984 KB |
Output is partially correct |
24 |
Correct |
10 ms |
1808 KB |
Output is correct |
25 |
Correct |
12 ms |
1728 KB |
Output is correct |
26 |
Correct |
14 ms |
1872 KB |
Output is correct |
27 |
Correct |
9 ms |
1792 KB |
Output is correct |
28 |
Correct |
11 ms |
1756 KB |
Output is correct |
29 |
Correct |
26 ms |
1752 KB |
Output is correct |
30 |
Correct |
33 ms |
1752 KB |
Output is correct |