結果
問題 |
No.178 美しいWhitespace (1)
|
ユーザー |
![]() |
提出日時 | 2017-04-30 10:32:23 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 2,334 ms |
コンパイル使用メモリ | 77,616 KB |
実行使用メモリ | 51,372 KB |
最終ジャッジ日時 | 2024-09-13 23:29:29 |
合計ジャッジ時間 | 5,557 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int N = Integer.parseInt(reader.readLine()); String[] inputs; long max = Long.MIN_VALUE; long[] widths = new long[N]; for (int i = 0; i < N; i++) { inputs = reader.readLine().split(" "); long a = Long.parseLong(inputs[0]); long b = Long.parseLong(inputs[1]); widths[i] = a + 4 * b; max = Math.max(max, a + 4 * b); } long numOfSpaces = 0; boolean isPerfect = true; for (int i = 0; i < N; i++) { if ((max - widths[i]) % 2 != 0) { isPerfect = false; break; } else { numOfSpaces += (max - widths[i]) / 2; } } if (isPerfect) { System.out.println(numOfSpaces); } else { System.out.println(-1); } } }