結果
問題 | No.178 美しいWhitespace (1) |
ユーザー | tak |
提出日時 | 2018-08-05 10:05:30 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 107 ms / 2,000 ms |
コード長 | 2,539 bytes |
コンパイル時間 | 2,646 ms |
コンパイル使用メモリ | 91,924 KB |
実行使用メモリ | 52,568 KB |
最終ジャッジ日時 | 2024-09-19 18:01:12 |
合計ジャッジ時間 | 5,735 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
51,192 KB |
testcase_01 | AC | 74 ms
51,572 KB |
testcase_02 | AC | 66 ms
51,348 KB |
testcase_03 | AC | 73 ms
51,168 KB |
testcase_04 | AC | 100 ms
52,124 KB |
testcase_05 | AC | 100 ms
52,568 KB |
testcase_06 | AC | 101 ms
52,220 KB |
testcase_07 | AC | 93 ms
51,808 KB |
testcase_08 | AC | 97 ms
52,084 KB |
testcase_09 | AC | 103 ms
52,056 KB |
testcase_10 | AC | 102 ms
52,300 KB |
testcase_11 | AC | 87 ms
52,120 KB |
testcase_12 | AC | 87 ms
52,176 KB |
testcase_13 | AC | 95 ms
52,192 KB |
testcase_14 | AC | 97 ms
52,116 KB |
testcase_15 | AC | 100 ms
52,288 KB |
testcase_16 | AC | 97 ms
52,284 KB |
testcase_17 | AC | 93 ms
52,076 KB |
testcase_18 | AC | 93 ms
51,928 KB |
testcase_19 | AC | 107 ms
52,312 KB |
testcase_20 | AC | 93 ms
52,068 KB |
testcase_21 | AC | 99 ms
52,220 KB |
testcase_22 | AC | 87 ms
51,872 KB |
testcase_23 | AC | 103 ms
52,292 KB |
testcase_24 | AC | 91 ms
52,284 KB |
ソースコード
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());} }