結果

問題 No.178 美しいWhitespace (1)
ユーザー taktak
提出日時 2018-08-05 10:03:47
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,533 bytes
コンパイル時間 3,036 ms
コンパイル使用メモリ 91,012 KB
実行使用メモリ 55,592 KB
最終ジャッジ日時 2023-10-19 22:02:35
合計ジャッジ時間 6,590 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
54,564 KB
testcase_01 AC 80 ms
54,508 KB
testcase_02 AC 75 ms
54,556 KB
testcase_03 AC 80 ms
54,576 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 104 ms
55,008 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 99 ms
55,228 KB
testcase_12 AC 101 ms
54,780 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 102 ms
55,104 KB
testcase_19 WA -
testcase_20 AC 98 ms
55,360 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 111 ms
55,488 KB
testcase_24 AC 103 ms
55,316 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(); }

    int f(int[] a, int[] b){
        int[] sums = new int[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){
            int max     = Arrays.stream(sums).max().getAsInt();
            int 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