結果

問題 No.281 門松と魔法(1)
ユーザー FF256grhy
提出日時 2015-11-06 19:06:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 888 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 20:43:18
合計ジャッジ時間 1,596 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d%d%d%d", &d, &h1, &h2, &h3);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

#define ERR 2000000000

int main(void) {
	int d, h1, h2, h3;
	scanf("%d%d%d%d", &d, &h1, &h2, &h3);
	
	int a = 0;
	if(d == 0) {
		if( (h1 < h2 && h3 < h2 && h1 != h3) || (h2 < h1 && h2 < h3 && h1 != h3) ) {}
		else { a = -1; }
	} else {
		if(h1 < h3) {
			int temp = h1;
			h1 = h3;
			h3 = temp;
		}
		if(h1 == h3) {
			h3 = (h3 < d ? 0 : h3 - d);
			a++;
		}
		
		if(h1 == h3) { a = -1; } else {
			if( (h1 < h2 && h3 < h2) || (h2 < h1 && h2 < h3) ) {}
			else {
				int x = (h1 - h2) / d + 1;
				h1 = (h1 < x * d ? 0 : h1 - x * d);
				if(h1 == h3) {
					h1 = (h1 < d ? 0 : h1 - d);
					x++;
					if(h1 == h3) { x = ERR; }
				}
				
				int y = (h2 - h3) / d + 1;
				h2 = (h2 < y * d ? 0 : h2 - y * d);
				if(h2 == h3) { y = ERR; }
				
				int z = (x < y ? x : y);
				if(z == ERR) { a = -1; } else { a += z; }
			}
		}
	}
	
	printf("%d\n", a);
	return 0;
}
0