#define B(x,h) (x&(1 << h))
int encode(int n, int x, int y) {
int h = 0, cntx = 0, cnty = 0;
while (h != 10){
bool X = B(x, h);
bool Y = B(y, h);
h++;
cntx += X;
cnty += Y;
if (X > Y){
return h;
}
}
h = 0;
while (h != 5){
bool X = B(cntx, h);
bool Y = B(cnty, h);
h++;
if (X < Y){
return 10 + h;
}
}
}
int decode(int n, int q, int h) {
if (h <= 10){
h -= 1;
bool Q = (q&(1 << h));
return Q;
}
else{
int i = h - 11, cntq = 0;
h = 0;
while (h != 10){
bool Q = (q&(1 << h));
h++;
cntq += Q;
}
bool Q = (cntq&(1 << i));
return !Q;
}
}
Compilation message
encoder.cpp: In function 'int encode(int, int, int)':
encoder.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1882 ms |
25672 KB |
Output is partially correct - maxh = 14 |
2 |
Partially correct |
1816 ms |
25672 KB |
Output is partially correct - maxh = 14 |