結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー | hiromi_ayase |
提出日時 | 2016-07-08 22:41:24 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 548 ms / 2,000 ms |
コード長 | 1,249 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 77,524 KB |
実行使用メモリ | 74,240 KB |
最終ジャッジ日時 | 2024-10-13 06:07:42 |
合計ジャッジ時間 | 23,616 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 100 ms
40,272 KB |
testcase_01 | AC | 113 ms
41,332 KB |
testcase_02 | AC | 103 ms
39,852 KB |
testcase_03 | AC | 123 ms
41,556 KB |
testcase_04 | AC | 116 ms
41,272 KB |
testcase_05 | AC | 114 ms
41,100 KB |
testcase_06 | AC | 118 ms
41,120 KB |
testcase_07 | AC | 114 ms
41,420 KB |
testcase_08 | AC | 115 ms
41,120 KB |
testcase_09 | AC | 249 ms
48,300 KB |
testcase_10 | AC | 211 ms
47,724 KB |
testcase_11 | AC | 252 ms
48,256 KB |
testcase_12 | AC | 204 ms
47,092 KB |
testcase_13 | AC | 429 ms
58,216 KB |
testcase_14 | AC | 274 ms
49,940 KB |
testcase_15 | AC | 206 ms
44,320 KB |
testcase_16 | AC | 223 ms
47,832 KB |
testcase_17 | AC | 258 ms
48,860 KB |
testcase_18 | AC | 540 ms
71,624 KB |
testcase_19 | AC | 119 ms
41,424 KB |
testcase_20 | AC | 114 ms
41,332 KB |
testcase_21 | AC | 117 ms
41,280 KB |
testcase_22 | AC | 121 ms
41,280 KB |
testcase_23 | AC | 107 ms
40,084 KB |
testcase_24 | AC | 119 ms
41,292 KB |
testcase_25 | AC | 120 ms
41,424 KB |
testcase_26 | AC | 119 ms
41,464 KB |
testcase_27 | AC | 120 ms
41,080 KB |
testcase_28 | AC | 120 ms
41,192 KB |
testcase_29 | AC | 106 ms
40,560 KB |
testcase_30 | AC | 110 ms
40,700 KB |
testcase_31 | AC | 119 ms
41,264 KB |
testcase_32 | AC | 109 ms
40,216 KB |
testcase_33 | AC | 121 ms
41,440 KB |
testcase_34 | AC | 123 ms
41,644 KB |
testcase_35 | AC | 114 ms
41,428 KB |
testcase_36 | AC | 122 ms
41,408 KB |
testcase_37 | AC | 114 ms
40,988 KB |
testcase_38 | AC | 118 ms
41,364 KB |
testcase_39 | AC | 115 ms
41,880 KB |
testcase_40 | AC | 117 ms
41,232 KB |
testcase_41 | AC | 116 ms
41,392 KB |
testcase_42 | AC | 119 ms
41,224 KB |
testcase_43 | AC | 102 ms
40,196 KB |
testcase_44 | AC | 126 ms
41,512 KB |
testcase_45 | AC | 117 ms
41,160 KB |
testcase_46 | AC | 105 ms
40,256 KB |
testcase_47 | AC | 117 ms
41,400 KB |
testcase_48 | AC | 119 ms
41,452 KB |
testcase_49 | AC | 477 ms
71,380 KB |
testcase_50 | AC | 171 ms
43,600 KB |
testcase_51 | AC | 164 ms
43,400 KB |
testcase_52 | AC | 262 ms
47,640 KB |
testcase_53 | AC | 182 ms
44,568 KB |
testcase_54 | AC | 255 ms
47,916 KB |
testcase_55 | AC | 130 ms
41,520 KB |
testcase_56 | AC | 175 ms
43,644 KB |
testcase_57 | AC | 331 ms
55,056 KB |
testcase_58 | AC | 423 ms
64,472 KB |
testcase_59 | AC | 393 ms
59,960 KB |
testcase_60 | AC | 266 ms
51,836 KB |
testcase_61 | AC | 430 ms
74,240 KB |
testcase_62 | AC | 287 ms
51,632 KB |
testcase_63 | AC | 428 ms
64,444 KB |
testcase_64 | AC | 275 ms
47,892 KB |
testcase_65 | AC | 222 ms
48,492 KB |
testcase_66 | AC | 273 ms
51,640 KB |
testcase_67 | AC | 270 ms
48,128 KB |
testcase_68 | AC | 284 ms
47,916 KB |
testcase_69 | AC | 119 ms
41,460 KB |
testcase_70 | AC | 115 ms
41,400 KB |
testcase_71 | AC | 109 ms
40,164 KB |
testcase_72 | AC | 119 ms
41,068 KB |
testcase_73 | AC | 118 ms
41,648 KB |
testcase_74 | AC | 105 ms
40,192 KB |
testcase_75 | AC | 115 ms
41,308 KB |
testcase_76 | AC | 115 ms
41,120 KB |
testcase_77 | AC | 115 ms
41,184 KB |
testcase_78 | AC | 120 ms
41,576 KB |
testcase_79 | AC | 104 ms
40,320 KB |
testcase_80 | AC | 116 ms
41,360 KB |
testcase_81 | AC | 114 ms
41,200 KB |
testcase_82 | AC | 119 ms
41,364 KB |
testcase_83 | AC | 108 ms
39,988 KB |
testcase_84 | AC | 108 ms
40,224 KB |
testcase_85 | AC | 121 ms
41,564 KB |
testcase_86 | AC | 119 ms
41,404 KB |
testcase_87 | AC | 116 ms
41,528 KB |
testcase_88 | AC | 103 ms
39,816 KB |
testcase_89 | AC | 317 ms
53,040 KB |
testcase_90 | AC | 429 ms
58,924 KB |
testcase_91 | AC | 548 ms
71,084 KB |
testcase_92 | AC | 248 ms
48,160 KB |
testcase_93 | AC | 466 ms
62,888 KB |
testcase_94 | AC | 158 ms
41,768 KB |
testcase_95 | AC | 490 ms
63,192 KB |
testcase_96 | AC | 425 ms
59,276 KB |
testcase_97 | AC | 398 ms
55,696 KB |
testcase_98 | AC | 312 ms
48,032 KB |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.nextLine()); String[] s = sc.nextLine().split(" "); int K = s.length; int[] H = new int[K]; for (int i = 0; i < K; i++) { H[i] = Integer.parseInt(s[i]); N -= H[i]; } N++; if (H[0] == 0) { System.out.println(1); } else if (N < K || K < 0 || N <= 0) { System.out.println("NA"); } else { System.out.println(combMod(N, K, 1000000007)); } } public static long combMod(long n, long r, long mod) { long comb = 1; for (int i = 0; i < r; i++) { comb = (comb * (n - i)) % mod; comb = (comb * inverse(r - i, mod)) % mod; } return comb; } public static long[] extgcd(long a, long b) { long u = 1; long v = 0; long x = 0; long y = 1; while (a > 0) { long q = b / a; x -= q * u; y -= q * v; b -= q * a; long tmp; tmp = x; x = u; u = tmp; tmp = y; y = v; v = tmp; tmp = b; b = a; a = tmp; } return new long[] { b, x, y }; } public static long inverse(long n, long mod) { long[] gcd = extgcd(n, mod); if (gcd[0] == 1) { return (gcd[1] + mod) % mod; } else { return 0; } } }