結果
問題 | No.391 CODING WAR |
ユーザー | ぴろず |
提出日時 | 2016-07-08 22:45:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 206 ms / 2,000 ms |
コード長 | 1,775 bytes |
コンパイル時間 | 2,193 ms |
コンパイル使用メモリ | 76,792 KB |
実行使用メモリ | 43,540 KB |
最終ジャッジ日時 | 2024-04-21 07:27:01 |
合計ジャッジ時間 | 6,477 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 111 ms
40,264 KB |
testcase_01 | AC | 109 ms
40,032 KB |
testcase_02 | AC | 119 ms
41,364 KB |
testcase_03 | AC | 116 ms
41,172 KB |
testcase_04 | AC | 106 ms
39,900 KB |
testcase_05 | AC | 114 ms
41,208 KB |
testcase_06 | AC | 104 ms
40,036 KB |
testcase_07 | AC | 119 ms
41,576 KB |
testcase_08 | AC | 117 ms
41,780 KB |
testcase_09 | AC | 203 ms
42,592 KB |
testcase_10 | AC | 206 ms
42,708 KB |
testcase_11 | AC | 107 ms
40,408 KB |
testcase_12 | AC | 116 ms
41,136 KB |
testcase_13 | AC | 193 ms
42,404 KB |
testcase_14 | AC | 182 ms
41,828 KB |
testcase_15 | AC | 205 ms
43,540 KB |
testcase_16 | AC | 164 ms
42,208 KB |
testcase_17 | AC | 187 ms
42,832 KB |
testcase_18 | AC | 160 ms
42,280 KB |
testcase_19 | AC | 158 ms
42,324 KB |
ソースコード
package no391; import java.util.Scanner; public class Main { /* * 問題への割り当てf(x) * 異なる全射の数え上げ * ググった * http://mathtrain.jp/zensya */ public static long MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int m = sc.nextInt(); if (n < m) { System.out.println(0); return; // throw new RuntimeException("反則"); } long ans = 0; long[] fact = Mod.factorialArray(m+1, MOD); long[] factInv = Mod.factorialInverseArray(m+1, MOD, Mod.inverseArray(m+1, MOD)); for(int i=1;i<=m;i++) { long x = fact[m] * factInv[i] % MOD * factInv[m-i] % MOD * Mod.pow(i, n, MOD); ans = Mod.n(ans + ((m - i) % 2 == 0 ? 1 : -1) * x, MOD); } System.out.println(ans); } } class Mod { public static long n(long x,long mod) { x %= mod; if (x < 0) { x += mod; } return x; } public static long pow(long a,long n,long mod) { long res = 1; while(n > 0) { if ((n & 1) > 0) { res = (res * a) % mod; } a = (a * a) % mod; n/=2; } return res; } public static long[] inverseArray(int maxN,long modP) { long[] inv = new long[maxN+1]; inv[1] = 1; for(int i=2;i<=maxN;i++) { inv[i] = modP - (modP / i) * inv[(int) (modP%i)] % modP; } return inv; } public static long[] factorialArray(int maxN,long mod) { long[] fact = new long[maxN+1]; fact[0] = 1 % mod; for(int i=1;i<=maxN;i++) { fact[i] = fact[i-1] * i % mod; } return fact; } public static long[] factorialInverseArray(int maxN,long modP,long[] inverseArray) { long[] factInv = new long[maxN+1]; factInv[0] = 1; for(int i=1;i<=maxN;i++) { factInv[i] = factInv[i-1] * inverseArray[i] % modP; } return factInv; } }