結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー GrenacheGrenache
提出日時 2017-03-25 12:38:08
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,374 bytes
コンパイル時間 4,801 ms
コンパイル使用メモリ 76,604 KB
実行使用メモリ 210,592 KB
最終ジャッジ日時 2023-09-20 10:34:10
合計ジャッジ時間 17,509 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,824 KB
testcase_01 AC 127 ms
55,560 KB
testcase_02 AC 128 ms
55,680 KB
testcase_03 AC 128 ms
56,064 KB
testcase_04 AC 757 ms
205,408 KB
testcase_05 AC 132 ms
55,848 KB
testcase_06 AC 836 ms
207,728 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 747 ms
207,516 KB
testcase_10 AC 128 ms
54,192 KB
testcase_11 AC 251 ms
69,588 KB
testcase_12 AC 129 ms
55,824 KB
testcase_13 AC 160 ms
60,400 KB
testcase_14 AC 130 ms
55,796 KB
testcase_15 AC 141 ms
56,128 KB
testcase_16 AC 134 ms
55,680 KB
testcase_17 AC 139 ms
56,008 KB
testcase_18 AC 814 ms
207,528 KB
testcase_19 AC 750 ms
207,112 KB
testcase_20 AC 932 ms
208,724 KB
testcase_21 AC 759 ms
207,280 KB
testcase_22 AC 746 ms
207,040 KB
testcase_23 AC 742 ms
207,028 KB
testcase_24 AC 830 ms
210,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder498 {

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

		List<List<Integer>> ans = new ArrayList<>();
		List<Long> q = new ArrayList<>();
		List<List<Integer>> ql = new ArrayList<>();
		q.add(enc(0, 0));
		ql.add(new ArrayList<>());
		for (int i = 0; i < k; i++) {
			for (int j = 0, size = q.size(); j < size; j++) {
				long e = q.get(j);
				List<Integer> 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);

					List<Integer> tmpl = new ArrayList<>(el);
					tmpl.add(l + 1);
					q.add(enc(nx, ny));
					ql.add(tmpl);

					if (nx == gx && ny == gy) {
						ans.add(tmpl);
					}
				}
			}
		}

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

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

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

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

		long ret = 0;
		for (List<Integer> e : ans) {
			long tmp = 1;
			int sum = 0;
			for (int ee : e) {
				sum += ee;
				tmp *= ifact[ee];
				tmp %= MOD;
			}

			tmp *= fact[sum];
			tmp %= MOD;

			ret += tmp;
			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