結果

問題 No.281 門松と魔法(1)
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-12 21:12:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 204,924 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 16:23:49
合計ジャッジ時間 3,477 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/281/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll d;
    vector<ll> H(3);
    cin >> d;
    for (auto&& h : H) {
        cin >> h;
    }
    if ((H[0] < H[1] && H[1] > H[2] && H[0] != H[2]) || (H[0] > H[1] && H[1] < H[2] && H[0] != H[2])) {
        cout << 0 << endl;
        return 0;
    }
    if (d == 0) {
        cout << -1 << endl;
        return 0;
    }
    ll maine = 1e11;
    auto book = [&](ll& height, ll threshold) {
        if (threshold == 0)
            return (ll)1e11;
        if (height < threshold)
            return 0ll;
        ll ret = (height - threshold + d) / d;
        height -= ret * d;
        if (height < 0)
            return (ll)1e11;
        return ret;
    };
    {
        //low-high-low;
        auto h = H;
        ll score = book(h[0], h[1]) + book(h[2], h[1]);
        if (h[0] == h[2])
            score += book(h[0], h[2]);
        maine = min(maine, score);
    }
    {
        //high-low-high
        auto h = H;
        ll score = 0;
        if (h[0] == h[2])
            score += book(h[0], h[2]);
        score += book(h[1], h[0]) + book(h[1], h[2]);
        maine = min(maine, score);
    }
    cout << (maine > 1e10 ? -1 : maine) << endl;
}
0