結果

問題 No.2451 Redistribute Integers
ユーザー ks2mks2m
提出日時 2023-09-01 23:26:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,179 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 4,217 ms
コンパイル使用メモリ 72,116 KB
実行使用メモリ 69,640 KB
最終ジャッジ日時 2023-09-01 23:27:12
合計ジャッジ時間 16,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,516 KB
testcase_01 AC 127 ms
55,824 KB
testcase_02 AC 125 ms
55,464 KB
testcase_03 AC 124 ms
55,896 KB
testcase_04 AC 1,081 ms
66,752 KB
testcase_05 AC 125 ms
55,768 KB
testcase_06 AC 124 ms
55,692 KB
testcase_07 AC 124 ms
55,724 KB
testcase_08 AC 1,075 ms
66,992 KB
testcase_09 AC 123 ms
56,200 KB
testcase_10 AC 152 ms
56,120 KB
testcase_11 AC 182 ms
56,244 KB
testcase_12 AC 758 ms
64,948 KB
testcase_13 AC 1,042 ms
66,880 KB
testcase_14 AC 1,179 ms
69,640 KB
testcase_15 AC 870 ms
64,608 KB
testcase_16 AC 861 ms
64,560 KB
testcase_17 AC 953 ms
66,492 KB
testcase_18 AC 1,053 ms
66,828 KB
testcase_19 AC 429 ms
60,568 KB
testcase_20 AC 969 ms
66,784 KB
testcase_21 AC 1,081 ms
67,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int g = 0;
		for (int i = 1; i < n; i++) {
			g = gcd(g, Math.abs(a[i] - a[i - 1]));
		}
		if (g % n == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}
0