結果
| 問題 |
No.1683 Robot Guidance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-17 23:18:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,500 bytes |
| コンパイル時間 | 1,456 ms |
| コンパイル使用メモリ | 170,864 KB |
| 実行使用メモリ | 19,024 KB |
| 最終ジャッジ日時 | 2024-06-29 22:06:26 |
| 合計ジャッジ時間 | 11,689 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 WA * 4 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;
typedef long long ll;
vector<ll> f(2000001, 1);
ll MOD = 1000000007;
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll comb(ll x, ll y) {
ll ret = f[x];
ret = ret * mod_pow(f[y], MOD - 2, MOD) % MOD;
ret = ret * mod_pow(f[x - y], MOD - 2, MOD) % MOD;
return ret;
}
int main() {
ll A, B, X, Y;
rep(i, 0, 2000000) f[i + 1] = f[i] * (i + 1) % MOD;
cin >> A >> B >> X >> Y;
if (A < abs(X) + abs(Y)) {
cout << 0 << endl;
return 0;
}
if (A % 2 != (X + Y) % 2) {
cout << 0 << endl;
return 0;
}
if (B == 0) {
if (X == A) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
if (B == 1) {
if (X >= 0 && Y >= 0 && X + Y == A) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
if (B == 2) {
if (Y >= 0 && abs(X) + Y <= A) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
if (B == 3) {
cout << (A - abs(X) - abs(Y)) / 2 + 1 << endl;
return 0;
}
ll R = (B + 4) / 4, U = (B + 3) / 4, L = (B + 2) / 4, D = (B + 1) / 4;
ll ans = 0, C = (A - abs(X) - abs(Y)) / 2;
rep(i, 0, C + 1) {
//cout << "i=" << i << endl;
ll P = 1;
if (X > 0) {
P = P * comb(R - 1 + X + i, R - 1) % MOD;
//cout << "ans=" << ans << endl;
P = P * comb(L - 1 + i, L - 1) % MOD;
//cout << "ans=" << ans << endl;
} else {
P = P * comb(R - 1 + i, R - 1) % MOD;
//cout << "ans=" << ans << endl;
P = P * comb(L - 1 - X + i, L - 1) % MOD;
//cout << "ans=" << ans << endl;
}
if (Y > 0) {
P = P * comb(U - 1 + Y + C - i, U - 1) % MOD;
//cout << "ans=" << ans << endl;
P = P * comb(D - 1 + C - i, D - 1) % MOD;
//cout << "ans=" << ans << endl;
} else {
P = P * comb(U - 1 + C - i, U - 1) % MOD;
//cout << "ans=" << ans << endl;
P = P * comb(D - 1 - Y + C - i, D - 1) % MOD;
//cout << "ans=" << ans << endl;
}
ans = (ans + P) % MOD;
}
cout << ans << endl;
//cout << "R=" << R << " U=" << U << " L=" << L << " D=" << D << endl;
}