結果

問題 No.178 美しいWhitespace (1)
ユーザー taktak
提出日時 2018-08-05 10:05:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 2,539 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 83,048 KB
実行使用メモリ 55,848 KB
最終ジャッジ日時 2023-10-19 22:02:43
合計ジャッジ時間 6,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
54,780 KB
testcase_01 AC 83 ms
54,744 KB
testcase_02 AC 75 ms
54,692 KB
testcase_03 AC 84 ms
54,852 KB
testcase_04 AC 110 ms
55,152 KB
testcase_05 AC 113 ms
55,572 KB
testcase_06 AC 111 ms
55,476 KB
testcase_07 AC 102 ms
55,076 KB
testcase_08 AC 115 ms
55,572 KB
testcase_09 AC 112 ms
55,548 KB
testcase_10 AC 115 ms
55,532 KB
testcase_11 AC 103 ms
55,524 KB
testcase_12 AC 106 ms
55,232 KB
testcase_13 AC 112 ms
55,848 KB
testcase_14 AC 115 ms
55,312 KB
testcase_15 AC 113 ms
55,716 KB
testcase_16 AC 114 ms
53,644 KB
testcase_17 AC 112 ms
55,144 KB
testcase_18 AC 106 ms
55,436 KB
testcase_19 AC 115 ms
55,532 KB
testcase_20 AC 105 ms
55,268 KB
testcase_21 AC 111 ms
55,580 KB
testcase_22 AC 99 ms
55,020 KB
testcase_23 AC 112 ms
53,440 KB
testcase_24 AC 104 ms
54,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.util.function.*;

public class Main {

    public static void main(String[] args) { new Main().stream(); }

    final FastIO      io   = new FastIO();
    final PrintWriter out  = new PrintWriter(System.out);

    void stream(){ solve(); out.flush(); }

    long f(int[] a, int[] b){
        long[] sums = new long[a.length];
        REP(a.length,i-> sums[i] = a[i] + b[i] * 4);
        long oddNum = Arrays.stream(sums).filter(i -> i % 2 == 0).count();
        if(oddNum==0||oddNum==sums.length){
            long max     = Arrays.stream(sums).max().getAsLong();
            long diffSum = Arrays.stream(sums).map(i -> max - i ).sum();
            return diffSum / 2;
        }else{
            return -1;
        }
    }

    void solve() {
        int N = io.Int();
        int[] a = new int[N];
        int[] b = new int[N];
        REP(N, i->{
            a[i] = io.Int();
            b[i] = io.Int();
        });

        System.out.println(f(a,b));

    }
    void FOR(int a, int b, Consumer<Integer>act) { for(int i = a; i < b; ++i) act.accept(i); }
    void REP(int a, Consumer<Integer>act) { FOR(0, a, act); }
}

class FastIO{
    private final InputStream in = System.in;
    private final byte[] buffer  = new byte[1<<12];
    private int   ptr = 0, buffLen = 0;
    private boolean hasNextByte     ()      {
        if(ptr < buffLen) return true;
        ptr = 0;
        try{ buffLen = in.read(buffer); } catch (IOException e){ e.printStackTrace(); }
        return buffLen > 0;
    }
    private int     readByte        ()      { return hasNextByte()? buffer[ptr++] : -1; }
    private boolean isPrintableChar (int c) { return 33 <= c && c <= 126; } //ASCII
    private void    skipUnprintable ()      { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; }
    private boolean hasNext         ()      { skipUnprintable(); return hasNextByte();}
    private String  next            ()      {
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)){ sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    public String String () { return next(); }
    public char   Char   () { return next().charAt(0);}
    public int    Int    () { return Integer.parseInt(next());}
    public long   Long   () { return Long.parseLong(next());}
    public double Double () { return Double.parseDouble(next());}
}
0