結果

問題 No.1120 Strange Teacher
ユーザー ks2mks2m
提出日時 2020-07-22 21:44:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,099 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 74,516 KB
実行使用メモリ 66,976 KB
最終ジャッジ日時 2023-09-04 16:56:35
合計ジャッジ時間 9,850 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 44 ms
49,220 KB
testcase_10 AC 294 ms
66,012 KB
testcase_11 AC 275 ms
66,332 KB
testcase_12 AC 282 ms
66,296 KB
testcase_13 AC 295 ms
66,436 KB
testcase_14 AC 282 ms
66,416 KB
testcase_15 AC 288 ms
66,924 KB
testcase_16 AC 276 ms
66,492 KB
testcase_17 AC 289 ms
66,296 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 45 ms
49,164 KB
testcase_21 AC 46 ms
49,328 KB
testcase_22 AC 46 ms
49,308 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 46 ms
49,420 KB
testcase_26 AC 47 ms
49,168 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 44 ms
49,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long sum = 0;
		int[] d = new int[n];
		for (int i = 0; i < n; i++) {
			d[i] = a[i] - b[i];
			sum += d[i];
		}
		if (n == 2) {
			if (sum == 0) {
				System.out.println(Math.abs(d[0]));
			} else {
				System.out.println(-1);
			}
			return;
		}
		if (sum < 0 || sum % (n - 2) != 0) {
			System.out.println(-1);
			return;
		}

		long cnt = sum / (n - 2);
		long sum2 = 0;
		for (int i = 0; i < n; i++) {
			long val = (cnt - d[i]) / 2;
			if (val < 0) {
				System.out.println(-1);
				return;
			}
			sum2 += val;
		}
		System.out.println(-1);
	}
}
0