結果

問題 No.246 質問と回答
ユーザー yuki2006
提出日時 2015-07-13 11:21:34
言語 Go
(1.23.4)
結果
RE  
実行時間 -
コード長 950 bytes
コンパイル時間 13,999 ms
コンパイル使用メモリ 241,656 KB
実行使用メモリ 25,832 KB
平均クエリ数 2.00
最終ジャッジ日時 2024-07-16 06:49:20
合計ジャッジ時間 14,583 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
//	screenBuffer := bytes.NewBuffer(nil)
//	screenWriter := bufio.NewWriterSize(screenBuffer, 8192)
	A := 0
	B := pow(10, 9) + 1

	for B-A > 1 {
		c := (A + B) / 2
		fmt.Print("? ")
		fmt.Println(c)

		ans := nextInt()
		if ans == 1 {
			A = c
		}else {
			B = c
		}
	}
	fmt.Print("! ")
	fmt.Println(-1)

}

var s = bufio.NewScanner(os.Stdin)

func next() string {
	s.Split(bufio.ScanWords)
	s.Scan()
	return s.Text()
}
func nextLine() string {
	s.Split(bufio.ScanLines)
	s.Scan()
	return s.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}
func nextLong() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}
//aのb乗をします O(log b)
func pow(a int, b int) int {
	total := 1
	tmp := a
	for b > 0 {
		if b%2 == 1 {
			total*=tmp
		}
		b/=2
		tmp*=tmp
	}
	return total
}
0