#include <bits/stdc++.h>
using namespace std;
int codes[925];
void codeGenerator(int N) {
if (codes[1]) {
return; }
int val = 0;
for (int mask = 0; mask < (1 << 12); ++mask) {
if (__builtin_popcount(mask) == 6) {
codes[++val] = mask; } } }
int encode(int N, int X, int Y) {
codeGenerator(N);
for (int i = 0; i < 12; ++i) {
if (((codes[X] >> i) & 1) and !((codes[Y] >> i) & 1)) {
return i + 1; } } }
int decode(int N, int Q, int H) {
codeGenerator(N);
if (codes[Q] & (1 << (H - 1))) {
return 1; }
return 0; }
#ifdef HOME
int main(void) {
freopen("question.in", "r", stdin);
freopen("question.out", "w", stdout);
int T; cin >> T;
while (T--) {
int N, X, Y, Q; cin >> N >> X >> Y >> Q;
cout << decode(N, Q, encode(N, X, Y)) << endl; }
return 0; }
#endif
#include <bits/stdc++.h>
using namespace std;
int codes[925];
void codeGenerator(int N) {
if (codes[1]) {
return; }
int val = 0;
for (int mask = 0; mask < (1 << 12); ++mask) {
if (__builtin_popcount(mask) == 6) {
codes[++val] = mask; } } }
int encode(int N, int X, int Y) {
codeGenerator(N);
for (int i = 0; i < 12; ++i) {
if (((codes[X] >> i) & 1) and !((codes[Y] >> i) & 1)) {
return i + 1; } } }
int decode(int N, int Q, int H) {
codeGenerator(N);
if (codes[Q] & (1 << (H - 1))) {
return 1; }
return 0; }
#ifdef HOME
int main(void) {
freopen("question.in", "r", stdin);
freopen("question.out", "w", stdout);
int T; cin >> T;
while (T--) {
int N, X, Y, Q; cin >> N >> X >> Y >> Q;
cout << decode(N, Q, encode(N, X, Y)) << endl; }
return 0; }
#endif
Compilation message
encoder.cpp: In function 'int encode(int, int, int)':
encoder.cpp:18:22: warning: control reaches end of non-void function [-Wreturn-type]
return i + 1; } } }
^
decoder.cpp: In function 'int encode(int, int, int)':
decoder.cpp:18:22: warning: control reaches end of non-void function [-Wreturn-type]
return i + 1; } } }
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1301 ms |
114552 KB |
Output is correct - maxh = 12 |
2 |
Correct |
1306 ms |
114304 KB |
Output is correct - maxh = 12 |