int encode(int n, int x, int y)
{
int C[15][15];
int i, j, a, b, s;
C[0][0] = 1;
for(i=1; i<=12; i++){
C[i][0] = 1;
for(j=1; j<i; j++){
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}
C[i][i] = C[i - 1][i - 1];
}
a = 6, b = 6;
for(i=0, s=0; i<12; i++){
if(a == 0) b --, s = s << 1 | 1;
else if(b == 0) a --, s = s << 1;
else if(x <= C[a + b - 1][a - 1]) a --, s <<= 1;
else x -= C[a + b - 1][a - 1], b --, s = s << 1 | 1;
}
x ^= s ^= x ^= s;
a = 6, b = 6;
for(i=0, s=0; i<12; i++){
if(a == 0) b --, s = s << 1 | 1;
else if(b == 0) a --, s = s << 1;
else if(y <= C[a + b - 1][a - 1]) a --, s <<= 1;
else y -= C[a + b - 1][a - 1], b --, s = s << 1 | 1;
}
y ^= s ^= y ^= s;
for(i=0; i<12; i++){
if((x & (1 << i)) && !(y & (1 << i))){
return i + 1;
}
}
return 0;
}
int decode(int n, int q, int h)
{
int C[15][15];
int i, j, a, b, s;
C[0][0] = 1;
for(i=1; i<=12; i++){
C[i][0] = 1;
for(j=1; j<=i; j++){
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}
}
a = 6, b = 6;
for(i=0, s=0; i<12; i++){
if(a == 0) b --, s = s << 1 | 1;
else if(b == 0) a --, s = s << 1;
else if(q <= C[a + b - 1][a - 1]) a --, s <<= 1;
else q -= C[a + b - 1][a - 1], b --, s = s << 1 | 1;
}
return s & (1 << h - 1)? 1 : 0;
}
Compilation message
decoder.cpp: In function 'int decode(int, int, int)':
decoder.cpp:24:21: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
return s & (1 << h - 1)? 1 : 0;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2142 ms |
80424 KB |
Output is correct - maxh = 12 |
2 |
Correct |
2115 ms |
80360 KB |
Output is correct - maxh = 12 |