結果

問題 No.281 門松と魔法(1)
ユーザー uafr_csuafr_cs
提出日時 2015-09-18 23:16:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 77,328 KB
実行使用メモリ 41,740 KB
最終ジャッジ日時 2024-04-24 11:36:38
合計ジャッジ時間 10,147 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
41,372 KB
testcase_01 AC 99 ms
40,040 KB
testcase_02 AC 98 ms
40,036 KB
testcase_03 AC 104 ms
40,428 KB
testcase_04 AC 100 ms
40,164 KB
testcase_05 AC 112 ms
41,296 KB
testcase_06 AC 109 ms
41,192 KB
testcase_07 AC 107 ms
41,052 KB
testcase_08 AC 106 ms
41,040 KB
testcase_09 AC 99 ms
39,860 KB
testcase_10 AC 103 ms
40,304 KB
testcase_11 AC 105 ms
40,936 KB
testcase_12 AC 106 ms
41,180 KB
testcase_13 AC 102 ms
40,304 KB
testcase_14 AC 106 ms
41,016 KB
testcase_15 WA -
testcase_16 AC 107 ms
41,444 KB
testcase_17 WA -
testcase_18 AC 107 ms
40,900 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 110 ms
41,060 KB
testcase_23 WA -
testcase_24 AC 111 ms
41,456 KB
testcase_25 AC 108 ms
41,168 KB
testcase_26 AC 112 ms
41,284 KB
testcase_27 AC 101 ms
40,148 KB
testcase_28 AC 111 ms
41,304 KB
testcase_29 AC 99 ms
40,200 KB
testcase_30 AC 114 ms
41,332 KB
testcase_31 AC 104 ms
40,796 KB
testcase_32 AC 115 ms
41,276 KB
testcase_33 AC 119 ms
41,484 KB
testcase_34 WA -
testcase_35 AC 94 ms
40,052 KB
testcase_36 AC 107 ms
40,980 KB
testcase_37 AC 109 ms
40,944 KB
testcase_38 AC 101 ms
40,420 KB
testcase_39 AC 98 ms
39,924 KB
testcase_40 AC 121 ms
41,340 KB
testcase_41 AC 103 ms
40,308 KB
testcase_42 AC 115 ms
41,144 KB
testcase_43 AC 276 ms
41,196 KB
testcase_44 AC 105 ms
41,368 KB
testcase_45 AC 109 ms
41,336 KB
testcase_46 AC 100 ms
40,312 KB
testcase_47 AC 111 ms
41,304 KB
testcase_48 AC 98 ms
40,396 KB
testcase_49 AC 99 ms
40,348 KB
testcase_50 AC 108 ms
41,500 KB
testcase_51 AC 107 ms
41,192 KB
testcase_52 AC 106 ms
41,164 KB
testcase_53 AC 110 ms
41,196 KB
testcase_54 AC 108 ms
41,324 KB
testcase_55 AC 113 ms
41,336 KB
testcase_56 AC 105 ms
41,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static boolean is_valid_kadomatsu(long h1, long h2, long h3){
		if(h1 == h2 || h2 == h3 || h3 == h1){
			return false;
		}
		
		if(h1 < h2 && h2 > h3){
			return true;
		}else if(h1 > h2 && h2 < h3){
			return true;
		}
		
		return false;
	}
	
	public static int answer = 15;
	
	public static void dfs(int count, long d, long h1, long h2, long h3){
		if(answer < count){
			return;
		}else if(is_valid_kadomatsu(h1, h2, h3)){
			answer = Math.min(answer, count);
			return;
		}
		
		if(h1 != 0){
			dfs(count + 1, d, Math.max(0, h1 - d), h2, h3);
		}
		
		if(h3 != 0){
			dfs(count + 1, d, h1, Math.max(0, h2 - d), h3);
		}
		
		if(h3 != 0){
			dfs(count + 1, d, h1, h2, Math.max(0, h3 - d));
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long d = sc.nextLong();
		final long h1 = sc.nextLong();
		final long h2 = sc.nextLong();
		final long h3 = sc.nextLong();
		
		dfs(0, d, h1, h2, h3);
		System.out.println(answer == 15 ? -1 : answer);
		
	}

}
0