結果

問題 No.281 門松と魔法(1)
ユーザー masamasa
提出日時 2015-09-18 23:30:13
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,190 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 60,740 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 16:26:40
合計ジャッジ時間 2,622 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int d, h1, h2, h3;

int calc_h2max() {
	int ans = 0;
	int a = h1;
	int b = h2;
	int c = h3;

	if (b < 2) {
		return -1;
	}

	int n;

	if (b <= a) {
		n = (a - b) / d + 1;
		a -= n * d;
		a = max(a, 0);
		ans += n;
	}

	if (b <= c) {
		n = (c - b) / d + 1;
		c -= n * d;
		c = max(c, 0);
		ans += n;
	}

	if (a != c) {
		return ans;
	}

	if (a == 0) {
		return -1;
	}

	return ans + 1;

}

int calc_h2min() {

	int ans = 0;
	int a = h1;
	int b = h2;
	int c = h3;

	int n;

	int min_ac = min(a, c);

	if (min_ac < 1) {
		return -1;
	}

	if (b >= min_ac) {
		n = (b - min_ac) / d + 1;
		b -= n * d;
		b = max(0, b);
		ans += n;
	}

	if (a != c) {
		return ans;
	}

	a = max(0, a - d);
	ans++;
	if (b < a) {
		return ans;
	}

	b = max(0, b - d);
	ans++;
	if (b != a) {
		return ans;
	}

	return -1;
}


int main() {
	cin >> d >> h1 >> h2 >> h3;

	int ans1 = calc_h2max();
	int ans2 = calc_h2min();

	int ans;

	if (ans1 == -1) {
		ans = ans2;
	} else if (ans2 == -1) {
		ans = ans1;
	} else {
		ans = min(ans1, ans2);
	}

	cout << ans << endl;
	return 0;
}
0