結果

問題 No.1120 Strange Teacher
ユーザー ApassApass
提出日時 2020-07-22 22:49:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 7,109 ms
コンパイル使用メモリ 76,428 KB
実行使用メモリ 62,272 KB
最終ジャッジ日時 2023-09-05 03:02:38
合計ジャッジ時間 12,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
50,772 KB
testcase_01 AC 61 ms
50,896 KB
testcase_02 AC 76 ms
52,904 KB
testcase_03 AC 134 ms
54,580 KB
testcase_04 AC 287 ms
60,468 KB
testcase_05 AC 282 ms
59,820 KB
testcase_06 AC 266 ms
62,272 KB
testcase_07 AC 272 ms
60,080 KB
testcase_08 AC 278 ms
59,472 KB
testcase_09 AC 56 ms
50,552 KB
testcase_10 AC 271 ms
61,888 KB
testcase_11 AC 306 ms
60,088 KB
testcase_12 AC 296 ms
59,848 KB
testcase_13 AC 274 ms
60,040 KB
testcase_14 AC 300 ms
60,368 KB
testcase_15 AC 264 ms
59,380 KB
testcase_16 WA -
testcase_17 AC 273 ms
57,588 KB
testcase_18 AC 60 ms
49,080 KB
testcase_19 AC 283 ms
62,096 KB
testcase_20 AC 43 ms
49,560 KB
testcase_21 AC 44 ms
49,504 KB
testcase_22 AC 57 ms
50,724 KB
testcase_23 AC 57 ms
50,908 KB
testcase_24 AC 278 ms
60,772 KB
testcase_25 AC 44 ms
49,468 KB
testcase_26 AC 56 ms
50,808 KB
testcase_27 AC 57 ms
50,708 KB
testcase_28 AC 57 ms
51,112 KB
testcase_29 AC 58 ms
50,656 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[0]) % 2 != 0 || operation < A[0] ) return -1;
        }

        return operation;
    }
}
0