結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー | uafr_cs |
提出日時 | 2015-06-04 18:49:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 156 ms / 5,000 ms |
コード長 | 2,315 bytes |
コンパイル時間 | 2,559 ms |
コンパイル使用メモリ | 83,336 KB |
実行使用メモリ | 42,588 KB |
最終ジャッジ日時 | 2024-04-26 22:13:13 |
合計ジャッジ時間 | 6,843 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 156 ms
42,588 KB |
testcase_01 | AC | 130 ms
41,300 KB |
testcase_02 | AC | 154 ms
42,168 KB |
testcase_03 | AC | 141 ms
41,952 KB |
testcase_04 | AC | 123 ms
41,052 KB |
testcase_05 | AC | 127 ms
40,892 KB |
testcase_06 | AC | 131 ms
41,132 KB |
testcase_07 | AC | 129 ms
41,116 KB |
testcase_08 | AC | 128 ms
40,976 KB |
testcase_09 | AC | 120 ms
40,668 KB |
testcase_10 | AC | 128 ms
41,256 KB |
testcase_11 | AC | 148 ms
42,276 KB |
testcase_12 | AC | 129 ms
41,352 KB |
testcase_13 | AC | 140 ms
41,732 KB |
testcase_14 | AC | 145 ms
42,204 KB |
testcase_15 | AC | 127 ms
41,512 KB |
testcase_16 | AC | 153 ms
42,084 KB |
testcase_17 | AC | 127 ms
41,068 KB |
testcase_18 | AC | 139 ms
41,716 KB |
testcase_19 | AC | 129 ms
40,996 KB |
testcase_20 | AC | 150 ms
42,364 KB |
testcase_21 | AC | 156 ms
42,092 KB |
testcase_22 | AC | 156 ms
42,260 KB |
testcase_23 | AC | 151 ms
42,056 KB |
testcase_24 | AC | 145 ms
41,852 KB |
ソースコード
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); } } }