結果

問題 No.178 美しいWhitespace (1)
コンテスト
ユーザー gogotea
提出日時 2015-04-06 00:57:54
言語 Go
(1.25.5)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 929 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 12,234 ms
コンパイル使用メモリ 242,644 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-01 18:10:38
合計ジャッジ時間 13,496 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	// Scan開始前にSplitを設定しないとPanicになるため、ここに移動
	sc.Split(bufio.ScanWords)

	lines, max := input()
	result := count(lines, max)
	fmt.Println(result)
}

func input() ([]int, int) {
	N := nextInt()
	lines := make([]int, N)
	max := 0

	for i := 0; i < N; i++ {
		a := nextInt()
		b := nextInt()
		lines[i] = a + b*4
		if lines[i] > max {
			max = lines[i]
		}
	}
	return lines, max
}

func count(lines []int, max int) int {
	result := 0
	for _, w := range lines {
		diff := max - w
		if diff%2 != 0 {
			return -1
		}
		result += diff / 2
	}
	return result
}

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	// sc.Split(bufio.ScanWords) // 削除: Scan後に呼ぶとPanicになるため
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}
0