結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー GrenacheGrenache
提出日時 2017-03-25 13:10:06
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,177 bytes
コンパイル時間 3,727 ms
コンパイル使用メモリ 76,912 KB
実行使用メモリ 137,236 KB
最終ジャッジ日時 2023-09-20 10:35:07
合計ジャッジ時間 12,371 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,028 KB
testcase_01 AC 124 ms
55,752 KB
testcase_02 AC 127 ms
56,100 KB
testcase_03 AC 126 ms
55,656 KB
testcase_04 AC 429 ms
136,224 KB
testcase_05 AC 126 ms
56,056 KB
testcase_06 AC 460 ms
137,236 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 511 ms
136,588 KB
testcase_10 AC 125 ms
55,904 KB
testcase_11 AC 201 ms
66,532 KB
testcase_12 AC 127 ms
55,744 KB
testcase_13 AC 149 ms
60,176 KB
testcase_14 AC 131 ms
55,904 KB
testcase_15 AC 132 ms
55,796 KB
testcase_16 AC 129 ms
56,004 KB
testcase_17 AC 132 ms
56,196 KB
testcase_18 AC 462 ms
136,728 KB
testcase_19 AC 433 ms
136,104 KB
testcase_20 AC 463 ms
137,028 KB
testcase_21 AC 431 ms
136,080 KB
testcase_22 AC 511 ms
136,672 KB
testcase_23 AC 435 ms
136,608 KB
testcase_24 AC 475 ms
136,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder498_1 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final int MOD = 1_000_000_007;

		int gx = sc.nextInt();
		int gy = sc.nextInt();
		int k = sc.nextInt();

		long[] x = new long[k];
		long[] y = new long[k];
		int[] n = new int[k];
		for (int i = 0; i < k; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			n[i] = sc.nextInt();
		}

		int si = 15 * 5;
		long[] fact = new long[si + 1];
		fact[0] = 1;
		for (int i = 1; i <= si; i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}

		long[] ifact = new long[si + 1];

		int loop = MOD - 2;
		long xxx = fact[si];
		ifact[si] = 1;
		while (loop > 0) {
			if (loop % 2 == 1) {
				ifact[si] = ifact[si] * xxx % MOD;
			}
			xxx = xxx * xxx % MOD;
			loop /= 2;
		}

		for (int i = si - 1; i >= 0; i--) {
			ifact[i] = ifact[i + 1] * (i + 1) % MOD;
		}

		long ret = 0;
		List<Long> q = new ArrayList<>();
		List<Integer> qs = new ArrayList<>();
		List<Long> ql = new ArrayList<>();
		q.add(enc(0, 0));
		qs.add(0);
		ql.add(1L);
		for (int i = 0; i < k; i++) {
			for (int j = 0, size = q.size(); j < size; j++) {
				long e = q.get(j);
				int es = qs.get(j);
				long el = ql.get(j);

				long xx = e / OFFSET - OFFSET2;
				long yy = e % OFFSET - OFFSET2;

				for (int l = 0; l < n[i]; l++) {
					long nx = xx + x[i] * (l + 1);
					long ny = yy + y[i] * (l + 1);

					q.add(enc(nx, ny));
					qs.add(es + l + 1);
					ql.add(el * ifact[l + 1] % MOD);

					if (nx == gx && ny == gy) {
						ret += el * ifact[l + 1] % MOD * fact[es + l + 1] % MOD;
						ret %= MOD;
					}
				}
			}
		}

		pr.println(ret);
	}

	static final int OFFSET = 1_000_000_000;
	static final int OFFSET2 = 100_000_000;

	private static long enc(long x, long y) {
		return (x + OFFSET2) * OFFSET + (y + OFFSET2);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0