結果

問題 No.281 門松と魔法(1)
ユーザー t98slidert98slider
提出日時 2023-02-02 04:22:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 925 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 166,964 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 13:13:17
合計ジャッジ時間 5,682 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
4,376 KB
testcase_41 WA -
testcase_42 AC 2 ms
4,376 KB
testcase_43 RE -
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 RE -
testcase_47 AC 1 ms
4,380 KB
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 1 ms
4,376 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 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 f1 = [&](ll v1, ll v2, ll v3){
        ll mn = min(v1, v3);
        if(mn == 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;
        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(ans >> 60)ans = -1;
    cout << ans << '\n';
}
0