結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
41,400 KB
testcase_01 AC 110 ms
40,060 KB
testcase_02 WA -
testcase_03 AC 107 ms
41,172 KB
testcase_04 AC 124 ms
41,132 KB
testcase_05 AC 121 ms
41,608 KB
testcase_06 AC 118 ms
40,064 KB
testcase_07 AC 117 ms
41,204 KB
testcase_08 AC 118 ms
41,064 KB
testcase_09 AC 104 ms
41,328 KB
testcase_10 AC 113 ms
41,212 KB
testcase_11 AC 117 ms
41,284 KB
testcase_12 AC 115 ms
41,428 KB
testcase_13 AC 114 ms
41,304 KB
testcase_14 AC 115 ms
41,688 KB
testcase_15 AC 123 ms
41,444 KB
testcase_16 AC 117 ms
40,220 KB
testcase_17 AC 119 ms
41,212 KB
testcase_18 AC 114 ms
41,740 KB
testcase_19 AC 118 ms
41,524 KB
testcase_20 AC 125 ms
41,284 KB
testcase_21 AC 130 ms
41,384 KB
testcase_22 AC 123 ms
41,524 KB
testcase_23 AC 122 ms
41,364 KB
testcase_24 AC 104 ms
39,880 KB
testcase_25 WA -
testcase_26 AC 121 ms
41,180 KB
testcase_27 AC 112 ms
41,288 KB
testcase_28 AC 108 ms
41,432 KB
testcase_29 AC 119 ms
41,552 KB
testcase_30 AC 121 ms
41,128 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 126 ms
41,500 KB
testcase_34 WA -
testcase_35 AC 127 ms
41,284 KB
testcase_36 AC 116 ms
40,220 KB
testcase_37 AC 118 ms
41,264 KB
testcase_38 AC 114 ms
41,424 KB
testcase_39 AC 119 ms
40,404 KB
testcase_40 AC 121 ms
41,712 KB
testcase_41 AC 122 ms
41,104 KB
testcase_42 AC 118 ms
41,392 KB
testcase_43 RE -
testcase_44 AC 117 ms
41,212 KB
testcase_45 AC 118 ms
41,200 KB
testcase_46 AC 106 ms
41,024 KB
testcase_47 AC 115 ms
41,232 KB
testcase_48 AC 116 ms
40,032 KB
testcase_49 AC 117 ms
41,296 KB
testcase_50 RE -
testcase_51 WA -
testcase_52 AC 115 ms
41,372 KB
testcase_53 AC 116 ms
41,084 KB
testcase_54 AC 115 ms
40,160 KB
testcase_55 AC 114 ms
41,500 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();
		}
		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