Submission #23600

# Submission time Handle Problem Language Result Execution time Memory
23600 2017-05-13T18:27:45 Z 0xrgb Question (Grader is different from the original contest) (CEOI14_question_grader) C++14
100 / 100
1711 ms 25720 KB
static int M[924][6];
static int Mr = 0;
static void M_init();

int encode (int n, int x, int y) {
	if (!Mr) M_init();
	for (int i = 0; i < 6; ++i) {
		int j;
		for (j = 0; j < 6; ++j) {
			if (M[x][i] == M[y][j]) break;
		}
		if (j == 6) return M[x][i];
	}
	return -1;
}

void M_init() {
	int arr[6] = {1, 2, 3, 4, 5, 6};
	for (int i = 1; i <= 920; ++i) {
		for (int j = 5; j >= 0; --j) {
			if (arr[j] < 7 + j) {
				int p = arr[j];
				for (int k = j; k < 6; ++k)
					arr[k] = ++p;
				break;
			}
		}

		for (int j = 0; j < 6; ++j)
			M[i][j] = arr[j];
	}

	Mr = 1;
}
static int M[924][6];
static int Mr = 0;
static void M_init();

int decode (int n, int q, int h) {
	if (!Mr) M_init();

	for (int i = 0; i < 6; ++i) {
		if (M[q][i] == h)
			return 1;
	}

	return 0;
}

void M_init() {
	int arr[6] = {1, 2, 3, 4, 5, 6};
	for (int i = 1; i <= 920; ++i) {
		for (int j = 5; j >= 0; --j) {
			if (arr[j] < 7 + j) {
				int p = arr[j];
				for (int k = j; k < 6; ++k)
					arr[k] = ++p;
				break;
			}
		}

		for (int j = 0; j < 6; ++j)
			M[i][j] = arr[j];
	}

	Mr = 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1711 ms 25720 KB Output is correct - maxh = 12
2 Correct 1692 ms 25720 KB Output is correct - maxh = 12