結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー | zimpha |
提出日時 | 2017-03-25 18:33:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 3,555 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 77,888 KB |
実行使用メモリ | 55,820 KB |
最終ジャッジ日時 | 2024-07-06 06:06:20 |
合計ジャッジ時間 | 5,125 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
50,256 KB |
testcase_01 | AC | 47 ms
49,988 KB |
testcase_02 | AC | 50 ms
50,288 KB |
testcase_03 | AC | 48 ms
50,272 KB |
testcase_04 | AC | 135 ms
54,748 KB |
testcase_05 | AC | 51 ms
50,192 KB |
testcase_06 | AC | 159 ms
55,612 KB |
testcase_07 | AC | 170 ms
55,660 KB |
testcase_08 | AC | 142 ms
55,544 KB |
testcase_09 | AC | 147 ms
54,940 KB |
testcase_10 | AC | 50 ms
50,536 KB |
testcase_11 | AC | 93 ms
54,900 KB |
testcase_12 | AC | 50 ms
50,248 KB |
testcase_13 | AC | 60 ms
50,856 KB |
testcase_14 | AC | 48 ms
50,248 KB |
testcase_15 | AC | 48 ms
50,336 KB |
testcase_16 | AC | 48 ms
49,960 KB |
testcase_17 | AC | 48 ms
50,420 KB |
testcase_18 | AC | 163 ms
55,820 KB |
testcase_19 | AC | 146 ms
55,780 KB |
testcase_20 | AC | 145 ms
55,184 KB |
testcase_21 | AC | 159 ms
55,728 KB |
testcase_22 | AC | 142 ms
54,664 KB |
testcase_23 | AC | 172 ms
55,652 KB |
testcase_24 | AC | 163 ms
55,728 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Chiaki.Hoshinomori */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task498 solver = new Task498(); solver.solve(1, in, out); out.close(); } static class Task498 { final static int mod = 1000000000 + 7; public void solve(int testNumber, InputReader in, PrintWriter out) { int Gx = in.nextInt(); int Gy = in.nextInt(); int K = in.nextInt(); int[] x = new int[K]; int[] y = new int[K]; int[] n = new int[K]; int total = 1; for (int i = 0; i < K; i++) { x[i] = in.nextInt(); y[i] = in.nextInt(); n[i] = in.nextInt(); total *= n[i] + 1; } long[] fac = new long[100]; long[] inv = new long[100]; fac[0] = inv[0] = 1; for (int i = 1; i < 100; i++) { fac[i] = i * fac[i - 1] % mod; inv[i] = MathUtils.pow_mod(fac[i], mod - 2, mod); } long ret = 0; for (int mask = 0; mask < total; ++mask) { int[] cnt = new int[K]; int m = mask; int sx = 0; int sy = 0; for (int i = 0; i < K; i++) { cnt[i] = m % (n[i] + 1); m /= (n[i] + 1); sx += x[i] * cnt[i]; sy += y[i] * cnt[i]; } if (sx == Gx && sy == Gy) { int sum = 0; long mul = 1; for (int i = 0; i < K; ++i) { sum += cnt[i]; mul = mul * inv[cnt[i]] % mod; } mul = mul * fac[sum] % mod; ret += mul; } } out.println(ret % mod); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class MathUtils { public static long pow_mod(long a, long n, long mod) { long result = 1; for (; n >= 1; n >>= 1) { if (n % 2 == 1) result = result * a % mod; a = a * a % mod; } return result; } } }