結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー GrenacheGrenache
提出日時 2017-03-25 13:14:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 2,338 bytes
コンパイル時間 4,133 ms
コンパイル使用メモリ 76,252 KB
実行使用メモリ 138,692 KB
最終ジャッジ日時 2023-09-20 10:35:20
合計ジャッジ時間 11,480 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,668 KB
testcase_01 AC 120 ms
56,244 KB
testcase_02 AC 121 ms
55,800 KB
testcase_03 AC 119 ms
56,192 KB
testcase_04 AC 426 ms
137,024 KB
testcase_05 AC 122 ms
55,952 KB
testcase_06 AC 426 ms
137,100 KB
testcase_07 AC 428 ms
138,692 KB
testcase_08 AC 426 ms
136,960 KB
testcase_09 AC 429 ms
136,912 KB
testcase_10 AC 120 ms
56,072 KB
testcase_11 AC 219 ms
64,988 KB
testcase_12 AC 118 ms
56,048 KB
testcase_13 AC 153 ms
60,720 KB
testcase_14 AC 120 ms
55,828 KB
testcase_15 AC 124 ms
56,424 KB
testcase_16 AC 120 ms
56,504 KB
testcase_17 AC 126 ms
54,384 KB
testcase_18 AC 423 ms
136,740 KB
testcase_19 AC 422 ms
135,656 KB
testcase_20 AC 427 ms
136,804 KB
testcase_21 AC 430 ms
134,872 KB
testcase_22 AC 430 ms
136,924 KB
testcase_23 AC 428 ms
136,680 KB
testcase_24 AC 436 ms
136,624 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;
		}

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

				}
			}
		}

		long ret = 0;
		for (int i = 0, size = q.size(); i < size; i++) {
			long e = q.get(i);
			int es = qs.get(i);
			long el = ql.get(i);

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

			if (xx == gx && yy == gy) {
				ret += el * fact[es] % 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