結果
問題 | No.1202 お菓子の食べ方 |
ユーザー | 👑 kmjp |
提出日時 | 2020-08-29 01:34:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 233 ms / 2,000 ms |
コード長 | 1,612 bytes |
コンパイル時間 | 2,255 ms |
コンパイル使用メモリ | 196,540 KB |
実行使用メモリ | 40,448 KB |
最終ジャッジ日時 | 2024-04-26 15:47:46 |
合計ジャッジ時間 | 13,647 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 233 ms
40,320 KB |
testcase_01 | AC | 228 ms
40,192 KB |
testcase_02 | AC | 228 ms
40,192 KB |
testcase_03 | AC | 224 ms
40,192 KB |
testcase_04 | AC | 225 ms
40,320 KB |
testcase_05 | AC | 226 ms
40,192 KB |
testcase_06 | AC | 221 ms
40,320 KB |
testcase_07 | AC | 230 ms
40,064 KB |
testcase_08 | AC | 226 ms
40,192 KB |
testcase_09 | AC | 232 ms
40,320 KB |
testcase_10 | AC | 88 ms
37,632 KB |
testcase_11 | AC | 105 ms
39,424 KB |
testcase_12 | AC | 159 ms
39,552 KB |
testcase_13 | AC | 91 ms
38,784 KB |
testcase_14 | AC | 156 ms
39,552 KB |
testcase_15 | AC | 85 ms
37,504 KB |
testcase_16 | AC | 136 ms
38,784 KB |
testcase_17 | AC | 107 ms
38,016 KB |
testcase_18 | AC | 106 ms
39,808 KB |
testcase_19 | AC | 90 ms
39,424 KB |
testcase_20 | AC | 139 ms
38,528 KB |
testcase_21 | AC | 136 ms
39,936 KB |
testcase_22 | AC | 90 ms
39,168 KB |
testcase_23 | AC | 123 ms
37,632 KB |
testcase_24 | AC | 128 ms
38,656 KB |
testcase_25 | AC | 90 ms
36,864 KB |
testcase_26 | AC | 141 ms
39,040 KB |
testcase_27 | AC | 134 ms
37,760 KB |
testcase_28 | AC | 103 ms
38,144 KB |
testcase_29 | AC | 105 ms
38,272 KB |
testcase_30 | AC | 81 ms
36,352 KB |
testcase_31 | AC | 82 ms
36,224 KB |
testcase_32 | AC | 82 ms
36,608 KB |
testcase_33 | AC | 77 ms
36,352 KB |
testcase_34 | AC | 77 ms
36,352 KB |
testcase_35 | AC | 78 ms
36,352 KB |
testcase_36 | AC | 77 ms
36,352 KB |
testcase_37 | AC | 76 ms
36,352 KB |
testcase_38 | AC | 79 ms
36,352 KB |
testcase_39 | AC | 81 ms
36,480 KB |
testcase_40 | AC | 223 ms
40,320 KB |
testcase_41 | AC | 225 ms
40,192 KB |
testcase_42 | AC | 226 ms
40,192 KB |
testcase_43 | AC | 229 ms
40,448 KB |
testcase_44 | AC | 225 ms
40,192 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int H,W; int S[1010][1010]; const ll mo=1000000007; ll comb(ll N_, ll C_) { const int NUM_=1400001; static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1]; if (fact[0]==0) { inv[1]=fact[0]=factr[0]=1; for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo; for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo; } if(C_<0 || C_>N_) return 0; return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo; } void solve() { int i,j,k,l,r,x,y; string s; cin>>H>>W; FOR(y,H) FOR(x,W) { cin>>S[y][x]; } ll ret=0; FOR(y,H) FOR(x,W) { //最後に-1 ret+=comb(y+x,x)*comb(S[y][x]-1+y+x,y+x)%mo; //最後に縦 // sum(Comb(0+m,0)~comb(n+m,n))=comb(n+m+1,n)を利用 ll a=comb(S[y][x]-1+x+y+1,S[y][x]-1); ll b=comb(S[y+1][x]-1+x+y+1,S[y+1][x]-1); (ret+=(a-b)*comb(x+y,x))%=mo; ll c=comb(S[y][x+1]-1+x+y+1,S[y][x+1]-1); (ret+=(a-c)*comb(x+y,x))%=mo; } cout<<(ret%mo+mo)%mo<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }