結果

問題 No.1202 お菓子の食べ方
ユーザー KudeKude
提出日時 2020-08-29 05:34:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 2,470 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 171,272 KB
実行使用メモリ 22,980 KB
最終ジャッジ日時 2024-04-26 15:59:34
合計ジャッジ時間 12,574 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 382 ms
22,848 KB
testcase_01 AC 377 ms
22,648 KB
testcase_02 AC 382 ms
22,876 KB
testcase_03 AC 378 ms
22,980 KB
testcase_04 AC 374 ms
22,916 KB
testcase_05 AC 376 ms
22,852 KB
testcase_06 AC 377 ms
22,916 KB
testcase_07 AC 376 ms
22,844 KB
testcase_08 AC 376 ms
22,872 KB
testcase_09 AC 378 ms
22,780 KB
testcase_10 AC 37 ms
19,004 KB
testcase_11 AC 75 ms
19,448 KB
testcase_12 AC 208 ms
20,880 KB
testcase_13 AC 40 ms
19,020 KB
testcase_14 AC 201 ms
20,884 KB
testcase_15 AC 33 ms
19,060 KB
testcase_16 AC 142 ms
20,164 KB
testcase_17 AC 84 ms
19,572 KB
testcase_18 AC 76 ms
19,404 KB
testcase_19 AC 40 ms
19,024 KB
testcase_20 AC 156 ms
20,284 KB
testcase_21 AC 159 ms
20,584 KB
testcase_22 AC 45 ms
19,124 KB
testcase_23 AC 122 ms
20,128 KB
testcase_24 AC 126 ms
20,056 KB
testcase_25 AC 39 ms
19,028 KB
testcase_26 AC 169 ms
20,476 KB
testcase_27 AC 142 ms
20,120 KB
testcase_28 AC 61 ms
19,364 KB
testcase_29 AC 86 ms
19,524 KB
testcase_30 AC 26 ms
18,916 KB
testcase_31 AC 28 ms
18,836 KB
testcase_32 AC 28 ms
18,900 KB
testcase_33 AC 28 ms
18,912 KB
testcase_34 AC 28 ms
18,880 KB
testcase_35 AC 28 ms
18,812 KB
testcase_36 AC 28 ms
18,896 KB
testcase_37 AC 28 ms
18,812 KB
testcase_38 AC 27 ms
18,952 KB
testcase_39 AC 27 ms
18,872 KB
testcase_40 AC 377 ms
22,784 KB
testcase_41 AC 386 ms
22,780 KB
testcase_42 AC 378 ms
22,800 KB
testcase_43 AC 385 ms
22,788 KB
testcase_44 AC 374 ms
22,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

#define MOD 1000000007
//#define MOD 998244353
struct mint {
	int i;
	mint() : i(0) {}
	mint(int x) {
		i = int(x % MOD);
		if (i < 0) i += MOD;
	}
	template<class T> mint(T x) {
		i = int(x % MOD);
		if (i < 0) i += MOD;
	}
	mint operator+(const mint x) const {return i + x.i;}
	mint operator-(const mint x) const {return i - x.i;}
	mint operator*(const mint x) const {return (long long)i * x.i;}
	mint operator/(const mint x) const {return (long long)i * x.pow(MOD - 2).i;}
	mint inv() {return pow(MOD - 2);}
	template<class T> mint pow(T p) const {
		long long r = 1;
		long long t = i;
		for(; p > 0; p >>= 1) {
			if (p & 1) r = r * t % MOD;
			t = t * t % MOD;
		}
		return r;
	}
	template<class T1, class T2> static mint pow(T1 a, T2 b) {
		long long r = 1;
		long long t = (long long)(a % MOD);
		for(; b > 0; b >>= 1) {
			if (b & 1) r = r * t % MOD;
			t = t * t % MOD;
		}
		return r;
	}
	mint& operator+=(const mint x) {
		i = (i + x.i) % MOD;
		return *this;
	}
	mint& operator-=(const mint x) {
		i = i - x.i;
		if (i < 0) i += MOD;
		return *this;
	}
	mint& operator*=(const mint x) {
		i = (int)((long long)i * x.i % MOD);
		return *this;
	}
	mint& operator/=(const mint x) {
		i = (long long)i * x.pow(MOD - 2).i % MOD;
		return *this;
	}
};

std::ostream& operator<<(std::ostream& os, const mint& m) {
	return os << m.i;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2e6);

int main() {
    int n, m;
    cin >> n >> m;
    VVI s(n + 1, VI(m + 1));
    rep(i, n) rep(j, m) cin >> s[i][j];
    mint ans = 0;
    rep(i, n) rep(j, m) {
        ans += comb(i + j, i) * (comb(i + j + s[i][j], i + j + 1) * 2 - comb(i + j + s[i + 1][j], i + j + 1) - comb(i + j + s[i][j + 1], i + j + 1) + comb(i + j + s[i][j] - 1, i + j));
    }
    cout << ans << endl;
}
0