結果

問題 No.1120 Strange Teacher
ユーザー ApassApass
提出日時 2020-07-22 22:55:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 311 ms / 1,000 ms
コード長 1,310 bytes
コンパイル時間 3,369 ms
コンパイル使用メモリ 76,432 KB
実行使用メモリ 62,548 KB
最終ジャッジ日時 2023-09-05 03:14:25
合計ジャッジ時間 10,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
48,624 KB
testcase_01 AC 60 ms
50,532 KB
testcase_02 AC 76 ms
51,816 KB
testcase_03 AC 136 ms
56,448 KB
testcase_04 AC 285 ms
59,484 KB
testcase_05 AC 269 ms
59,820 KB
testcase_06 AC 305 ms
60,020 KB
testcase_07 AC 274 ms
59,552 KB
testcase_08 AC 275 ms
59,988 KB
testcase_09 AC 56 ms
50,556 KB
testcase_10 AC 259 ms
61,632 KB
testcase_11 AC 263 ms
59,452 KB
testcase_12 AC 270 ms
61,856 KB
testcase_13 AC 292 ms
59,760 KB
testcase_14 AC 270 ms
59,772 KB
testcase_15 AC 266 ms
59,884 KB
testcase_16 AC 283 ms
60,112 KB
testcase_17 AC 267 ms
60,240 KB
testcase_18 AC 56 ms
50,632 KB
testcase_19 AC 311 ms
62,548 KB
testcase_20 AC 44 ms
49,352 KB
testcase_21 AC 43 ms
49,420 KB
testcase_22 AC 56 ms
50,484 KB
testcase_23 AC 55 ms
50,668 KB
testcase_24 AC 276 ms
59,912 KB
testcase_25 AC 42 ms
49,320 KB
testcase_26 AC 55 ms
50,548 KB
testcase_27 AC 55 ms
50,632 KB
testcase_28 AC 55 ms
50,596 KB
testcase_29 AC 57 ms
50,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.math.MathContext;
import java.util.*;

public class StrangeTeacher {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        pw.println(solve());
        pw.close();
    }

    private static long solve() throws IOException {
        int N = readInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) A[i] = readInt();
        for (int i = 0; i < N; i++) A[i] -= readInt();

        if (N == 2) {
            if (A[0] + A[1] == 0) return Math.abs(A[0]);
            else return -1;
        }

        long sum = Arrays.stream(A).sum();
        if (sum < 0 || sum % (N - 2) != 0) return -1;
        long operation = sum / (N-2);

        for (int i = 0; i < N; i++) {
            if ((operation - A[i]) % 2 != 0 || operation < A[i] ) return -1;
        }

        return operation;
    }
}
0