結果

問題 No.178 美しいWhitespace (1)
ユーザー koukonkokoukonko
提出日時 2015-12-14 13:03:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 74,956 KB
実行使用メモリ 51,748 KB
最終ジャッジ日時 2023-10-13 16:29:01
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
49,592 KB
testcase_01 AC 39 ms
49,360 KB
testcase_02 AC 37 ms
49,248 KB
testcase_03 AC 39 ms
49,436 KB
testcase_04 AC 73 ms
51,548 KB
testcase_05 AC 69 ms
50,800 KB
testcase_06 AC 68 ms
50,376 KB
testcase_07 AC 40 ms
49,204 KB
testcase_08 AC 60 ms
51,436 KB
testcase_09 AC 71 ms
51,548 KB
testcase_10 AC 77 ms
50,636 KB
testcase_11 AC 40 ms
49,336 KB
testcase_12 AC 39 ms
49,408 KB
testcase_13 AC 71 ms
50,472 KB
testcase_14 AC 71 ms
50,504 KB
testcase_15 AC 74 ms
51,200 KB
testcase_16 AC 72 ms
51,748 KB
testcase_17 AC 69 ms
50,892 KB
testcase_18 AC 38 ms
47,724 KB
testcase_19 AC 60 ms
50,620 KB
testcase_20 AC 39 ms
49,260 KB
testcase_21 AC 70 ms
51,604 KB
testcase_22 AC 57 ms
50,620 KB
testcase_23 AC 71 ms
50,768 KB
testcase_24 AC 70 ms
50,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		try {

			int N = Integer.parseInt(read.readLine());
			int i = 0, eo;
			List<Long> list = new ArrayList<>(N);
			String[] box = read.readLine().split(" ");

			long total = 0;
			total = Integer.parseInt(box[0]);
			total += Integer.parseInt(box[1]) * 4;
			list.add(total);

			if (total % 2 == 0) {
				eo = 0;
			} else {
				eo = 1;
			}

			long max = total;
			while (i++ < N - 1) {
				box = read.readLine().split(" ");
				total = Integer.parseInt(box[0]);
				total += Integer.parseInt(box[1]) * 4;
				list.add(total);

				if (total % 2 != eo) {
					break;
				} else {
					if (max < total) {
						max = total;
					}
				}
			}

			if (i < N) {
				System.out.println(-1);
			} else {
				Iterator<Long> it = list.iterator();
				long ans = 0;
				while (it.hasNext()) {
					ans += max - it.next();
				}

				System.out.println(ans / 2);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0