結果

問題 No.1202 お菓子の食べ方
ユーザー carrot46carrot46
提出日時 2020-08-29 00:19:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,655 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 173,316 KB
実行使用メモリ 26,984 KB
最終ジャッジ日時 2024-04-26 15:15:48
合計ジャッジ時間 26,665 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 546 ms
19,284 KB
testcase_11 AC 791 ms
19,984 KB
testcase_12 AC 1,686 ms
22,980 KB
testcase_13 AC 571 ms
19,188 KB
testcase_14 AC 1,629 ms
22,940 KB
testcase_15 AC 521 ms
19,000 KB
testcase_16 AC 1,239 ms
21,492 KB
testcase_17 AC 835 ms
20,092 KB
testcase_18 AC 788 ms
19,956 KB
testcase_19 AC 556 ms
19,200 KB
testcase_20 AC 1,326 ms
21,920 KB
testcase_21 AC 1,348 ms
21,888 KB
testcase_22 AC 599 ms
19,460 KB
testcase_23 AC 1,123 ms
21,408 KB
testcase_24 AC 1,145 ms
21,412 KB
testcase_25 AC 570 ms
19,352 KB
testcase_26 AC 1,567 ms
22,512 KB
testcase_27 AC 1,243 ms
21,516 KB
testcase_28 AC 704 ms
19,824 KB
testcase_29 AC 855 ms
20,156 KB
testcase_30 AC 474 ms
18,900 KB
testcase_31 AC 476 ms
18,884 KB
testcase_32 AC 473 ms
18,880 KB
testcase_33 AC 475 ms
18,868 KB
testcase_34 AC 475 ms
19,180 KB
testcase_35 AC 474 ms
18,936 KB
testcase_36 AC 476 ms
18,964 KB
testcase_37 AC 476 ms
19,108 KB
testcase_38 AC 475 ms
19,048 KB
testcase_39 AC 475 ms
19,072 KB
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

class mint{
    public:
        ll x;
        static unsigned long long mod;
        static unsigned long long mod_plus;
        mint(){x = 0;}
        mint(ll _x) : x((_x < 0 ? ((_x += mod_plus) < 0 ? _x + mod_plus : _x) : _x)%mod){}
        /*mint& operator=(const ll &a){
            x = a;
            return *this;
        }*/

        mint operator-(){
            return x == 0 ? 0 : mod - x;
        }
        mint& operator+=(const mint& a){
            if((x += a.x) >= mod) x -= mod;
            return *this;
        }
        mint operator+(const mint& a) const{
            mint res(*this);
            return res += a;
        }
        mint& operator-=(const mint& a){
            if((x -= a.x) < 0) x += mod;
            return *this;
        }
        mint operator-(const mint& a) const{
            mint res(*this);
            return res -= a;
        }
        mint& operator*=(const mint& a){
            (x *= a.x)%=mod;
            return *this;
        }
        /*mint& operator*=(const ll& a){
            mint temp(a);
            return *this *= temp;
        }*/
        mint operator*(const mint& a) const{
            mint res(*this);
            return res *= a;
        }
        /*mint operator*(const ll& a) const{
            mint res(*this);
            return res *= a;
        }*/
        mint pow(unsigned long long pw) const{
            mint res(1), comp(*this);
            while(pw){
                if(pw&1) res *= comp;
                comp *= comp;
                pw >>= 1;
            }
            return res;
        }
        //以下、modが素数のときのみ
        mint inv() const{
            mint res(*this);
            return res.pow(mod - 2);
        }
        mint& operator/=(const mint &a){
            (x *= a.inv().x)%=mod;
            return *this;
        }
        mint operator/(const mint &a) const{
            mint res(*this);
            return res /= a;
        }
};
ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
//unsigned long long mint::mod = 998244353;
unsigned long long mint::mod = int(1e+9) + 7;
unsigned long long mint::mod_plus = (LLONG_MAX / mint::mod) * mint::mod;
typedef vector<mint> vm;

const ll MAX_N = ll(1e+6) + 3000;
vm fact(MAX_N, mint(1)), fact_inv(MAX_N, mint(1));
void makefact(){
    reps(i,2,MAX_N) {
        fact[i] = fact[i-1] * mint(i);
        fact_inv[i] = fact[i].inv();
    }
}
mint nCm(ll n, ll m){
    return fact[n] * fact_inv[n-m] * fact_inv[m];
}
mint nCm_inv(ll n, ll m){
    return fact[n-m] * fact[m] * fact_inv[n];
}

mint f(int i, int j, ll a){
    if(a == 0) return mint(0);
    mint res(a);
    res *= fact[a + i + j];
    res /= i + j + 1;
    res *= fact_inv[a];
    return res;
}

int main() {
    makefact();
    cin>>N>>M;
    mat s(N + 1, vec(M + 1, 0));
    rep(i, N) rep(j, M) cin>>s[i][j];
    mint ans(0);
    rep(i, N){
        rep(j, M){
            mint temp(0);
            temp += f(i, j, s[i][j]) * 3;
            temp -= f(i, j, s[i + 1][j]) + f(i, j, s[i][j + 1]) + f(i, j, s[i][j] - 1);
            temp *= fact_inv[i] * fact_inv[j];
            ans += temp;
        }
    }
    cout<<ans<<endl;
}
0