結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー zimphazimpha
提出日時 2017-03-25 18:33:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 3,555 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 74,404 KB
実行使用メモリ 55,768 KB
最終ジャッジ日時 2023-09-20 10:38:54
合計ジャッジ時間 5,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,396 KB
testcase_01 AC 45 ms
49,460 KB
testcase_02 AC 45 ms
49,384 KB
testcase_03 AC 46 ms
49,360 KB
testcase_04 AC 139 ms
54,680 KB
testcase_05 AC 45 ms
49,416 KB
testcase_06 AC 158 ms
55,528 KB
testcase_07 AC 186 ms
55,612 KB
testcase_08 AC 154 ms
55,532 KB
testcase_09 AC 150 ms
55,388 KB
testcase_10 AC 45 ms
47,456 KB
testcase_11 AC 83 ms
54,680 KB
testcase_12 AC 45 ms
49,824 KB
testcase_13 AC 55 ms
50,488 KB
testcase_14 AC 44 ms
49,608 KB
testcase_15 AC 45 ms
50,008 KB
testcase_16 AC 45 ms
49,576 KB
testcase_17 AC 50 ms
49,576 KB
testcase_18 AC 165 ms
55,480 KB
testcase_19 AC 155 ms
55,404 KB
testcase_20 AC 152 ms
55,144 KB
testcase_21 AC 162 ms
55,768 KB
testcase_22 AC 159 ms
55,528 KB
testcase_23 AC 168 ms
55,472 KB
testcase_24 AC 159 ms
54,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }

    }
}

0