結果

問題 No.1683 Robot Guidance
ユーザー packer_jppacker_jp
提出日時 2021-09-17 22:15:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 9,627 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 205,972 KB
実行使用メモリ 97,088 KB
最終ジャッジ日時 2024-06-29 20:50:14
合計ジャッジ時間 12,565 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
96,944 KB
testcase_01 AC 216 ms
96,924 KB
testcase_02 AC 222 ms
97,084 KB
testcase_03 AC 214 ms
96,992 KB
testcase_04 AC 209 ms
96,912 KB
testcase_05 AC 221 ms
97,012 KB
testcase_06 AC 222 ms
96,988 KB
testcase_07 AC 230 ms
96,988 KB
testcase_08 AC 255 ms
96,944 KB
testcase_09 AC 219 ms
96,920 KB
testcase_10 AC 231 ms
96,988 KB
testcase_11 AC 233 ms
96,936 KB
testcase_12 AC 258 ms
96,820 KB
testcase_13 AC 215 ms
96,972 KB
testcase_14 AC 255 ms
96,992 KB
testcase_15 AC 228 ms
96,936 KB
testcase_16 AC 221 ms
96,992 KB
testcase_17 AC 216 ms
97,008 KB
testcase_18 AC 225 ms
96,908 KB
testcase_19 AC 236 ms
96,888 KB
testcase_20 AC 228 ms
96,908 KB
testcase_21 AC 232 ms
96,932 KB
testcase_22 AC 211 ms
96,928 KB
testcase_23 AC 226 ms
96,936 KB
testcase_24 AC 245 ms
97,088 KB
testcase_25 AC 235 ms
96,992 KB
testcase_26 AC 211 ms
96,912 KB
testcase_27 AC 225 ms
96,992 KB
testcase_28 AC 216 ms
97,016 KB
testcase_29 AC 219 ms
96,908 KB
testcase_30 AC 207 ms
96,928 KB
testcase_31 AC 224 ms
97,012 KB
testcase_32 AC 217 ms
96,820 KB
testcase_33 AC 215 ms
97,048 KB
testcase_34 AC 217 ms
96,924 KB
testcase_35 AC 208 ms
97,080 KB
testcase_36 AC 223 ms
96,996 KB
testcase_37 AC 197 ms
96,928 KB
testcase_38 AC 204 ms
96,988 KB
testcase_39 AC 212 ms
96,884 KB
testcase_40 AC 209 ms
96,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define SZ(x) ((int)(x).size())
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define vsum(x) reduce(all(x))
#define vmax(a) *max_element(all(a))
#define vmin(a) *min_element(all(a))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define mp make_pair
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vc = vector<char>;
using VVi = vector<vector<int>>;
using VVl = vector<vector<ll>>;
using VVc = vector<vector<char>>;
constexpr ll inf = 1000000000ll;
constexpr ll INF = 4000000004000000000LL;
constexpr ld eps = 1e-15;
constexpr ld PI = 3.141592653589793;
constexpr int popcnt(ull x) { return __builtin_popcountll(x); }
template <typename T> using mat = vector<vector<T>>;
constexpr ll dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr ll dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
constexpr ll sign(ll a) { return (a > 0) - (a < 0); }
constexpr ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
constexpr ll cdiv(ll a, ll b) { return -fdiv(-a, b); }
constexpr ull bit(int n) { return 1ull << n; }
template <typename T> constexpr T mypow(T x, ll n) {
    T ret = 1;
    while (n) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}
constexpr ll modpow(ll x, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
        x %= mod;
        ret %= mod;
    }
    return ret;
}
template <typename T> T xor64(T lb, T ub) {
    static ull x = 88172645463325252ull;
    x ^= x << 7;
    return lb + (x ^= x >> 9) % (ub - lb);
}
constexpr ll safemod(ll x, ll mod) { return (x % mod + mod) % mod; }
template <typename T> constexpr T sq(const T &a) { return a * a; }
template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename U> bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <typename T, typename U> bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template <typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) {
    os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T> void print(const T &a) { cout << a << endl; }
template <typename T> void print(const vector<T> &v) {
    for (auto &e : v) cout << e << " ";
    cout << endl;
}
template <typename T> void scan(vector<T> &a) {
    for (auto &i : a) cin >> i;
}
struct timer {
    clock_t start_time;
    void start() { start_time = clock(); }
    int lap() {
        // return x ms.
        return (clock() - start_time) * 1000 / CLOCKS_PER_SEC;
    }
};
template <typename T = int> struct Edge {
    int from, to;
    T cost;
    int idx;

    Edge() = default;

    Edge(int from, int to, T cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {}

    operator int() const { return to; }
};
template <typename T = int> struct Graph {
    vector<vector<Edge<T>>> g;
    int es;

    Graph() = default;

    explicit Graph(int n) : g(n), es(0) {}

    size_t size() const { return g.size(); }

    void add_directed_edge(int from, int to, T cost = 1) { g[from].emplace_back(from, to, cost, es++); }

    void add_edge(int from, int to, T cost = 1) {
        g[from].emplace_back(from, to, cost, es);
        g[to].emplace_back(to, from, cost, es++);
    }

    void read(int M, int padding = -1, bool weighted = false, bool directed = false) {
        for (int i = 0; i < M; i++) {
            int a, b;
            cin >> a >> b;
            a += padding;
            b += padding;
            T c = T(1);
            if (weighted) cin >> c;
            if (directed)
                add_directed_edge(a, b, c);
            else
                add_edge(a, b, c);
        }
    }
};
#ifdef ONLINE_JUDGE
#define dump(...) (void(0))
#else
void debug() { cerr << endl; }
template <typename Head, typename... Tail> void debug(Head &&head, Tail &&... tail) {
    cerr << head;
    if (sizeof...(Tail)) cerr << ", ";
    debug(tail...);
}
#define dump(...) cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ", debug(__VA_ARGS__)
#endif
struct rep {
    struct itr {
        ll v;
        itr(ll v) : v(v) {}
        void operator++() { ++v; }
        ll operator*() const { return v; }
        bool operator!=(itr i) const { return v < *i; }
    };
    ll l, r;
    rep(ll l, ll r) : l(l), r(r) {}
    rep(ll r) : rep(0, r) {}
    itr begin() const { return l; };
    itr end() const { return r; };
};
struct per {
    struct itr {
        ll v;
        itr(ll v) : v(v) {}
        void operator++() { --v; }
        ll operator*() const { return v; }
        bool operator!=(itr i) const { return v > *i; }
    };
    ll l, r;
    per(ll l, ll r) : l(l), r(r) {}
    per(ll r) : per(0, r) {}
    itr begin() const { return r - 1; };
    itr end() const { return l - 1; };
};
struct io_setup {
    static constexpr int PREC = 20;
    io_setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} iOS;
template <ll MOD = 1000000007> struct modint {
    ll val;
    modint(ll val = 0) : val(val >= 0 ? val % MOD : (MOD - (-val) % MOD) % MOD) {}
    static ll mod() { return MOD; }
    modint inv() const {
        ll a = val, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return modint(u);
    }
    modint pow(ll k) const {
        modint ret = 1, mul = val;
        while (k) {
            if (k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    modint &operator+=(const modint &a) {
        if ((val += a.val) >= MOD) val -= MOD;
        return *this;
    }
    modint &operator-=(const modint &a) {
        if ((val += MOD - a.val) >= MOD) val -= MOD;
        return *this;
    }
    modint &operator*=(const modint &a) {
        (val *= a.val) %= MOD;
        return *this;
    }
    modint &operator/=(const modint &a) { return *this *= a.inv(); }
    bool operator==(const modint &a) const { return val == a.val; }
    bool operator!=(const modint &a) const { return rel_ops::operator!=(*this, a); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint(-val); }
    friend modint operator+(const modint &a, const modint &b) { return modint(a) += b; }
    friend modint operator-(const modint &a, const modint &b) { return modint(a) -= b; }
    friend modint operator*(const modint &a, const modint &b) { return modint(a) *= b; }
    friend modint operator/(const modint &a, const modint &b) { return modint(a) /= b; }
    friend istream &operator>>(istream &is, modint &a) {
        ll val;
        is >> val;
        a = modint(val);
        return is;
    }
    friend ostream &operator<<(ostream &os, const modint &a) { return os << a.val; }
};
using mint = modint<>;

template <typename mint> struct combination {
    vector<mint> fact, finv, inv;
    combination(int n) : fact(n + 1), finv(n + 1), inv(n + 1) {
        fact[0] = fact[1] = finv[0] = finv[1] = inv[1] = 1;
        for (int i : rep(2, n + 1)) {
            fact[i] = fact[i - 1] * i;
            inv[i] = -inv[mint::mod() % i] * (mint::mod() / i);
            finv[i] = finv[i - 1] * inv[i];
        }
    }
    mint P(int n, int r) { return r < 0 || n < r ? 0 : (fact[n] * finv[n - r]); }
    mint C(int n, int r) { return P(n, r) * finv[r]; }
    mint H(int n, int r) { return n == 0 && r == 0 ? 1 : C(n + r - 1, r); }
    mint catalan(int n) { return C(2 * n, n) / (n + 1); }
};

int main() {
    ll a, b, x, y;
    cin >> a >> b >> x >> y;
    combination<mint> comb(4000000);
    mint ans = 0;
    for (ll i : rep(a + 1)) {
        ll j = a - i;
        if ((i ^ x) & 1) continue;
        if ((j ^ y) & 1) continue;
        ll n0 = (i + x) / 2, n1 = (j + y) / 2, n2 = (i - x) / 2, n3 = (j - y) / 2;
        if (n0 < 0 || n1 < 0 || n2 < 0 || n3 < 0) continue;
        ans += comb.H(cdiv(b + 1, 4), n0) * comb.H(cdiv(b, 4), n1) * comb.H(cdiv(b - 1, 4), n2) *
               comb.H(cdiv(b - 2, 4), n3);
    }
    cout << ans << endl;
}
0