結果

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

テストケース

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