結果

問題 No.1683 Robot Guidance
ユーザー rtyurtyu
提出日時 2021-10-13 15:16:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 72,128 KB
実行使用メモリ 55,472 KB
最終ジャッジ日時 2023-10-17 19:06:04
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,600 KB
testcase_01 AC 2 ms
5,600 KB
testcase_02 AC 2 ms
5,660 KB
testcase_03 AC 12 ms
16,560 KB
testcase_04 AC 5 ms
10,416 KB
testcase_05 AC 8 ms
10,416 KB
testcase_06 AC 17 ms
18,608 KB
testcase_07 AC 14 ms
16,560 KB
testcase_08 AC 43 ms
34,992 KB
testcase_09 AC 14 ms
18,608 KB
testcase_10 AC 26 ms
24,752 KB
testcase_11 AC 21 ms
18,608 KB
testcase_12 AC 35 ms
28,848 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 45 ms
43,184 KB
testcase_15 AC 32 ms
39,088 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
5,720 KB
testcase_20 AC 2 ms
5,720 KB
testcase_21 AC 2 ms
5,644 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 48 ms
39,088 KB
testcase_25 AC 31 ms
39,036 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 46 ms
55,472 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 28 ms
34,940 KB
testcase_33 AC 23 ms
26,748 KB
testcase_34 AC 26 ms
26,748 KB
testcase_35 AC 27 ms
30,844 KB
testcase_36 AC 28 ms
30,844 KB
testcase_37 AC 22 ms
28,796 KB
testcase_38 AC 22 ms
28,848 KB
testcase_39 AC 31 ms
39,036 KB
testcase_40 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const long long md = 1000000007;
long long ft[4000009], rt[4000009];

long long fp(long long n, long long k)
{
	long long s = 1;
	while (k) {
		if (k & 1) s = (s * n) % md;
		n = (n * n) % md; k /= 2;
	}
	return s;
}

long long cb(int n, int k)
{
	if (n < k) return 0;
	return (((ft[n] * rt[k]) % md) * rt[n - k]) % md;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, x, y; cin >> a >> b >> x >> y;
	if (((a + abs(x) + abs(y)) & 1) || abs(x) + abs(y) > a) {
		cout << 0 << '\n';
		return 0;
	}
	if (!a) {
		cout << 1 << '\n';
		return 0;
	}
	if (!b) {
		if (x == a && !y) cout << 1 << '\n';
		else cout << 0 << '\n';
		return 0;
	}
	int n = a + b + 1 + abs(x) + abs(y);
	ft[0] = rt[0] = 1;
	for (int i = 1; i <= n; i++)
		ft[i] = (ft[i - 1] * i) % md;
	rt[n] = fp(ft[n], md - 2);
	for (int i = n - 1; i >= 1; i--)
		rt[i] = (rt[i + 1] * (i + 1)) % md;
	int c[4] = { 0, 0, 0, 0 }, r[4] = { 0, 0, 0, 0 }, tp = 0;
	for (int i = 0; i <= b; i++) {
		c[tp]++;
		tp = (tp + 1) % 4;
	}
	if (x > 0) r[0] = x;
	else r[2] = -x;
	if (y > 0) r[1] = y;
	else r[3] = -y;
	a = (a - (abs(x) + abs(y))) / 2;
	long long ans = 0;
	r[1] += a; r[3] += a;
	for (int i = 0; i <= a; i++) {
		long long s = 1;
		for (int j = 0; j < 4; j++) 
			if (r[j])
				s = (s * cb(c[j] + r[j] - 1, r[j])) % md;
		ans = (ans + s) % md;
		r[0]++; r[1]--; r[2]++; r[3]--;
	}
	cout << ans << '\n';
	return 0;
}
0