답안 #36524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36524 2017-12-10T07:24:17 Z cheater2k 질문 (CEOI14_question_grader) C++14
100 / 100
1816 ms 27480 KB
#include <bits/stdc++.h>
using namespace std;

namespace A {
	int mp[960]; 
	bool called; // check whether function build() was called
	// map i (1 <= i <= 920) with a 12-bit integer j such that __builtin_popcount(j) = 6
	void build() {
		int cur = 0;
		for (int mask = 0; mask < (1 << 12); ++mask) {
			if (__builtin_popcount(mask) == 6) {
				mp[++cur] = mask;
			}
		}
	}
};

int encode (int n, int x, int y) {
	if (!A::called) A::called = true, A::build();
	int X = A::mp[x], Y = A::mp[y];
	for (int i = 0; i < 12; ++i) {
		int bitX = (X >> i & 1);
		int bitY = (Y >> i & 1);
		if (!bitX && bitY) {
			// the i-th bit of X is 0 while that of Y is 1
			return i + 1;
		}
	}
}
#include <bits/stdc++.h>
using namespace std;

namespace B { // similar to namespace A
	int mp[960]; 
	bool called; // check whether function build() was called
	// map i (1 <= i <= 920) with a 12-bit integer j such that __builtin_popcount(j) = 6
	void build() {
		int cur = 0;
		for (int mask = 0; mask < (1 << 12); ++mask) {
			if (__builtin_popcount(mask) == 6) {
				mp[++cur] = mask;
			}
		}
	}
};

int decode (int n, int q, int h) { // X and Y is different at h-th bit
	if (!B::called) B::called = true, B::build();
	int Q = B::mp[q];
	--h;
	int bitQ = Q >> h & 1;
	if (!bitQ) return true; else return false;
}

Compilation message

encoder.cpp: In function 'int encode(int, int, int)':
encoder.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1816 ms 27480 KB Output is correct - maxh = 12
2 Correct 1766 ms 27480 KB Output is correct - maxh = 12