結果

問題 No.2057 Ising Model
ユーザー HimaHima
提出日時 2022-10-02 15:22:21
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 12,410 ms
コンパイル使用メモリ 213,820 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-26 09:41:28
合計ジャッジ時間 13,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 1 ms
4,380 KB
testcase_39 WA -
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 WA -
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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