結果

問題 No.281 門松と魔法(1)
ユーザー t98slidert98slider
提出日時 2023-02-02 04:29:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 167,060 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-14 13:17:36
合計ジャッジ時間 4,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int main(){
    ll d;
    vector<ll> a(3);
    cin >> d >> a[0] >> a[1] >> a[2];
    auto f0 = [&](ll v1, ll v2, ll v3){
        if(v1 == v3)return false;
        if(v2 > max(v1, v3))return true;
        return (v2 < min(v1, v3));
    };
    auto f1 = [&](ll v1, ll v2, ll v3){
        ll mn = min(v1, v3);
        if(mn == 0 || d == 0)return 1ll << 60;
        ll c = (max(0ll, v2 - (mn - 1)) + d - 1) / d, ans = 0;
        v2 -= c * d, ans += c;
        if(v2 < 0)return 1ll << 60;
        if(v1 == v3){
            if(v1 - d < 0)return 1ll << 60;
            ans++;
            if(v2 >= v1 - d){
                v2 -= d;
                ans++;
                if(v2 < 0)return 1ll << 60;
            }
        }
        return ans;
    };
    auto f2 = [&](ll v1, ll v2, ll v3){
        ll ans = 0;
        if(d == 0)return 1ll << 60;
        ll c = (max(0ll, v1 - (v2 - 1)) + d - 1) / d;
        ans += c, v1 -= d * c;
        c = (max(0ll, v3 - (v2 - 1)) + d - 1) / d;
        ans += c, v3 -= d * c;
        if(min(v1, v3) < 0)return 1ll << 60;
        if(v1 == v3){
            if(v1 == 0)return 1ll << 60;
        }
        return ans;
    };
    ll ans = min(f1(a[0], a[1], a[2]), f2(a[0], a[1], a[2]));
    if(f0(a[0], a[1], a[2]))ans = 0;
    if(ans >> 60)ans = -1;
    cout << ans << '\n';
}
0