結果

問題 No.281 門松と魔法(1)
ユーザー lattice
提出日時 2015-09-19 00:15:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,750 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 64,576 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-06 19:32:21
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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(d == 0)
	{
		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;
			}
		}
		cout << -1;
		return 0;
	}

	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 = temp;
		}

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

		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;
		}
		else
		{
			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 if(h3-d > h2)
			{
				cout << 1;
			}
			else if(h2 > d)
			{
				cout << 2;
			}
			else
			{
				cout << -1;
			}
		}
		return 0;
	}

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


	// h1 != h2 == h3

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

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

		return 0;
	}

	cout << -1;

	return 0;
}
0