結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー uafr_csuafr_cs
提出日時 2015-06-04 18:49:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 2,315 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 90,472 KB
実行使用メモリ 55,200 KB
最終ジャッジ日時 2024-11-14 13:50:00
合計ジャッジ時間 6,632 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
54,756 KB
testcase_01 AC 125 ms
54,148 KB
testcase_02 AC 145 ms
55,068 KB
testcase_03 AC 149 ms
54,976 KB
testcase_04 AC 129 ms
54,084 KB
testcase_05 AC 130 ms
54,072 KB
testcase_06 AC 132 ms
54,084 KB
testcase_07 AC 131 ms
54,276 KB
testcase_08 AC 127 ms
54,052 KB
testcase_09 AC 128 ms
54,120 KB
testcase_10 AC 116 ms
52,912 KB
testcase_11 AC 141 ms
54,304 KB
testcase_12 AC 112 ms
52,672 KB
testcase_13 AC 160 ms
54,948 KB
testcase_14 AC 151 ms
55,200 KB
testcase_15 AC 125 ms
54,328 KB
testcase_16 AC 149 ms
54,948 KB
testcase_17 AC 125 ms
53,844 KB
testcase_18 AC 137 ms
54,404 KB
testcase_19 AC 132 ms
53,924 KB
testcase_20 AC 137 ms
54,656 KB
testcase_21 AC 156 ms
55,132 KB
testcase_22 AC 162 ms
54,944 KB
testcase_23 AC 156 ms
54,772 KB
testcase_24 AC 155 ms
54,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static final int SIZE = 3;
	
	public static boolean check(final int N, int[] xs, int[] ys){
		final int diff = (xs[0] - xs[1]) * (xs[0] - xs[1]) + (ys[0] - ys[1]) * (ys[0] - ys[1]);
		//System.out.println(Arrays.toString(xs) + " " + Arrays.toString(ys));
		
		for(int i = 1; i < N; i++){
			final int new_diff = (xs[i] - xs[(i + 1) % N]) * (xs[i] - xs[(i + 1) % N]) + (ys[i] - ys[(i + 1) % N]) * (ys[i] - ys[(i + 1) % N]);
			
			//System.out.println(diff + " " + new_diff + " " + xs[i] + " " + ys[i] + " " + xs[i + 1] + " " + ys[i + 1]);
			if(diff != new_diff){
				return false;
			}
		}
		
		return true;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[] xs = new int[SIZE];
		int[] ys = new int[SIZE];
		for(int i = 0; i < SIZE; i++){
			final int x = sc.nextInt();
			final int y = sc.nextInt();
			
			xs[i] = x;
			ys[i] = y;
		}
		
		int diff_max = Integer.MIN_VALUE;
		int far_1_point = -1, far_2_point = -1;
		
		for(int i = 0; i < SIZE; i++){
			for(int j = i + 1; j < SIZE; j++){
				final int diff = (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);
				
				if(diff_max < diff){
					diff_max = diff;
					far_1_point = i;
					far_2_point = j;
				}
			}
		}
		int diff_x = xs[far_2_point] - xs[far_1_point];
		int diff_y = ys[far_2_point] - ys[far_1_point];

		int other_1_point = far_2_point == 1 ? 2 : far_1_point == 0 ? 1 : 0;

		//System.out.println(far_1_point + " " + other_1_point + " " + far_2_point);
		
		if(check(4, 
				new int[]{xs[far_1_point], xs[other_1_point], xs[far_2_point], xs[other_1_point] + diff_y}, 
				new int[]{ys[far_1_point], ys[other_1_point], ys[far_2_point], ys[other_1_point] - diff_x})){
			System.out.println((xs[other_1_point] + diff_y) + " " + (ys[other_1_point] - diff_x));
		}else if(check(4, 
						new int[]{xs[far_1_point], xs[other_1_point], xs[far_2_point], xs[other_1_point] - diff_y}, 
						new int[]{ys[far_1_point], ys[other_1_point], ys[far_2_point], ys[other_1_point] + diff_x})){
			System.out.println((xs[other_1_point] - diff_y) + " " + (ys[other_1_point] + diff_x));
		}else{
			System.out.println(-1);
		}
		
	}
	
}
0