結果
問題 |
No.246 質問と回答
|
ユーザー |
|
提出日時 | 2015-07-13 11:20:46 |
言語 | Go (1.23.4) |
結果 |
RE
|
実行時間 | - |
コード長 | 978 bytes |
コンパイル時間 | 13,885 ms |
コンパイル使用メモリ | 240,980 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 2.00 |
最終ジャッジ日時 | 2024-07-16 06:48:42 |
合計ジャッジ時間 | 17,692 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 30 |
ソースコード
package main import ( "fmt" ) import ( "bufio" "os" "strconv" "bytes" ) 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) screenWriter.Flush() 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 }