結果

問題 No.281 門松と魔法(1)
ユーザー ぴろずぴろず
提出日時 2015-09-18 22:37:47
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 2,813 ms
コンパイル使用メモリ 77,400 KB
実行使用メモリ 41,564 KB
最終ジャッジ日時 2024-04-24 10:59:32
合計ジャッジ時間 9,847 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
40,088 KB
testcase_01 AC 108 ms
40,196 KB
testcase_02 WA -
testcase_03 AC 115 ms
41,004 KB
testcase_04 AC 96 ms
39,524 KB
testcase_05 AC 104 ms
39,732 KB
testcase_06 AC 116 ms
40,964 KB
testcase_07 AC 109 ms
40,224 KB
testcase_08 AC 126 ms
41,324 KB
testcase_09 AC 124 ms
41,264 KB
testcase_10 AC 113 ms
41,228 KB
testcase_11 AC 111 ms
41,120 KB
testcase_12 AC 101 ms
40,056 KB
testcase_13 AC 113 ms
40,860 KB
testcase_14 AC 100 ms
40,364 KB
testcase_15 AC 111 ms
41,028 KB
testcase_16 AC 114 ms
41,208 KB
testcase_17 AC 113 ms
40,992 KB
testcase_18 AC 114 ms
41,164 KB
testcase_19 AC 119 ms
41,056 KB
testcase_20 AC 111 ms
41,096 KB
testcase_21 AC 113 ms
40,996 KB
testcase_22 AC 115 ms
41,228 KB
testcase_23 AC 115 ms
41,220 KB
testcase_24 AC 101 ms
39,908 KB
testcase_25 WA -
testcase_26 AC 121 ms
41,376 KB
testcase_27 AC 115 ms
41,016 KB
testcase_28 AC 113 ms
41,128 KB
testcase_29 AC 115 ms
41,168 KB
testcase_30 AC 117 ms
41,032 KB
testcase_31 AC 120 ms
40,056 KB
testcase_32 AC 122 ms
41,196 KB
testcase_33 AC 125 ms
41,160 KB
testcase_34 WA -
testcase_35 AC 124 ms
41,116 KB
testcase_36 AC 117 ms
41,128 KB
testcase_37 AC 115 ms
40,460 KB
testcase_38 AC 111 ms
40,820 KB
testcase_39 AC 114 ms
40,108 KB
testcase_40 AC 110 ms
41,308 KB
testcase_41 AC 115 ms
40,872 KB
testcase_42 AC 111 ms
41,092 KB
testcase_43 AC 100 ms
39,904 KB
testcase_44 AC 111 ms
40,880 KB
testcase_45 AC 115 ms
41,288 KB
testcase_46 AC 111 ms
41,256 KB
testcase_47 AC 103 ms
40,084 KB
testcase_48 AC 107 ms
40,920 KB
testcase_49 AC 103 ms
40,080 KB
testcase_50 AC 116 ms
40,276 KB
testcase_51 WA -
testcase_52 AC 115 ms
41,188 KB
testcase_53 AC 116 ms
41,352 KB
testcase_54 AC 115 ms
41,120 KB
testcase_55 AC 114 ms
41,104 KB
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no280;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int[] h = new int[3];
		for(int i=0;i<3;i++) {
			h[i] = sc.nextInt();
		}

		if (d == 0) {
			if (h[0] != h[1] && h[1] != h[2] && h[2] != h[0] && (h[1] > h[0] && h[1] > h[2]) || (h[1] < h[0] && h[1] < h[2])) {
				System.out.println(0);
			}else{
				System.out.println(-1);
			}
			return;
		}


		int[] p = new int[3];
		for(int i=0;i<3;i++) {
			p[i] = i;
		}

		int ans = 1 << 29;
		do {
			if (p[0] != 1 && p[2] != 1) {
				continue;
			}
			int count = 0;
			int x = h[p[0]];
			for(int i=1;i<3;i++) {
				if (x == 0) {
					count = 1 << 29;
					break;
				}
				if (h[p[i]] >= x) {
					int magic = (h[p[i]] - x) / d + 1;
					count += magic;
					x = h[p[i]] - magic * d;
				}else{
					x = h[p[i]];
				}
			}
//			System.out.println(Arrays.toString(p) + ":" + count);
			ans = Math.min(ans,count);
		} while(nextPermutation(p));

		if (ans >= 1 << 29) {
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}

	static boolean nextPermutation(int[] p) {
		for(int a=p.length-2;a>=0;--a) {
			if(p[a]<p[a+1]) {
				for(int b=p.length-1;;--b) {
					if(p[b]>p[a]) {
						int t = p[a];
						p[a] = p[b];
						p[b] = t;
						for(++a, b=p.length-1;a<b;++a,--b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}

}
0