結果
問題 | No.281 門松と魔法(1) |
ユーザー | uafr_cs |
提出日時 | 2015-12-04 02:40:48 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,970 bytes |
コンパイル時間 | 2,360 ms |
コンパイル使用メモリ | 77,924 KB |
実行使用メモリ | 54,424 KB |
最終ジャッジ日時 | 2024-11-06 19:47:10 |
合計ジャッジ時間 | 11,683 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
54,200 KB |
testcase_01 | AC | 134 ms
54,204 KB |
testcase_02 | WA | - |
testcase_03 | AC | 132 ms
53,992 KB |
testcase_04 | AC | 132 ms
54,016 KB |
testcase_05 | AC | 136 ms
54,100 KB |
testcase_06 | AC | 133 ms
54,060 KB |
testcase_07 | AC | 135 ms
54,252 KB |
testcase_08 | AC | 135 ms
53,952 KB |
testcase_09 | AC | 136 ms
54,116 KB |
testcase_10 | AC | 134 ms
53,972 KB |
testcase_11 | AC | 135 ms
54,200 KB |
testcase_12 | AC | 133 ms
54,088 KB |
testcase_13 | AC | 134 ms
54,076 KB |
testcase_14 | AC | 132 ms
54,032 KB |
testcase_15 | AC | 135 ms
53,832 KB |
testcase_16 | AC | 134 ms
53,872 KB |
testcase_17 | WA | - |
testcase_18 | AC | 123 ms
53,852 KB |
testcase_19 | AC | 137 ms
54,128 KB |
testcase_20 | AC | 134 ms
54,160 KB |
testcase_21 | AC | 135 ms
53,916 KB |
testcase_22 | AC | 133 ms
53,996 KB |
testcase_23 | WA | - |
testcase_24 | AC | 134 ms
54,040 KB |
testcase_25 | WA | - |
testcase_26 | AC | 143 ms
54,256 KB |
testcase_27 | AC | 144 ms
53,736 KB |
testcase_28 | AC | 133 ms
53,992 KB |
testcase_29 | AC | 136 ms
54,328 KB |
testcase_30 | WA | - |
testcase_31 | AC | 133 ms
54,292 KB |
testcase_32 | AC | 132 ms
54,052 KB |
testcase_33 | WA | - |
testcase_34 | AC | 133 ms
54,108 KB |
testcase_35 | WA | - |
testcase_36 | AC | 134 ms
54,252 KB |
testcase_37 | AC | 135 ms
54,212 KB |
testcase_38 | WA | - |
testcase_39 | AC | 135 ms
53,920 KB |
testcase_40 | AC | 136 ms
54,048 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 133 ms
54,204 KB |
testcase_45 | AC | 132 ms
54,024 KB |
testcase_46 | AC | 135 ms
54,080 KB |
testcase_47 | AC | 134 ms
54,112 KB |
testcase_48 | AC | 136 ms
53,856 KB |
testcase_49 | AC | 135 ms
53,708 KB |
testcase_50 | AC | 133 ms
53,844 KB |
testcase_51 | WA | - |
testcase_52 | AC | 124 ms
53,040 KB |
testcase_53 | AC | 135 ms
54,132 KB |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
ソースコード
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(final long h1, final long h2, final long h3){ return (h1 < h2 && h2 > h3) || (h1 > h2 && h2 < h3); } public static long d(final long h, final long d){ return Math.max(0, h - d); } public static long d(final long h_max, final long h_min, final long d){ return h_max < h_min ? 0 : (h_max - h_min) / d + 1; } public static long all_same(final long h, final long d){ return h > d ? 3 : -1; } public static long two_same(final long h1, final long h2, final long h3, final long d){ if(h1 == h2 && h2 < h3){ return is_valid(h1, d(h2, d), h3) ? 1 : -1; } if(h1 > h2 && h2 == h3){ return is_valid(h1, d(h2, d), h3) ? 1 : -1; } if(h1 == h2 && h2 > h3){ if(is_valid(d(h1, d), h2, h3)){ // d(h1) < h2 && h2 > h3 return 1; } final long h2_count = d(h2, h3, d); final long d_h2 = h2 - d * h2_count; if(is_valid(h1, d_h2, h3)){ return h2_count; } // h1 > d(h2) && d(h2) < h3 else{ return -1; } } if(h1 < h2 && h2 == h3){ if(is_valid(h1, h2, d(h3, d))){ return 1; } final long h2_count = d(h2, h1, d); final long d_h2 = h2 - d * h2_count; if(is_valid(h1, d_h2, h3)){ return h2_count; } else { return -1; } } if(h1 == h3 && h1 < h2){ return is_valid(d(h1, d), h2, h3) ? 1 : -1; } if(h1 == h3 && h1 > h2){ final long h1_count = d(h1, h2, d); final long d_h1 = h1 - d * h1_count; if(d_h1 == 0){ return -1; } return h1_count * 2 + 1; } return -1; } public static long all_diff(final long h1, final long h2, final long h3, final long d){ if(h1 > h2 && h2 > h3){ final long h1_count = d(h1, h2, d); final long d_h1 = h1 - d * h1_count; if(is_valid(d_h1, h2, h3)){ return h1_count; }else{ return two_same(h1, h2, h3, d); } } if(h1 < h2 && h2 < h3){ final long h3_count = d(h3, h2, d); final long d_h3 = h3 - d * h3_count; //System.out.println(d_h3); if(is_valid(h1, h2, d_h3)){ return h3_count; }else{ return two_same(h1, h2, h3, d); } } return -1; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final long d = sc.nextLong(); long h1 = sc.nextLong(); long h2 = sc.nextLong(); long h3 = sc.nextLong(); if(is_valid(h1, h2, h3)){ System.out.println(0); return; }else if(d == 0){ System.out.println(-1); return; } final long max = Math.max(h1, Math.max(h2, h3)); final long min = Math.min(h1, Math.min(h2, h3)); final long med = (h1 + h2 + h3) - (max + min); //System.out.println(max + " " + min + " " + med); if(max == min){ System.out.println(all_same(max, d)); }else if(max == med || min == med){ System.out.println(two_same(h1, h2, h3, d)); }else{ System.out.println(all_diff(h1, h2, h3, d)); } } }