結果

問題 No.2057 Ising Model
ユーザー Hima
提出日時 2022-10-02 15:22:21
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 12,604 ms
コンパイル使用メモリ 219,552 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-25 04:13:23
合計ジャッジ時間 13,912 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func firstSolve(n, a, b int) int {
	// 1, -1, 1, -1, ....
	a1 := -a*(n-1) - b*(n%2)
	// 1, 1, 1, 1, ....
	a2 := a*(n-1) - b*n
	ans := Min(a1, a2)
	return ans
}

func solve(n, a, b int) int {
	f := func(x int) int {
		if x%2 == 0 && x == n/2 {
			return (n-4*x+1)*a - (n-2*x)*b
		} else {
			return (n-4*x-1)*a - (n-2*x)*b
		}
	}
	a1 := f(0)
	a2 := f(n / 2)
	a3 := f((n - 1) / 2)
	ans := Min(a1, Min(a2, a3))
	return ans
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n, a, b := nextInt(), nextInt(), nextInt()
	ans := solve(n, a, b)
	PrintInt(ans)
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func PrintInt(x int) {
	defer out.Flush()
	fmt.Fprintln(out, x)
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
0