# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1120079 | fyan | Mobitel (COCI19_mobitel) | C++14 | 6060 ms | 21832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define i64 long long
const int mxn = 305;
const int mod = 1e9+7;
i64 ksm(int a, int b = mod-2) {
i64 res=1, aux=a;
for (int i=1; i<=b; i*=2) {
if (i&b) res=res*aux%mod;
aux=aux*aux%mod;
}
return res;
}
i64 ft[2*mxn],ift[2*mxn];
i64 nck(int n, int k) {
return ft[n]*ift[k]%mod*ift[n-k]%mod;
}
int r,c,n,g[mxn][mxn];
map<int,int> dp[mxn*mxn];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
ft[0] = ift[0] = 1;
for (int i=1; i<2*mxn; i++) {
ft[i] = i*ft[i-1]%mod;
ift[i] = ksm(ft[i]);
}
cin>>r>>c>>n; n--;
for (int i=0; i<r; i++) {
for (int j=0; j<c; j++) {
cin>>g[i][j];
}
}
cin>>r>>c>>n;
dp[0][n/g[0][0]]++;
for (int i=0; i<r; i++) {
for (int j=0; j<c; j++) {
if (i<r-1) {
for (auto [v,amt] : dp[i*mxn+j]) {
dp[(i+1)*mxn+j][v/g[i+1][j]] += amt;
dp[(i+1)*mxn+j][v/g[i+1][j]] %= mod;
}
}
if (j<c-1) {
for (auto [v,amt] : dp[i*mxn+j]) {
dp[i*mxn+j+1][v/g[i][j+1]] += amt;
dp[i*mxn+j+1][v/g[i][j+1]] %= mod;
}
}
if (i!=r-1 || j!=c-1) dp[i*mxn+j].clear();
}
}
int cnt = 0;
for (auto [v,amt] : dp[(r-1)*mxn+c-1]) {
if (v) {
cnt += amt;
cnt %= mod;
}
}
cnt = (mod+nck(r+c-2,c-1)-cnt)%mod;
cout<<cnt;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |