結果

問題 No.1683 Robot Guidance
ユーザー SSRSSSRS
提出日時 2021-09-17 21:42:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 168,660 KB
実行使用メモリ 18,988 KB
最終ジャッジ日時 2023-09-12 07:08:45
合計ジャッジ時間 6,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 36 ms
6,260 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 22 ms
4,608 KB
testcase_06 AC 57 ms
6,648 KB
testcase_07 AC 44 ms
6,244 KB
testcase_08 AC 180 ms
17,276 KB
testcase_09 AC 47 ms
6,408 KB
testcase_10 AC 102 ms
11,192 KB
testcase_11 AC 88 ms
12,384 KB
testcase_12 AC 156 ms
18,444 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 183 ms
16,880 KB
testcase_15 AC 122 ms
17,212 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 189 ms
18,940 KB
testcase_24 AC 196 ms
17,900 KB
testcase_25 AC 188 ms
18,988 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 147 ms
17,484 KB
testcase_28 AC 189 ms
18,764 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 190 ms
18,788 KB
testcase_31 AC 48 ms
6,912 KB
testcase_32 AC 127 ms
16,984 KB
testcase_33 AC 89 ms
9,528 KB
testcase_34 AC 92 ms
11,932 KB
testcase_35 AC 139 ms
16,828 KB
testcase_36 AC 139 ms
16,872 KB
testcase_37 AC 28 ms
5,392 KB
testcase_38 AC 114 ms
16,852 KB
testcase_39 AC 98 ms
11,284 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
long long modbinom(int n, int k){
	if (n < 0 || k < 0 || k > n){
		return 0;
	} else {
		return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
	}
}
int main(){
  int A, B, X, Y;
  cin >> A >> B >> X >> Y;
  long long ans = 0;
  for (int i = 0; i <= A; i++){
    int j = A - i;
    if ((X - i) % 2 == 0 && (Y - j) % 2 == 0){
      int r = (i + X) / 2;
      int l = (i - X) / 2;
      int u = (j + Y) / 2;
      int d = (j - Y) / 2;
      if (r >= 0 && l >= 0 && u >= 0 && d >= 0){
        long long add = 1;
        if (r > 0){
          add *= modbinom((B + 4) / 4 + r - 1, r);
        }
        if (u > 0){
          add *= modbinom((B + 3) / 4 + u - 1, u);
          add %= MOD;
        }
        if (l > 0){
          add *= modbinom((B + 2) / 4 + l - 1, l);
          add %= MOD;
        }
        if (d > 0){
          add *= modbinom((B + 1) / 4 + d - 1, d);
          add %= MOD;
        }
        ans += add;
      }
    }
  }
  ans %= MOD;
  cout << ans << endl;
}
0