結果

問題 No.185 和風
ユーザー gogoteagogotea
提出日時 2015-04-20 01:25:07
言語 Go1.4
(1.4.2)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 847 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 33,248 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 11:46:16
合計ジャッジ時間 1,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()

	zz := -1
	for i := 0; i < N; i++ {
		X := sc.NextInt()
		Y := sc.NextInt()
		z := Y - X
		if z <= 0 {
			fmt.Println(-1)
			return
		}
		if i == 0 {
			zz = z
			continue
		}
		if zz != z {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(zz)
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		bufio.NewScanner(r),
	}
}

func (s *Scanner) Next() string {
	sc := s.Scanner
	sc.Split(bufio.ScanWords)
	return nextToken(sc)
}

func nextToken(sc *bufio.Scanner) string {
	sc.Scan()
	if sc.Err() != nil {
		panic(sc.Err())
	}
	return sc.Text() // not handle EOF
}

func (s *Scanner) NextInt() int {
	i, e := strconv.Atoi(s.Next())
	if e != nil {
		panic(e)
	}
	return i
}
0