結果

問題 No.2057 Ising Model
ユーザー t98slidert98slider
提出日時 2022-08-26 22:15:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 166,928 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 22:52:17
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ll n, a, b, ans = 1ll << 62;
    cin >> n >> a >> b;
    auto f = [&](ll c1){
        ll c2 = n - c1;
        if(c1 < 0 || c1 > n || c2 < 0 || c2 > n)return;
        ll d = min(2 * min(c1, c2), n - 1);
        ans = min(ans, a * (-d + (n - 1 - d)) + b * (c1 - c2));
    };
    for(ll i = 0; i <= 100; i++){
        f(i);
        f(n - i);
        f(n / 2 + i);
        f(n / 2 - i);
    }
    cout << ans << '\n';
}
0