結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー uafr_csuafr_cs
提出日時 2017-03-24 23:54:08
言語 Java19
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,711 bytes
コンパイル時間 4,062 ms
コンパイル使用メモリ 75,692 KB
実行使用メモリ 56,872 KB
最終ジャッジ日時 2023-09-20 05:44:24
合計ジャッジ時間 9,277 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
55,732 KB
testcase_01 AC 128 ms
55,512 KB
testcase_02 AC 131 ms
55,868 KB
testcase_03 AC 130 ms
55,880 KB
testcase_04 AC 153 ms
55,476 KB
testcase_05 AC 128 ms
55,660 KB
testcase_06 AC 159 ms
53,876 KB
testcase_07 AC 173 ms
56,240 KB
testcase_08 AC 182 ms
56,636 KB
testcase_09 AC 151 ms
55,620 KB
testcase_10 AC 128 ms
56,040 KB
testcase_11 AC 151 ms
56,552 KB
testcase_12 AC 130 ms
55,756 KB
testcase_13 AC 149 ms
56,444 KB
testcase_14 AC 131 ms
55,624 KB
testcase_15 AC 132 ms
55,712 KB
testcase_16 AC 132 ms
55,432 KB
testcase_17 AC 131 ms
55,708 KB
testcase_18 AC 190 ms
56,416 KB
testcase_19 AC 179 ms
56,388 KB
testcase_20 AC 179 ms
56,616 KB
testcase_21 AC 176 ms
56,864 KB
testcase_22 AC 164 ms
56,420 KB
testcase_23 AC 190 ms
56,872 KB
testcase_24 AC 190 ms
56,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static final long MOD = 1000000007;
	
	public static long mod_pow(long a, long e, long m){
		if(e == 0){
			return 1;
		}else if(e % 2 == 0){
			long ret = mod_pow(a, e / 2, m);
			return (ret * ret) % m;
		}else{
			return (mod_pow(a, e - 1, m) * a) % m;
		}
	}
	
	public static long mod_inv(long a, long p){
		return mod_pow(a, p - 2, p);
	}
	
	public static long dfs(int deep, int limit, int[] using, int[] xs, int[] ys, int[] ns, int gx, int gy, long x, long y){
		if(deep >= limit){
			if(gx == x && gy == y){
				final int use_sum = Arrays.stream(using).sum();
				//if(use_sum == 0){ return 0; }
				long upper = 1;
				
				for(int i = 1; i <= use_sum; i++){
					upper *= i;
					upper %= MOD;
				}
				
				long lower = 1;
				for(int part = 0; part < limit; part++){
					for(int i = 1; i <= using[part]; i++){
						lower *= i;
						lower %= MOD;
					}
				}
				
				return (upper * mod_inv(lower, MOD)) % MOD;
			}else{
				return 0;
			}
		}else{
			long ret = 0;
			for(int i = 0; i <= ns[deep]; i++){
				using[deep] = i;
				ret += dfs(deep + 1, limit, using, xs, ys, ns, gx, gy, x + xs[deep] * i, y + ys[deep] * i);
				ret %= MOD;
			}
			
			return ret;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int gx = sc.nextInt();
		final int gy = sc.nextInt();
		final int K = sc.nextInt();
		
		int[] xs = new int[K];
		int[] ys = new int[K];
		int[] ns = new int[K];
		for(int i = 0; i < K; i++){
			xs[i] = sc.nextInt();
			ys[i] = sc.nextInt();
			ns[i] = sc.nextInt();
		}
		
		System.out.println(dfs(0, K, new int[K], xs, ys, ns, gx, gy, 0, 0));
		
	}
}
0