結果

問題 No.281 門松と魔法(1)
ユーザー pekempeypekempey
提出日時 2015-09-18 23:29:59
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,886 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 159,088 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:41:17
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
#define rng(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;

int main() {
    ll d, h1, h2, h3;
    cin >> d >> h1 >> h2 >> h3;
    if (h1 < h2 && h2 > h3 && h1 != h3) {
        cout << 0 << endl;		
        return 0;
    }
    if (h1 > h2 && h2 < h3 && h1 != h3) {
        cout << 0 << endl;
        return 0;
    }
    if (d == 0) {
    	cout << -1 << endl;
    	return 0;
    }
    const ll inf = 1e18;
    auto f = [&](ll a, ll b) { 
        if (a < b) return inf;
        return (a - b + d) / d; 
    };
    auto g = [&](ll a) {
        return max(0ll, a - d);
    };
    ll ans = inf;
    {
        ll th1 = h1;
        ll cand = 0;
        if (th1 == h3) th1 = g(th1), cand++;
        ll c = f(h2, min(th1, h3));	
        cand += c;
        ll th2 = max(0ll, h2 - c * d);
        if (th1 == th2 || th2 == h3 || h3 == th1) cand = inf;
        cerr << cand << endl;
        chmin(ans, cand);
    }
    {
        ll th3 = h3;
        ll cand = 0;
        if (h2 == th3) th3 = g(th3), cand++;
        ll c = f(h1, h3);
        cand += c;
        ll th1 = max(0ll, h1 - c * d);
        if (th1 == h2 || h2 == th3 || th3 == th1) cand = inf;
        cerr << cand << endl;
        chmin(ans, cand);
    }
    {
        ll th1 = h1;
        ll cand = 0;
        if (th1 == h2) th1 = g(th1), cand++;
        ll c = f(h3, h2);
        cand += c;
        ll th3 = max(0ll, h3 - c * d);
        if (th1 == h2 || h2 == th3 || th3 == th1) cand = inf;
        cerr << cand << endl;
        chmin(ans, cand);
    }
    if (ans >= inf) ans = -1;
    cout << ans << endl;
}
0