結果

問題 No.1683 Robot Guidance
ユーザー ぷらぷら
提出日時 2021-09-17 22:39:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 200,316 KB
実行使用メモリ 50,504 KB
最終ジャッジ日時 2023-09-12 08:39:11
合計ジャッジ時間 6,482 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
50,240 KB
testcase_01 AC 60 ms
50,444 KB
testcase_02 AC 63 ms
50,192 KB
testcase_03 AC 65 ms
50,292 KB
testcase_04 AC 66 ms
50,212 KB
testcase_05 AC 66 ms
50,296 KB
testcase_06 AC 70 ms
50,208 KB
testcase_07 AC 69 ms
50,256 KB
testcase_08 AC 81 ms
50,236 KB
testcase_09 AC 65 ms
50,208 KB
testcase_10 AC 70 ms
50,172 KB
testcase_11 AC 73 ms
50,156 KB
testcase_12 AC 75 ms
50,268 KB
testcase_13 AC 61 ms
50,244 KB
testcase_14 AC 70 ms
50,204 KB
testcase_15 AC 63 ms
50,164 KB
testcase_16 AC 65 ms
50,212 KB
testcase_17 AC 63 ms
50,296 KB
testcase_18 AC 63 ms
50,192 KB
testcase_19 AC 65 ms
50,324 KB
testcase_20 AC 65 ms
50,464 KB
testcase_21 AC 63 ms
50,152 KB
testcase_22 AC 65 ms
50,272 KB
testcase_23 AC 64 ms
50,332 KB
testcase_24 AC 82 ms
50,248 KB
testcase_25 AC 67 ms
50,212 KB
testcase_26 AC 68 ms
50,152 KB
testcase_27 AC 68 ms
50,188 KB
testcase_28 AC 68 ms
50,252 KB
testcase_29 AC 70 ms
50,324 KB
testcase_30 AC 69 ms
50,148 KB
testcase_31 AC 71 ms
50,208 KB
testcase_32 AC 70 ms
50,328 KB
testcase_33 AC 72 ms
50,452 KB
testcase_34 AC 76 ms
50,420 KB
testcase_35 AC 74 ms
50,188 KB
testcase_36 AC 71 ms
50,504 KB
testcase_37 AC 73 ms
50,240 KB
testcase_38 AC 71 ms
50,232 KB
testcase_39 AC 69 ms
50,192 KB
testcase_40 AC 70 ms
50,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 1000000007;

long long fac[2000005], finv[2000005], inv[2000005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 2000005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k) {
    if (n-k <= 0) return 1;
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    int A,B,X,Y;
    cin >> A >> B >> X >> Y;
    COMinit();
    long long ans = 0;
    int a = 1+B/4;
    int b = min(1,B)+(B-1)/4;
    int c = min(1,B-1)+(B-2)/4;
    int d = min(1,B-2)+(B-3)/4;
    if(A-abs(X)-abs(Y) < 0 || (A-abs(X)-abs(Y))%2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    for(int i = abs(X); i+abs(Y) <= A; i += 2) {
        int e = (i-abs(X))/2,f = i-e;
        long long tmp = 1;
        if(X >= 0) {
            tmp *= COM(a+f-1,a-1);
            tmp *= COM(c+e-1,c-1);
            tmp %= mod;
        }
        else {
            tmp *= COM(c+f-1,c-1);
            tmp *= COM(a+e-1,a-1);
            tmp %= mod;
        }
        e = ((A-i)-abs(Y))/2,f = (A-i)-e;
        if(Y >= 0) {
            tmp *= COM(b+f-1,b-1);
            tmp %= mod;
            tmp *= COM(d+e-1,d-1);
            tmp %= mod;
        }
        else {
            tmp *= COM(d+f-1,d-1);
            tmp %= mod;
            tmp *= COM(b+e-1,b-1);
            tmp %= mod;
        }
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;
}
0