This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "communication.h"
void encode(int N,int X) {
int i,j;
vi vv = {0,6,9,15};
vpii poss;
poss.pb(mp(1,N));
while (1) {
int l = 0;
for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
if (l <= 2) return;
sort(poss.begin(),poss.end());
int num = 0;
for (i = 0; i < poss.size(); i++) {
if (X >= poss[i].second) num += poss[i].second-poss[i].first+1;
else if (X >= poss[i].first) num += X-poss[i].first+1;
}
int s = (l+3)/4,q = (num-1)/s;
int S = vv[q],T = 0;
for (i = 0; i < 4; i++) T |= send((S >> i) & 1) << i;
vi cand;
for (i = 0; i < 4; i++) {
for (j = 1; j < 4; j++) {
if (((vv[i]^T) & (1 << j)) && ((vv[i]^T) & (1 << (j-1)))) break;
}
if (j == 4) cand.pb(i);
}
vpii poss2;
for (int c: cand) {
int x = 0;
for (i = 0; i < poss.size(); i++) {
int l = max(x+1,c*s+1),r = min(x+poss[i].second-poss[i].first+1,(c+1)*s);
if (l <= r) poss2.pb(mp(poss[i].first+l-(x+1),poss[i].first+r-(x+1)));
x += poss[i].second-poss[i].first+1;
}
}
poss = poss2;
}
}
pair<int,int> decode(int N) {
int i,j;
vi vv = {0,6,9,15};
vpii poss;
poss.pb(mp(1,N));
while (1) {
int l = 0;
for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
if (l <= 2) {
vi all;
for (i = 0; i < poss.size(); i++) {
for (j = poss[i].first; j <= poss[i].second; j++) all.pb(j);
}
if (all.size() == 1) return mp(all[0],all[0]);
else return mp(all[0],all[1]);
}
sort(poss.begin(),poss.end());
int s = (l+3)/4,T = 0;
for (i = 0; i < 4; i++) T |= (receive() << i);
vi cand;
for (i = 0; i < 4; i++) {
for (j = 1; j < 4; j++) {
if (((vv[i]^T) & (1 << j)) && ((vv[i]^T) & (1 << (j-1)))) break;
}
if (j == 4) cand.pb(i);
}
vpii poss2;
for (int c: cand) {
int x = 0;
for (i = 0; i < poss.size(); i++) {
int l = max(x+1,c*s+1),r = min(x+poss[i].second-poss[i].first+1,(c+1)*s);
if (l <= r) poss2.pb(mp(poss[i].first+l-(x+1),poss[i].first+r-(x+1)));
x += poss[i].second-poss[i].first+1;
}
}
poss = poss2;
}
}
Compilation message (stderr)
communication.cpp: In function 'void encode(int, int)':
communication.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
| ~~^~~~~~~~~~~~~
communication.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (i = 0; i < poss.size(); i++) {
| ~~^~~~~~~~~~~~~
communication.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (i = 0; i < poss.size(); i++) {
| ~~^~~~~~~~~~~~~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:103:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
| ~~^~~~~~~~~~~~~
communication.cpp:106:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (i = 0; i < poss.size(); i++) {
| ~~^~~~~~~~~~~~~
communication.cpp:125:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for (i = 0; i < poss.size(); i++) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |