結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー kimiyukikimiyuki
提出日時 2017-03-29 01:37:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,905 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 50,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 18:40:02
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <array>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
using ll = long long;
using namespace std;

constexpr int mod = 1e9+7;
ll powmod(ll x, ll y) { // O(log y)
    assert (0 <= x and x < mod);
    assert (0 <= y);
    ll z = 1;
    for (ll i = 1; i <= y; i <<= 1) {
        if (y & i) z = z * x % mod;
        x = x * x % mod;
    }
    return z;
}
ll inv(ll x) { // p must be a prime, O(log p)
    return powmod(x, mod-2);
}
int fact(int n) {
    static vector<int> memo(1,1);
    if (memo.size() <= n) {
        int l = memo.size();
        memo.resize(n+1);
        repeat_from (i,l,n+1) memo[i] = memo[i-1] *(ll) i % mod;
    }
    return memo[n];
}
int choose(int n, int r) { // O(n) at first time, otherwise O(\log n)
    if (n < r) return 0;
    r = min(r, n - r);
    return fact(n) *(ll) inv(fact(n-r)) % mod *(ll) inv(fact(r)) % mod;
}
int main() {
    int w, h, k; scanf("%d%d%d", &w, &h, &k);
    assert (k <= 5);
    array<int, 5> x = {};
    array<int, 5> y = {};
    array<int, 5> n = {};
    repeat (i,k) scanf("%d%d%d", &x[i], &y[i], &n[i]);
    ll acc = 0;
    array<int, 5> i;
    for (i[4] = 0; i[4] <= n[4]; ++ i[4])
    for (i[3] = 0; i[3] <= n[3]; ++ i[3])
    for (i[2] = 0; i[2] <= n[2]; ++ i[2])
    for (i[1] = 0; i[1] <= n[1]; ++ i[1])
    for (i[0] = 0; i[0] <= n[0]; ++ i[0]) {
        ll x_acc = 0;
        ll y_acc = 0;
        repeat (j,k) {
            x_acc += i[j] *(ll) x[j];
            y_acc += i[j] *(ll) y[j];
        }
        if (x_acc == w and y_acc == h) {
            ll cnt = 1;
            int i_acc = 0;
            repeat (j,k) {
                i_acc += i[j];
                cnt = cnt * choose(i_acc, i[j]) % mod;
            }
            acc += cnt;
        }
    }
    printf("%lld\n", acc);
    return 0;
}
0