結果

問題 No.648  お や す み 
ユーザー c-yan
提出日時 2020-10-25 00:32:58
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 14,404 ms
コンパイル使用メモリ 227,128 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-21 16:46:10
合計ジャッジ時間 16,477 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	defer flush()

	n := readInt()

	ok := 0
	ng := 2000000000
	for ng-ok > 1 {
		m := ok + (ng-ok)/2
		if m*(m+1)/2 <= n {
			ok = m
		} else {
			ng = m
		}
	}

	if ok*(ok+1)/2 == n {
		println("YES")
		println(ok)
	} else {
		println("NO")
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}
0