結果

問題 No.281 門松と魔法(1)
ユーザー t98slidert98slider
提出日時 2023-02-02 04:33:14
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 1,401 ms
使用メモリ 3,520 KB
最終ジャッジ日時 2023-02-02 04:33:17
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,464 KB
testcase_01 AC 1 ms
3,412 KB
testcase_02 AC 2 ms
3,488 KB
testcase_03 AC 1 ms
3,372 KB
testcase_04 AC 1 ms
3,440 KB
testcase_05 AC 2 ms
3,492 KB
testcase_06 AC 2 ms
3,476 KB
testcase_07 AC 2 ms
3,412 KB
testcase_08 AC 2 ms
3,372 KB
testcase_09 AC 2 ms
3,384 KB
testcase_10 AC 1 ms
3,496 KB
testcase_11 AC 1 ms
3,440 KB
testcase_12 AC 1 ms
3,384 KB
testcase_13 AC 1 ms
3,372 KB
testcase_14 AC 2 ms
3,372 KB
testcase_15 AC 2 ms
3,340 KB
testcase_16 AC 2 ms
3,496 KB
testcase_17 AC 1 ms
3,412 KB
testcase_18 AC 2 ms
3,428 KB
testcase_19 AC 1 ms
3,364 KB
testcase_20 AC 2 ms
3,340 KB
testcase_21 AC 1 ms
3,332 KB
testcase_22 AC 2 ms
3,520 KB
testcase_23 AC 1 ms
3,340 KB
testcase_24 AC 2 ms
3,400 KB
testcase_25 AC 1 ms
3,400 KB
testcase_26 AC 1 ms
3,448 KB
testcase_27 AC 2 ms
3,452 KB
testcase_28 AC 2 ms
3,404 KB
testcase_29 AC 1 ms
3,460 KB
testcase_30 AC 1 ms
3,420 KB
testcase_31 AC 1 ms
3,432 KB
testcase_32 AC 1 ms
3,388 KB
testcase_33 AC 2 ms
3,432 KB
testcase_34 AC 1 ms
3,336 KB
testcase_35 AC 1 ms
3,404 KB
testcase_36 AC 1 ms
3,440 KB
testcase_37 AC 2 ms
3,340 KB
testcase_38 AC 2 ms
3,456 KB
testcase_39 WA -
testcase_40 AC 1 ms
3,408 KB
testcase_41 WA -
testcase_42 AC 1 ms
3,340 KB
testcase_43 AC 1 ms
3,436 KB
testcase_44 AC 2 ms
3,372 KB
testcase_45 AC 2 ms
3,376 KB
testcase_46 AC 2 ms
3,444 KB
testcase_47 AC 2 ms
3,368 KB
testcase_48 AC 2 ms
3,360 KB
testcase_49 AC 2 ms
3,340 KB
testcase_50 AC 2 ms
3,336 KB
testcase_51 AC 1 ms
3,340 KB
testcase_52 AC 1 ms
3,440 KB
testcase_53 AC 1 ms
3,336 KB
testcase_54 AC 1 ms
3,440 KB
testcase_55 AC 1 ms
3,500 KB
testcase_56 AC 2 ms
3,440 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;
        v2 = max(v2, 0ll);
        if(v1 == v3){
            v1 -= d;
            ans++;
            v1 = max(v1, 0ll);
            if(v2 >= v1){
                v2 -= d;
                ans++;
                v2 = max(v2, 0ll);
            }
        }
        return (f0(v1, v2, v3) ? ans : 1ll << 60);
    };
    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