結果

問題 No.1683 Robot Guidance
ユーザー 259_Momone
提出日時 2021-09-17 22:05:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 203,776 KB
最終ジャッジ日時 2025-01-24 15:00:06
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>

int main(){
    using namespace std;
    using modint = atcoder::static_modint<1000000007>;
    const auto [A, D0, D1, D2, D3]{[]{
        unsigned long a, b;
        cin >> a >> b;
        return make_tuple(a, (b + 4) / 4, (b + 3) / 4, (b + 2) / 4, (b + 1) / 4);
    }()};
    const auto [G0, G1, G2, G3]{[]{
        long X, Y;
        cin >> X >> Y;
        return tuple<unsigned long, unsigned long, unsigned long, unsigned long>{X > 0 ? X : 0, Y > 0 ? Y : 0, X < 0 ? -X : 0, Y < 0 ? -Y : 0};
    }()};
    if(((G0 ^ G1 ^ G2 ^ G3 ^ A) & 1) || (A < G0 + G1 + G2 + G3)){
        cout << '0' << endl;
        return 0;
    }
    
    const auto S{(A - G0 - G1 - G2 - G3) / 2};
    const auto N{max({D0 + G0, D1 + G1, D2 + G2, D3 + G3}) + S};

    vector<modint> fact{1};
    fact.reserve(N + 1);
    for(unsigned long i{1}; i <= N; ++i)fact.emplace_back(fact.back() * modint::raw(i));
    vector<modint> ifact{fact.back().inv()};
    ifact.reserve(N + 1);
    for(unsigned long i{N}; i; --i)ifact.emplace_back(ifact.back() * modint::raw(i));
    reverse(begin(ifact), end(ifact));

    modint ans{};
    const auto query{[&fact, &ifact](unsigned long x, unsigned long y){
        return x ? fact[x + y - 1] * ifact[y] * ifact[x - 1] : modint::raw(!y);
    }};
    for(unsigned long i{}; i <= S; ++i)ans += query(D0, G0 + i) * query(D1, G1 + S - i) * query(D2, G2 + i) * query(D3, G3 + S - i);
    cout << ans.val() << endl;
    return 0;
}
0