結果
問題 | No.1181 Product Sum for All Subsets |
ユーザー | CuriousFairy315 |
提出日時 | 2021-03-05 03:00:48 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 7,233 bytes |
コンパイル時間 | 3,134 ms |
コンパイル使用メモリ | 84,872 KB |
実行使用メモリ | 40,840 KB |
最終ジャッジ日時 | 2024-10-05 18:27:44 |
合計ジャッジ時間 | 7,116 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
36,716 KB |
testcase_01 | AC | 55 ms
36,384 KB |
testcase_02 | AC | 59 ms
37,244 KB |
testcase_03 | AC | 69 ms
36,836 KB |
testcase_04 | RE | - |
testcase_05 | AC | 55 ms
36,888 KB |
testcase_06 | AC | 54 ms
36,536 KB |
testcase_07 | AC | 55 ms
36,860 KB |
testcase_08 | AC | 56 ms
36,824 KB |
testcase_09 | AC | 56 ms
36,944 KB |
testcase_10 | AC | 56 ms
36,700 KB |
testcase_11 | AC | 54 ms
36,544 KB |
testcase_12 | AC | 137 ms
40,240 KB |
testcase_13 | AC | 87 ms
37,736 KB |
testcase_14 | AC | 133 ms
40,208 KB |
testcase_15 | AC | 143 ms
39,844 KB |
testcase_16 | AC | 137 ms
40,284 KB |
testcase_17 | AC | 109 ms
39,048 KB |
testcase_18 | AC | 155 ms
40,288 KB |
testcase_19 | AC | 146 ms
39,784 KB |
testcase_20 | AC | 138 ms
40,444 KB |
testcase_21 | AC | 115 ms
39,312 KB |
testcase_22 | AC | 106 ms
38,944 KB |
testcase_23 | AC | 77 ms
37,548 KB |
testcase_24 | AC | 92 ms
38,132 KB |
testcase_25 | AC | 115 ms
39,168 KB |
testcase_26 | AC | 75 ms
37,128 KB |
testcase_27 | RE | - |
testcase_28 | AC | 139 ms
40,840 KB |
testcase_29 | AC | 139 ms
40,512 KB |
ソースコード
public class Main { public static void main(String[] args) { new Main(); } public Main() { FastScanner fs = new FastScanner(); java.io.PrintWriter out = new java.io.PrintWriter(System.out); solve(fs, out); out.flush(); } public void solve(FastScanner fs, java.io.PrintWriter out) { int N = fs.nextInt(); long K = fs.nextLong(); int[] fact = new int[N + 1], inv = new int[N + 1], invf = new int[N + 1]; fact[0] = fact[1] = inv[1] = invf[0] = invf[1] = 1; for (int i = 2;i <= N;++ i) { fact[i] = mul(fact[i - 1], i); inv[i] = MOD - mul(inv[MOD % i], MOD / i); invf[i] = mul(invf[i - 1], inv[i]); } int ans = 0; for (int i = 0;i < N;++ i) { int S = IntMath.pow(mul(K + 1, inv[2]), i, MOD); int T = mul(fact[N], mul(invf[N - i], invf[i])); ans = add(ans, mul(S, T)); } out.println(mul(ans, IntMath.pow((int)(K % MOD), N, MOD))); } final int MOD = 1_000_000_007; private int add(long a, long b) { int ans = (int)((a + b) % MOD); if (ans < 0) ans += MOD; return ans; } private int mul(long a, long b) { a %= MOD; b %= MOD; int ans = (int)((a * b) % MOD); if (ans < 0) ans += MOD; return ans; } } class FastScanner { private final java.io.InputStream in = System.in; private final byte[] buffer = new byte[8192]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) return true; ptr = 0; try { buflen = in.read(buffer); } catch (java.io.IOException e) { e.printStackTrace(); } return buflen > 0; } private byte readByte() { return hasNextByte() ? buffer[ptr++ ] : -1; } private static boolean isPrintableChar(byte c) { return 32 < c || c < 0; } private static boolean isNumber(int c) { return '0' <= c && c <= '9'; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++ ; return hasNextByte(); } public String next() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); byte b; while (isPrintableChar(b = readByte())) sb.appendCodePoint(b); return sb.toString(); } public final char nextChar() { if (!hasNext()) throw new java.util.NoSuchElementException(); return (char)readByte(); } public final long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; try { byte b = readByte(); if (b == '-') { while (isNumber(b = readByte())) n = n * 10 + '0' - b; return n; } else if (!isNumber(b)) throw new NumberFormatException(); do n = n * 10 + b - '0'; while (isNumber(b = readByte())); } catch (java.util.NoSuchElementException e) {} return n; } public final int nextInt() { if (!hasNext()) throw new java.util.NoSuchElementException(); int n = 0; try { byte b = readByte(); if (b == '-') { while (isNumber(b = readByte())) n = n * 10 + '0' - b; return n; } else if (!isNumber(b)) throw new NumberFormatException(); do n = n * 10 + b - '0'; while (isNumber(b = readByte())); } catch (java.util.NoSuchElementException e) {} return n; } public double nextDouble() { return Double.parseDouble(next()); } } class Arrays { public static void sort(final int[] array) { int l, min = 0xFFFFFFFF, max = 0; for (l = 0; l < array.length; ++l) { int i = array[l]; min &= i; max |= i; if ((i & 0x80000000) == 0) break; } for (int r = l + 1; r < array.length; ++r) { int i = array[r]; min &= i; max |= i; if ((i & 0x80000000) != 0) { array[r] = array[l]; array[l++ ] = i; } } int use = min ^ max, bit = Integer.highestOneBit(use & 0x7FFFFFFF); if (bit == 0) return; sort(array, 0, l, use, bit); sort(array, l, array.length, use, bit); } private static void sort(final int[] array, final int left, final int right, final int use, int digit) { if (right - left <= 96) { for (int i = left + 1; i < right; ++i) { int tmp = array[i], tmp2, j; for (j = i; j > left && (tmp2 = array[j - 1]) > tmp; --j) array[j] = tmp2; array[j] = tmp; } return; } int l = left; while (l < right && (array[l] & digit) == 0) ++l; for (int r = l + 1; r < right; ++r) { int i = array[r]; if ((i & digit) == 0) { array[r] = array[l]; array[l++ ] = i; } } if ((digit = Integer.highestOneBit(use & digit - 1)) == 0) return; sort(array, left, l, use, digit); sort(array, l, right, use, digit); } public static void sort(final long[] array) { int l; long min = 0xFFFFFFFFFFFFFFFFL, max = 0; for (l = 0; l < array.length; ++l) { long i = array[l]; min &= i; max |= i; if ((i & 0x8000000000000000L) == 0) break; } for (int r = l + 1; r < array.length; ++r) { long i = array[r]; min &= i; max |= i; if ((i & 0x8000000000000000L) != 0) { array[r] = array[l]; array[l++ ] = i; } } long use = min ^ max, bit = Long.highestOneBit(use & 0x7FFFFFFFFFFFFFFFL); if (bit == 0) return; sort(array, 0, l, use, bit); sort(array, l, array.length, use, bit); } private static void sort(final long[] array, final int left, final int right, final long use, long digit) { if (right - left <= 96) { for (int i = left + 1, j; i < right; ++i) { long tmp = array[i], tmp2; for (j = i; j > left && (tmp2 = array[j - 1]) > tmp; --j) array[j] = tmp2; array[j] = tmp; } return; } int l = left; while (l < right && (array[l] & digit) == 0) ++l; for (int r = l + 1; r < right; ++r) { long i = array[r]; if ((i & digit) == 0) { array[r] = array[l]; array[l++ ] = i; } } if ((digit = Long.highestOneBit(use & digit - 1)) == 0) return; sort(array, left, l, use, digit); sort(array, l, right, use, digit); } } class IntMath { public static int gcd(int a, int b) { while (a != 0) if ((b %= a) != 0) a %= b; else return a; return b; } public static int gcd(int... array) { int ret = array[0]; for (int i = 1; i < array.length; ++i) ret = gcd(ret, array[i]); return ret; } public static long gcd(long a, long b) { while (a != 0) if ((b %= a) != 0) a %= b; else return a; return b; } public static long gcd(long... array) { long ret = array[0]; for (int i = 1; i < array.length; ++i) ret = gcd(ret, array[i]); return ret; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static int pow(int a, int b) { int ans = 1; for (int mul = a; b > 0; b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul; return ans; } public static long pow(long a, long b) { long ans = 1; for (long mul = a; b > 0; b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul; return ans; } public static int pow(int a, long b, int mod) { if (b < 0) b = b % (mod - 1) + mod - 1; long ans = 1; for (long mul = a; b > 0; b >>= 1, mul = mul * mul % mod) if ((b & 1) != 0) ans = ans * mul % mod; return (int)ans; } public static int pow(long a, long b, int mod) { return pow((int)(a % mod), b, mod); } public static int floorsqrt(long n) { return (int)Math.sqrt(n + 0.1); } public static int ceilsqrt(long n) { return n <= 1 ? (int)n : (int)Math.sqrt(n - 0.1) + 1; } }