結果

問題 No.1120 Strange Teacher
ユーザー ks2mks2m
提出日時 2020-07-22 21:50:14
言語 Java19
(openjdk 21)
結果
AC  
実行時間 302 ms / 1,000 ms
コード長 1,180 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 74,824 KB
実行使用メモリ 66,628 KB
最終ジャッジ日時 2023-09-04 17:42:34
合計ジャッジ時間 8,514 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
49,288 KB
testcase_01 AC 42 ms
49,448 KB
testcase_02 AC 58 ms
50,392 KB
testcase_03 AC 104 ms
54,488 KB
testcase_04 AC 266 ms
65,976 KB
testcase_05 AC 266 ms
65,716 KB
testcase_06 AC 259 ms
65,264 KB
testcase_07 AC 287 ms
66,192 KB
testcase_08 AC 273 ms
66,392 KB
testcase_09 AC 39 ms
49,200 KB
testcase_10 AC 258 ms
66,628 KB
testcase_11 AC 254 ms
66,492 KB
testcase_12 AC 270 ms
66,100 KB
testcase_13 AC 257 ms
66,268 KB
testcase_14 AC 283 ms
66,232 KB
testcase_15 AC 280 ms
66,448 KB
testcase_16 AC 296 ms
65,756 KB
testcase_17 AC 279 ms
66,292 KB
testcase_18 AC 39 ms
49,288 KB
testcase_19 AC 302 ms
66,032 KB
testcase_20 AC 39 ms
49,324 KB
testcase_21 AC 39 ms
49,248 KB
testcase_22 AC 40 ms
49,676 KB
testcase_23 AC 39 ms
49,556 KB
testcase_24 AC 266 ms
64,456 KB
testcase_25 AC 40 ms
49,256 KB
testcase_26 AC 39 ms
49,192 KB
testcase_27 AC 40 ms
49,564 KB
testcase_28 AC 40 ms
47,236 KB
testcase_29 AC 40 ms
49,612 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]);
			if (val < 0 || val % 2 != 0) {
				System.out.println(-1);
				return;
			}
			sum2 += val / 2;
		}
		if (sum2 == cnt) {
			System.out.println(cnt);
		} else {
			System.out.println(-1);
		}
	}
}
0