結果

問題 No.406 鴨等間隔の法則
ユーザー tsunabittsunabit
提出日時 2018-06-23 11:47:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 516 ms / 2,000 ms
コード長 2,069 bytes
コンパイル時間 4,146 ms
コンパイル使用メモリ 76,276 KB
実行使用メモリ 69,728 KB
最終ジャッジ日時 2023-09-21 18:54:55
合計ジャッジ時間 17,233 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 342 ms
59,728 KB
testcase_01 AC 123 ms
55,740 KB
testcase_02 AC 124 ms
56,200 KB
testcase_03 AC 122 ms
55,800 KB
testcase_04 AC 468 ms
67,044 KB
testcase_05 AC 334 ms
60,764 KB
testcase_06 AC 331 ms
60,648 KB
testcase_07 AC 336 ms
60,388 KB
testcase_08 AC 450 ms
66,532 KB
testcase_09 AC 507 ms
69,504 KB
testcase_10 AC 348 ms
60,268 KB
testcase_11 AC 444 ms
68,532 KB
testcase_12 AC 365 ms
64,704 KB
testcase_13 AC 362 ms
60,100 KB
testcase_14 AC 468 ms
67,424 KB
testcase_15 AC 201 ms
57,100 KB
testcase_16 AC 213 ms
58,008 KB
testcase_17 AC 194 ms
57,240 KB
testcase_18 AC 222 ms
59,948 KB
testcase_19 AC 220 ms
59,996 KB
testcase_20 AC 238 ms
60,048 KB
testcase_21 AC 246 ms
59,804 KB
testcase_22 AC 294 ms
60,212 KB
testcase_23 AC 365 ms
64,276 KB
testcase_24 AC 428 ms
66,936 KB
testcase_25 AC 502 ms
69,288 KB
testcase_26 AC 510 ms
69,272 KB
testcase_27 AC 419 ms
66,788 KB
testcase_28 AC 427 ms
68,296 KB
testcase_29 AC 516 ms
69,728 KB
testcase_30 AC 515 ms
69,492 KB
testcase_31 AC 495 ms
69,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.Stream;

// ***問題文***
// 太郎君は、家の近くにある河川敷で、N(≥3)羽の鴨が休んでいるのを見つけました。この河川敷はまっすぐです。
// そこで、上流のある地点を原点x=0として、それぞれの鴨の休んでいる位置をx軸のx≥0を満たす部分にある点として
// 表すことにします。そして、このN
// 羽の鴨について、次の二つの条件が同時に成り立つときに限り、鴨等間隔の法則を満たしているということにします。
//     どの2羽の鴨の座標も相異なる。
//     隣り合う2羽の鴨の座標の差がすべて等しい。
// 太郎君は、鴨の数Nと鴨の休んでいる座標x0,x1,⋯,xN−1を記録しました。これらが与えられるので、
// N羽の鴨が鴨等間隔の法則を満たしているどうかを判定してください。 
// ***入力***
// N
// x0 x1 ⋯ xN−1
// 1行目には、太郎君の見つけた鴨の数N(3≤N≤105)が正整数で与えられる。
// 2行目には、鴨i(0≤i≤N−1)の休んでいる座標xi(0≤xi≤108)が非負整数で、スペースで区切られて与えられる。
// ここで、「j<kならばxj<xkである」とは限らない。
// ***出力***
// N羽の鴨が鴨等間隔の法則を満たしていれば文字列YESを、さもなければ文字列NOを出力してください。
// 最後に改行してください。


public class No406 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int[] x = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		Arrays.sort(x);
		String out = "YES";
		int temp = x[1] - x[0];
		for(int i = 0; i < n - 1; i++){
			int sa = x[i + 1] - x[i];
		    if(temp != sa || sa == 0) {;
				out = "NO";
				break;
			}
		}
		System.out.println(out);
	}
}
0