結果
問題 |
No.246 質問と回答
|
ユーザー |
|
提出日時 | 2015-07-13 11:22:09 |
言語 | Go (1.23.4) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 949 bytes |
コンパイル時間 | 11,042 ms |
コンパイル使用メモリ | 230,992 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 2.00 |
最終ジャッジ日時 | 2024-07-16 06:49:57 |
合計ジャッジ時間 | 14,443 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 30 |
ソースコード
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(A) } 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 }