結果

問題 No.281 門松と魔法(1)
ユーザー pekempeypekempey
提出日時 2015-09-18 23:14:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,535 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 159,068 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:33:46
合計ジャッジ時間 3,584 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 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 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 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 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 RE -
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 WA -
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 1 ms
5,376 KB
testcase_45 WA -
testcase_46 RE -
testcase_47 WA -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 2 ms
5,376 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 WA -
testcase_55 AC 2 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)	{
		cout << 0 << endl;		
		return 0;
	}
	if (h1 > h2 && h2 < h3) {
		cout << 0 << 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