Submission #10723

# Submission time Handle Problem Language Result Execution time Memory
10723 2014-11-10T05:36:15 Z lala123kr 개미 (GA4_ant) C
0 / 100
396 ms 1088 KB
#include <stdio.h>
#include <math.h>
#include <limits.h>

int i, arr[3][3];
int get(int a, int b) {
	return pow(a, 2) + pow(b, 2);
}
int getSmaller(int a, int b) {
	return a < b? a : b;
}
void swap(int * a, int * b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void nomalize() {
	int j;
	//s1로 맞춤 A(0, a, b)
	for(i = 0 ; i < 3; i ++) {
		if(arr[1][i] == 0) {
			j = i;
			break;
		}
		else if(arr[1][i] == arr[0][i]) {
			arr[2][i] = arr[0][i] - arr[2][i];
			arr[1][i] = 0;
			j = i;
			break;
		}
	}

	//교환 : mirroring
	if(j != 0) {
		for(i = 0 ; i < 3; i++) 
			swap(&arr[i][0], &arr[i][j]);
	}

	//s2로 맞춤 B(c, 0, d)
	for(i = 1 ; i < 3; i ++) {
		if(arr[2][i] == 0) {
			j = i;
			break;
		}
		else if(arr[2][i] == arr[0][i]) {
			arr[1][i] = arr[0][i] - arr[1][i];
			arr[2][i] = 0;
			j = i;
			break;
		}
	}

	//교환 : mirroring
	if(j == 2) {
		for(i = 0 ; i < 3; i++) 
			swap(&arr[i][1], &arr[i][j]);
	}
}
int find() {
	int result = INT_MAX;
	int y, z, tmp[3];
	//int L = arr[0][0], W = arr[0][1], H = arr[0][2];

	//같은면
	for(i = 0 ; i < 3; i ++) {
		if(arr[1][i] == arr[2][i] &&
		 		(arr[1][i] == 0 || arr[1][i] == arr[0][i])) {
			y = (i + 1)%3;
			z = (i + 2)%3;

			result = getSmaller(result, get(arr[1][y] - arr[2][y], arr[1][z] - arr[2][z]));
		}
	}

	//반대면, 4방향에 대해 계산함 
	for(i = 0 ; i < 3 ; i++) { 
		if(arr[1][i] + arr[0][i] == arr[2][i] &&
		 		(arr[1][i] == 0 || arr[1][i] == arr[0][i])) {
			y = (i + 1)%3;
			z = (i + 2)%3;

			tmp[0] = arr[1][y] + arr[2][y];
			tmp[1] = arr[1][z] - arr[2][z];
			tmp[2] = get(getSmaller(arr[0][i] + tmp[0], arr[0][i] + arr[0][y] * 2 - tmp[0]), tmp[1]);
			
			result = tmp[2];

			tmp[0] = arr[1][z] + arr[2][z];
			tmp[1] = arr[1][y] - arr[2][y];
			tmp[2] = get(getSmaller(arr[0][i] + tmp[0], arr[0][i] + arr[0][z] * 2 - tmp[0]), tmp[1]);
			
			result = tmp[2] < result ? tmp[2] : result;
		}
	}

	//인접면
	//s1, s2 fix (0, a, b), (c, 0, d)
	nomalize();

	//gradient  tmp[0] / tmp[1]
	if( arr[0][0] * arr[0][1] < arr[0][2] * arr[0][2] ) {
		tmp[0] = -arr[0][1];
		tmp[1] = arr[0][2];
	} else {
		tmp[0] = -arr[0][2];
		tmp[1] = arr[0][1];
	}
	
	//2. 3side
	result = get(arr[1][2] + arr[2][0], arr[1][1] + arr[2][2]);
	
	//1. 직선
	result = getSmaller(result, get(arr[1][1] + arr[2][0], arr[1][2] - arr[2][2]));

	//3. 4side
		//gradient  tmp[0] / tmp[1]
	if( arr[0][0] * arr[0][1] < arr[0][2] * arr[0][2] ) {
		tmp[0] = -arr[0][1];
		tmp[1] = arr[0][2];
	} else {
		tmp[0] = -arr[0][2];
		tmp[1] = arr[0][1];
	}

	arr[1][2] = arr[0][2] - arr[1][2];
	arr[2][2] = arr[0][2] - arr[2][2];
	
	result = getSmaller(result, get(arr[1][2] + arr[2][0], arr[1][1] + arr[2][2]));

	return result;
}
int main() {
	int n;
	scanf("%d", &n);
	while(n--) {
		for(i = 0 ; i < 3 ; i ++) 
			scanf("%d %d %d", &arr[i][0], &arr[i][1], &arr[i][2]);

		printf("%d\n", find());
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 1088 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 384 ms 1088 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 392 ms 1088 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 1088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 356 ms 1088 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 388 ms 1088 KB Output isn't correct
2 Halted 0 ms 0 KB -