結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー Yang33Yang33
提出日時 2019-01-22 12:42:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 4,025 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 167,600 KB
実行使用メモリ 9,448 KB
最終ジャッジ日時 2023-10-13 17:39:00
合計ジャッジ時間 4,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,368 KB
testcase_01 AC 9 ms
9,344 KB
testcase_02 AC 9 ms
9,268 KB
testcase_03 AC 8 ms
9,268 KB
testcase_04 AC 9 ms
9,320 KB
testcase_05 AC 9 ms
9,304 KB
testcase_06 AC 9 ms
9,152 KB
testcase_07 AC 9 ms
9,372 KB
testcase_08 AC 9 ms
9,156 KB
testcase_09 AC 9 ms
9,280 KB
testcase_10 AC 9 ms
9,260 KB
testcase_11 AC 9 ms
9,388 KB
testcase_12 AC 9 ms
9,156 KB
testcase_13 AC 9 ms
9,312 KB
testcase_14 AC 9 ms
9,440 KB
testcase_15 AC 9 ms
9,144 KB
testcase_16 AC 9 ms
9,284 KB
testcase_17 AC 9 ms
9,300 KB
testcase_18 AC 9 ms
9,300 KB
testcase_19 AC 9 ms
9,156 KB
testcase_20 AC 10 ms
9,448 KB
testcase_21 AC 9 ms
9,280 KB
testcase_22 AC 10 ms
9,152 KB
testcase_23 AC 9 ms
9,164 KB
testcase_24 AC 9 ms
9,164 KB
testcase_25 AC 9 ms
9,324 KB
testcase_26 AC 9 ms
9,340 KB
testcase_27 AC 9 ms
9,312 KB
testcase_28 AC 9 ms
9,444 KB
testcase_29 AC 9 ms
9,260 KB
testcase_30 AC 9 ms
9,252 KB
testcase_31 AC 9 ms
9,152 KB
testcase_32 AC 9 ms
9,144 KB
testcase_33 AC 10 ms
9,312 KB
testcase_34 AC 9 ms
9,308 KB
testcase_35 AC 9 ms
9,436 KB
testcase_36 AC 9 ms
9,340 KB
testcase_37 AC 9 ms
9,336 KB
testcase_38 AC 10 ms
9,304 KB
testcase_39 AC 10 ms
9,268 KB
testcase_40 AC 9 ms
9,392 KB
testcase_41 AC 11 ms
9,276 KB
testcase_42 AC 10 ms
9,272 KB
testcase_43 AC 11 ms
9,256 KB
testcase_44 AC 11 ms
9,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/01/22  Problem: yukicoder 660  / Link: http://yukicoder.me/problems/no/660  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

template <::std::uint_fast32_t MODULO> class modint {
public:
	using uint32 = ::std::uint_fast32_t; using uint64 = ::std::uint_fast64_t; using value_type = uint32; uint32 a; modint() noexcept : a(0) {}modint(long long x)noexcept :a(x%MODULO) {}modint operator+(const modint &o) const noexcept { return a + o.a < MODULO ? modint(a + o.a) : modint(a + o.a - MODULO); }modint operator-(const modint &o) const noexcept { return modint(a < o.a ? a + MODULO - o.a : a - o.a); }modint operator*(const modint &o) const noexcept { return modint(static_cast<uint64>(a) * o.a % MODULO); }modint operator/(const modint &o) const { return modint(static_cast<uint64>(a) * (~o).a % MODULO); }modint &operator+=(const modint &o) noexcept { return *this = *this + o; }modint &operator-=(const modint &o) noexcept { return *this = *this - o; }modint &operator*=(const modint &o) noexcept { return *this = *this * o; }modint &operator/=(const modint &o) { return *this = *this / o; }modint operator~() const noexcept { return pow(MODULO - 2); }modint operator-() const noexcept { return a ? modint(MODULO - a) : *this; }modint operator++() noexcept { return a == MODULO - 1 ? a = 0 : ++a, *this; }modint operator--() noexcept { return a ? --a : a = MODULO - 1, *this; }bool operator==(const modint &o) const noexcept { return a == o.a; }bool operator!=(const modint &o) const noexcept { return a != o.a; }bool operator<(const modint &o) const noexcept { return a < o.a; }bool operator<=(const modint &o) const noexcept { return a <= o.a; }bool operator>(const modint &o) const noexcept { return a > o.a; }bool operator>=(const modint &o) const noexcept { return a >= o.a; }explicit operator bool() const noexcept { return a; }explicit operator uint32() const noexcept { return a; }modint pow(uint32 x) const noexcept { uint64 t = a, u = 1; while (x) { if (x & 1)u = u * t % MODULO; t = (t * t) % MODULO; x >>= 1; }	return modint(u); }
	uint32 get() const noexcept { return a; }
};
using mint = modint<MOD>;
const mint mintzero = mint(0); const mint mintone = mint(1);
mint modinv(mint a) { return mintone / mint(a); }

vector<mint> fact, inv_fact;

void init_fact(int n) {
	fact.resize(n);
	fact[0] = mintone;
	for (int i = 1; i < n; i++) {
		fact[i] = fact[i - 1] * mint(i);
	}
	inv_fact.resize(n);
	inv_fact[n - 1] = modinv(fact[n - 1]);
	for (int i = n - 2; i >= 0; i--) {
		inv_fact[i] = mint(i + 1) * inv_fact[i + 1];
	}
}
mint nCr(int n, int r) {
	if (n < r || n < 0 || r < 0) return mintzero;
	return fact[n] * inv_fact[r] * inv_fact[n - r];
}


mint f(int h, int w, int k) {
	return mint(nCr(h + w, w)) - mint(nCr(h + w, w + k + 1));
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	init_fact(4e5 + 6);
	LL N; cin >> N;
	mint ans = 0;
	mint pre = 0;
	FOR(i, 0, N / 2 + 1) {
		mint ret = f(N + i-1, i, N - 1);
		ans += ret;
	}

	cout << ans.get() << "\n";

	return 0;
}
0