#include <bits/stdc++.h>
using namespace std;
vector <vector <int> > all;
int encode (int n, int x, int y) {
x--; y--;
const int K = 12;
if(all.size() == 0){
for(int i = 0 ; i < (1 << K) ; i++){
if(__builtin_popcount(i) != K / 2) continue;
vector <int> cur;
for(int j = 0 ; j < K ; j++){
if((i >> j) & 1) cur.push_back(j);
}
all.push_back(cur);
}
}
for(auto &i : all[x]){
if(count(all[y].begin(), all[y].end(), i)) continue;
return i + 1;
}
assert(false);
}
#include <bits/stdc++.h>
using namespace std;
vector <vector <int> > all;
int decode (int n, int q, int h) {
h--; q--;
const int K = 12;
if(all.size() == 0){
for(int i = 0 ; i < (1 << K) ; i++){
if(__builtin_popcount(i) != K / 2) continue;
vector <int> cur;
for(int j = 0 ; j < K ; j++){
if((i >> j) & 1) cur.push_back(j);
}
all.push_back(cur);
}
}
for(auto &i : all[q]){
if(i == h) return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1616 ms |
79416 KB |
Output is correct - maxh = 12 |
2 |
Correct |
1611 ms |
79768 KB |
Output is correct - maxh = 12 |