結果
| 問題 |
No.498 ワープクリスタル (給料日編)
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2017-03-24 23:46:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,659 bytes |
| コンパイル時間 | 2,295 ms |
| コンパイル使用メモリ | 79,116 KB |
| 実行使用メモリ | 56,868 KB |
| 最終ジャッジ日時 | 2024-07-06 01:42:12 |
| 合計ジャッジ時間 | 7,487 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 WA * 2 |
ソースコード
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();
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);
}
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));
}
}
uafr_cs