답안 #26948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26948 2017-07-07T11:51:11 Z 0xrgb 앵무새 (IOI11_parrots) C++14
98 / 100
12 ms 2432 KB
#include "encoder.h"
#include "encoderlib.h"

static int LIB[257][7];

static void init() {
	int arr[7] = {-1, -1, -1, -1, -1, -1, -1};
	for (int i = 0; i < 257; ++i) {
		for (int j = 0; j < 7; ++j) LIB[i][j] = arr[j];
		int k;
		for (k = 6; arr[k] == 3; --k);
		++arr[k];
		for (int l = k + 1; l <= 6; ++l) arr[l] = arr[k];
	}
}

void encode(int N, int M[]) {	
	static bool isSet = true;
	if (isSet) {
		isSet = false;
		init();
	}
	
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 7; ++j) {
			if (LIB[M[i] + 1][j] == -1) continue;
			send(LIB[M[i] + 1][j] + (4 * i));	
		}
	}
}
#include "decoder.h"
#include "decoderlib.h"

#include <algorithm>

static int LIB[257][7];

static void init() {
	int arr[7] = {-1, -1, -1, -1, -1, -1, -1};
	for (int i = 0; i < 257; ++i) {
		for (int j = 0; j < 7; ++j) LIB[i][j] = arr[j];
		int k;
		for (k = 6; arr[k] == 3; --k);
		++arr[k];
		for (int l = k + 1; l <= 6; ++l) arr[l] = arr[k];
	}
}

static int find_num(int arr[7]) {
	int l = 0, r = 256;
	
	while(l <= r) {
		const int m = (l + r) >> 1;
		int fl;
		for (int i = 0; i < 7; ++i) {
			fl = arr[i] - LIB[m][i];
			if (fl != 0) break;
		}
		
		if (fl == 0) return m;
		else if (fl > 0) l = m + 1;
		else r = m - 1;
	}
	
	return -1;
}

void decode(int N, int L, int X[]) {
	static bool isSet = true;
	if (isSet) {
		isSet = false;
		init();
	}
	
	std::sort(X, X + L);
	int arr[7], arl = 0, nl = 3;
	for (int i = 0; i < L; ++i) {
		if (nl < X[i]) {
			nl += 4;
			for (int j = arl; j < 7; ++j) arr[j] = -1;
			std::sort(arr, arr + 7);
			
			const int n = find_num(arr) - 1;
			if (n != -1) output(n);
			arl = 0;
		}
		
		arr[arl++] = X[i] % 4;
	}
	
	for (int j = arl; j < 7; ++j) arr[j] = -1;
	std::sort(arr, arr + 7);
	
	const int n = find_num(arr) - 1;
	if (n != -1) output(n);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1592 KB Output is correct
2 Correct 4 ms 1592 KB Output is correct
3 Correct 5 ms 1744 KB Output is correct
4 Correct 6 ms 1960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1992 KB Output is correct
2 Correct 5 ms 2144 KB Output is correct
3 Correct 5 ms 2144 KB Output is correct
4 Correct 5 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2176 KB Output is correct
2 Correct 5 ms 2176 KB Output is correct
3 Correct 6 ms 2176 KB Output is correct
4 Correct 7 ms 2176 KB Output is correct
5 Correct 7 ms 2176 KB Output is correct
6 Correct 7 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 5 ms 2176 KB Output is partially correct - P = 7.000000
2 Partially correct 11 ms 2184 KB Output is partially correct - P = 7.000000
3 Partially correct 8 ms 2184 KB Output is partially correct - P = 7.000000
4 Partially correct 10 ms 2184 KB Output is partially correct - P = 7.000000
5 Partially correct 11 ms 2184 KB Output is partially correct - P = 7.000000
6 Partially correct 12 ms 2432 KB Output is partially correct - P = 7.000000
7 Partially correct 12 ms 2432 KB Output is partially correct - P = 7.000000