結果

問題 No.281 門松と魔法(1)
ユーザー startcppstartcpp
提出日時 2015-09-18 23:43:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,476 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 55,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:42:07
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 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 1 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
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 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 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 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 1 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 RE -
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 RE -
testcase_47 AC 2 ms
5,376 KB
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 RE -
testcase_55 WA -
testcase_56 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//最高位はたたかない。k位にするものはk-1位より短くなるまで叩く。ただし負になったらGEND。
#include <iostream>
#define LL long long
using namespace std;

LL d;
LL h[4];

int main() {
	LL H[4];
	LL N[4];
	LL ans = 1145141919893810;
	
	cin >> d;
	cin >> h[1] >> h[2] >> h[3];
	
	//h[1] < h[3] < h[2]
	N[2] = 0;
	H[2] = h[2];
	N[3] = max((LL)0, (h[3] - H[2] + d)/d);
	H[3] = h[3] - N[3] * d;
	N[1] = max((LL)0, (h[1] - H[3] + d)/d);
	H[1] = h[1] - N[1] * d;
	if( H[1] < H[3] && H[3] < H[2] && H[1] >= 0 )
		ans = min(ans, N[1] + N[2] + N[3]);
		
	//h[3] < h[1] < h[2]
	N[2] = 0;
	H[2] = h[2];
	N[1] = max((LL)0, (h[1] - H[2] + d)/d);
	H[1] = h[1] - N[1] * d;
	N[3] = max((LL)0, (h[3] - H[1] + d)/d);
	H[3] = h[3] - N[3] * d;
	if( H[3] < H[1] && H[1] < H[2] && H[3] >= 0 )
		ans = min(ans, N[1] + N[2] + N[3]);
		
	//h[2] < h[1] < h[3]
	N[3] = 0;
	H[3] = h[3];
	N[1] = max((LL)0, (h[1] - H[3] + d)/d);
	H[1] = h[1] - N[1] * d;
	N[2] = max((LL)0, (h[2] - H[1] + d)/d);
	H[2] = h[2] - N[2] * d;
	if( H[2] < H[1] && H[1] < H[3] && H[2] >= 0 )
		ans = min(ans, N[1] + N[2] + N[3]);
		
	//h[2] < h[3] < h[1]
	N[1] = 0;
	H[1] = h[1];
	N[3] = max((LL)0, (h[3] - H[1] + d)/d);
	H[3] = h[3] - N[3] * d;
	N[2] = max((LL)0, (h[2] - H[3] + d)/d);
	H[2] = h[2] - N[2] * d;
	if( H[2] < H[3] && H[3] < H[1] && H[2] >= 0 )
		ans = min(ans, N[1] + N[2] + N[3]);
	
	if( ans == 1145141919893810 )
		cout << "-1" << endl;
	else
		cout << ans << endl;
	return 0;
}
0