結果
| 問題 | 
                            No.1120 Strange Teacher
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Apass
                         | 
                    
| 提出日時 | 2020-07-22 22:33:36 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,276 bytes | 
| コンパイル時間 | 3,316 ms | 
| コンパイル使用メモリ | 79,072 KB | 
| 実行使用メモリ | 49,220 KB | 
| 最終ジャッジ日時 | 2024-06-22 23:17:28 | 
| 合計ジャッジ時間 | 9,335 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 22 WA * 5 | 
ソースコード
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;
        }
        for (int i = 1; i < N; i++) {
            if ((A[i] - A[0]) % 2 != 0) return -1;
        }
        long sum = Arrays.stream(A).sum();
        if (sum < 0 || sum % (N - 2) != 0 || (sum - A[0]) % 2 != 0) return -1;
        return sum / (N - 2);
    }
}
            
            
            
        
            
Apass