結果
| 問題 |
No.2057 Ising Model
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-02 15:29:02 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 690 bytes |
| コンパイル時間 | 17,675 ms |
| コンパイル使用メモリ | 230,316 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-25 06:04:37 |
| 合計ジャッジ時間 | 15,623 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
func main() {
buf := make([]byte, 1024*1024)
sc.Buffer(buf, bufio.MaxScanTokenSize)
sc.Split(bufio.ScanWords)
n, a, b := nextInt(), nextInt(), nextInt()
// 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)
if n%2 == 0 {
a3 := -a*(n-3) - b*2
ans = Min(ans, a3)
}
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
}