結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-19 22:14:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 718 ms / 2,000 ms
コード長 1,213 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 74,548 KB
実行使用メモリ 56,852 KB
最終ジャッジ日時 2023-09-27 23:23:12
合計ジャッジ時間 29,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
39,424 KB
testcase_01 AC 110 ms
39,908 KB
testcase_02 AC 109 ms
39,508 KB
testcase_03 AC 110 ms
39,464 KB
testcase_04 AC 110 ms
39,424 KB
testcase_05 AC 114 ms
39,288 KB
testcase_06 AC 113 ms
39,496 KB
testcase_07 AC 113 ms
39,512 KB
testcase_08 AC 109 ms
39,528 KB
testcase_09 AC 300 ms
45,876 KB
testcase_10 AC 280 ms
45,736 KB
testcase_11 AC 354 ms
45,660 KB
testcase_12 AC 253 ms
45,640 KB
testcase_13 AC 483 ms
51,620 KB
testcase_14 AC 357 ms
45,996 KB
testcase_15 AC 236 ms
45,696 KB
testcase_16 AC 282 ms
45,588 KB
testcase_17 AC 319 ms
45,568 KB
testcase_18 AC 659 ms
53,868 KB
testcase_19 AC 113 ms
39,812 KB
testcase_20 AC 108 ms
39,592 KB
testcase_21 AC 108 ms
39,236 KB
testcase_22 AC 115 ms
39,740 KB
testcase_23 AC 108 ms
39,412 KB
testcase_24 AC 110 ms
39,460 KB
testcase_25 AC 124 ms
39,972 KB
testcase_26 AC 117 ms
40,132 KB
testcase_27 AC 119 ms
39,840 KB
testcase_28 AC 113 ms
39,300 KB
testcase_29 AC 111 ms
39,948 KB
testcase_30 AC 110 ms
39,884 KB
testcase_31 AC 112 ms
39,560 KB
testcase_32 AC 115 ms
39,324 KB
testcase_33 AC 109 ms
39,328 KB
testcase_34 AC 114 ms
39,988 KB
testcase_35 AC 118 ms
39,788 KB
testcase_36 AC 107 ms
39,536 KB
testcase_37 AC 117 ms
39,216 KB
testcase_38 AC 116 ms
39,496 KB
testcase_39 AC 121 ms
39,564 KB
testcase_40 AC 111 ms
39,264 KB
testcase_41 AC 111 ms
39,404 KB
testcase_42 AC 116 ms
39,788 KB
testcase_43 AC 109 ms
39,628 KB
testcase_44 AC 106 ms
39,824 KB
testcase_45 AC 110 ms
39,736 KB
testcase_46 AC 116 ms
39,524 KB
testcase_47 AC 110 ms
39,664 KB
testcase_48 AC 113 ms
39,224 KB
testcase_49 AC 656 ms
53,160 KB
testcase_50 AC 249 ms
45,788 KB
testcase_51 AC 225 ms
45,516 KB
testcase_52 AC 320 ms
45,468 KB
testcase_53 AC 280 ms
45,628 KB
testcase_54 AC 381 ms
46,248 KB
testcase_55 AC 173 ms
41,876 KB
testcase_56 AC 250 ms
45,608 KB
testcase_57 AC 448 ms
48,208 KB
testcase_58 AC 627 ms
54,216 KB
testcase_59 AC 546 ms
55,048 KB
testcase_60 AC 422 ms
46,568 KB
testcase_61 AC 718 ms
56,236 KB
testcase_62 AC 384 ms
46,880 KB
testcase_63 AC 620 ms
55,440 KB
testcase_64 AC 351 ms
46,488 KB
testcase_65 AC 325 ms
45,636 KB
testcase_66 AC 357 ms
46,552 KB
testcase_67 AC 366 ms
46,584 KB
testcase_68 AC 344 ms
46,536 KB
testcase_69 AC 113 ms
39,468 KB
testcase_70 AC 108 ms
39,492 KB
testcase_71 AC 115 ms
39,700 KB
testcase_72 AC 109 ms
39,236 KB
testcase_73 AC 109 ms
39,460 KB
testcase_74 AC 110 ms
39,232 KB
testcase_75 AC 109 ms
39,288 KB
testcase_76 AC 108 ms
39,496 KB
testcase_77 AC 111 ms
39,292 KB
testcase_78 AC 112 ms
39,340 KB
testcase_79 AC 111 ms
39,668 KB
testcase_80 AC 108 ms
39,284 KB
testcase_81 AC 113 ms
39,492 KB
testcase_82 AC 112 ms
39,304 KB
testcase_83 AC 110 ms
39,420 KB
testcase_84 AC 105 ms
39,272 KB
testcase_85 AC 109 ms
39,360 KB
testcase_86 AC 110 ms
39,440 KB
testcase_87 AC 112 ms
39,624 KB
testcase_88 AC 107 ms
39,812 KB
testcase_89 AC 389 ms
47,224 KB
testcase_90 AC 527 ms
53,644 KB
testcase_91 AC 667 ms
54,108 KB
testcase_92 AC 339 ms
45,676 KB
testcase_93 AC 535 ms
52,416 KB
testcase_94 AC 182 ms
42,708 KB
testcase_95 AC 568 ms
56,852 KB
testcase_96 AC 529 ms
50,788 KB
testcase_97 AC 469 ms
49,412 KB
testcase_98 AC 367 ms
46,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long m = sc.nextLong();
    ArrayList<Long> h = new ArrayList<Long>();
    long sum = 0;
    for(int i = 0; i < 1000000; i++) {
      try {
        long t = sc.nextLong();
        sum += t;
        h.add(t);
      } catch(Exception e) {
        break;
      }
    }
    long k = h.size();
    sum += (k - 1);
    long ans = 1;
    if(h.get(0) != 0) {
      if(sum > m) {
        System.out.println("NA");
      } else {
        long t = m - sum;
        long r1 = 1;
        long r2 = 1;
        for(long i = 1; i <= k; i++) {
          r1 = (r1 * (t + i)) % MOD;
          r2 = (r2 * i) % MOD;
        }
        long r3 = func(r2, MOD - 2);
        ans = (r1 * r3) % MOD;
        System.out.println(ans);
      }
    } else {
      System.out.println(1);      
    }
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if(x % 2 == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      long t = func(a, x / 2);
      t = (t * t) % MOD;
      return (a * t) % MOD;
    }
  }
}
0