結果

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

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;
int main()
{
	int d;
	cin >> d;
	int h1, h2, h3;
	cin >> h1 >> h2 >> h3;

	if(h1 != h2 && h1 != h3 && h2 != h3)
	{
		if(h1 < h2 && h3 < h2)
		{
			cout << 0;
			return 0;
		}

		if(h1 > h2 && h3 > h2)
		{
			cout << 0;
			return 0;
		}

		if(h1 > h2 && h1 > h3) // h2 > h3
		{
			int temp = h1;
			h1 = h3;
			h3 = h1;
		}

		// h1 < h2 < h3		
		int mh3 = (h3 - h2) / d + 1;
		int mh2 = (h2 - h1) / d + 1;

		if(h2 - mh2*d >= 0 && h3 - mh3*d >= 0)
		{
			cout << min(mh2, mh3);
		}
		else if(h2 - mh2*d >= 0)
		{
			cout << mh2;
		}
		else if( h3 - mh3*d >= 0)
		{
			cout << mh3;
		}
		{
			cout << -1;
		}
		return 0;
	}

	if(h1 == h2 == h3)
	{
		if(h1 - d*2 >= 0)
		{
			cout << 3;
		}
		else
		{
			cout << -1;
		}

		return 0;
	}

	if(h1 == h3)
	{
		if(h1 < d)
		{
			cout << -1;
		}
		else
		{
			if(h2 > h1)
			{
				cout << 1;
			}
			else
			{
				int mh3 = (h3 - h2) / d + 2;
				if(h3 - mh3*d <0)
				{
					cout << -1;
				}
				else
				{
					cout << mh3 * 2 - 1;
				}
			}
		}
		return 0;
	}

	if(h1 == h2)
	{
		h1 = h3;
		h3 = h2;
	}


	// h1 != h2 == h3

	if(h1 < h2)
	{
		int mh3 = (h3 - h2) / d + 2;
		if(h3 - mh3*d == h1) mh3++;

		if(h3 - mh3*d < 0)
		{
			cout << -1;
		}
		else
		{
			cout << mh3;
		}

		return 0;
	}
	else
	{
		if(h2 >= d)
		{
			cout << 1;
		}
		else
		{
			cout << -1;
		}

		return 0;
	}

	cout << -1;

	return 0;
}
0