結果
問題 | No.391 CODING WAR |
ユーザー | ぴろず |
提出日時 | 2016-07-08 22:44:26 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,736 bytes |
コンパイル時間 | 2,208 ms |
コンパイル使用メモリ | 76,816 KB |
実行使用メモリ | 43,560 KB |
最終ジャッジ日時 | 2024-04-21 07:26:27 |
合計ジャッジ時間 | 6,695 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
40,820 KB |
testcase_01 | AC | 139 ms
41,212 KB |
testcase_02 | AC | 133 ms
41,000 KB |
testcase_03 | AC | 121 ms
39,784 KB |
testcase_04 | AC | 136 ms
41,136 KB |
testcase_05 | RE | - |
testcase_06 | AC | 130 ms
40,828 KB |
testcase_07 | AC | 141 ms
41,236 KB |
testcase_08 | AC | 136 ms
41,020 KB |
testcase_09 | AC | 232 ms
43,560 KB |
testcase_10 | AC | 218 ms
42,288 KB |
testcase_11 | RE | - |
testcase_12 | AC | 138 ms
40,936 KB |
testcase_13 | AC | 224 ms
43,164 KB |
testcase_14 | AC | 198 ms
41,556 KB |
testcase_15 | AC | 225 ms
43,220 KB |
testcase_16 | AC | 194 ms
42,176 KB |
testcase_17 | AC | 210 ms
42,544 KB |
testcase_18 | AC | 176 ms
41,748 KB |
testcase_19 | AC | 163 ms
40,844 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) { 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; } }