結果

問題 No.281 門松と魔法(1)
ユーザー lattice
提出日時 2015-09-18 23:43:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,477 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 63,736 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-06 19:29:30
合計ジャッジ時間 2,235 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 36 RE * 2
権限があれば一括ダウンロードができます

ソースコード

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