結果
問題 | No.2057 Ising Model |
ユーザー |
![]() |
提出日時 | 2022-08-26 23:13:10 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 485 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-10-13 23:51:46 |
合計ジャッジ時間 | 2,403 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
from itertools import product def gen_small(N): for p in product([-1, 1], repeat=N): x = sum([s * t for s, t in zip(p, p[1:])]) y = sum(p) yield x, y N, A, B = map(int, input().split()) if N < 20: print(min(A * x - B * y for x, y in gen_small(N))) exit() ans = (N - 1) * A - N * B d = (N - 1) // 2 x = (N - 1) - 4 * d y = N - 2 * d ans = min(ans, A * x - B * y) if N % 2 == 0: x -= 2 y -= 2 ans = min(ans, A * x - B * y) print(ans)