結果

問題 No.281 門松と魔法(1)
ユーザー maine_honzuki
提出日時 2021-05-12 21:12:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 2,370 ms
コンパイル使用メモリ 196,436 KB
最終ジャッジ日時 2025-01-21 10:18:55
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 48 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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