結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2015-09-18 23:19:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,161 bytes |
| コンパイル時間 | 2,505 ms |
| コンパイル使用メモリ | 77,652 KB |
| 実行使用メモリ | 56,248 KB |
| 最終ジャッジ日時 | 2024-11-06 19:25:45 |
| 合計ジャッジ時間 | 13,501 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 WA * 7 |
ソースコード
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, h2, Math.max(0, h3 - d));
}
if(h2 != 0){
dfs(count + 1, d, h1, Math.max(0, h2 - d), h3);
}
}
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);
}
}
uafr_cs