// Willkommen! hier ist der Ort, an dem du sterben wirst :) so aufregend! nein?
#include"communication.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
const int maxn5 = 3e5 + 10;
const ll inf = 1e18;
const int lg = 30;
void encode(int n, int x){
int a = 0, b = 1, g = 0, keep = -1;
for(int i = 1; i < lg; i++){
if(max(a, b) > n){
a = b = min(a, b);
keep = -1;
g = i;
a ^= (1 << g);
continue;
}
int a1 = (keep == -1 ? send((x >> g)&1) : keep);
int b1 = send((x >> i)&1);
int b2 = send((x >> i)&1);
int a2 = send((x >> g)&1);
keep = a2;
if(b1 == b2){
a ^= (b1 << i);
b ^= (b1 << i);
continue;
}
if(a1 == a2){
if(((a >> g)&1) != a1)
a = b;
else
b = a;
a ^= (1 << i);
g = i;
keep = -1;
}
if(((a >> g)&1) != a1)
swap(a, b);
a |= (b2 << i);
b |= (b1 << i);
}
}
pair<int, int> decode(int N){
int a = 0, b = 1, g = 0, keep = -1;
for(int i = 1; i < lg; i++){
if(max(a, b) > N){
a = b = min(a, b);
keep = -1;
g = i;
a ^= (1 << g);
continue;
}
int a1 = (keep == -1 ? receive() : keep);
int b1 = receive();
int b2 = receive();
int a2 = receive();
keep = a2;
if(b1 == b2){
a ^= (b1 << i);
b ^= (b1 << i);
continue;
}
if(a1 == a2){
if(((a >> g)&1) != a1)
a = b;
else
b = a;
a ^= (1 << i);
g = i;
keep = -1;
continue;
}
if(((a >> g)&1) != a1)
swap(a, b);
a |= (b2 << i);
b |= (b1 << i);
}
a = max(a, 1); a = min(a, N);
b = max(b, 1); b = min(b, N);
return {a, b};
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1692 KB |
Output is correct |
2 |
Correct |
134 ms |
1720 KB |
Output is correct |
3 |
Correct |
54 ms |
1680 KB |
Output is correct |
4 |
Correct |
77 ms |
1668 KB |
Output is correct |
5 |
Correct |
17 ms |
1764 KB |
Output is correct |
6 |
Correct |
270 ms |
1768 KB |
Output is correct |
7 |
Correct |
217 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
347 ms |
200 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |