#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
#define MAX 303
int numRow, numCol, Lim;
int A[MAX][MAX];
int dp[2][MAX][2005];
int cnt[MAX][MAX];
vector<int> comp;
int find(int x){
return upper_bound(comp.begin(), comp.end(), x) - comp.begin() - 1;
}
void process(void){
cin >> numRow >> numCol >> Lim;
FOR(i, 1, numRow) FOR(j, 1, numCol){
cin >> A[i][j];
}
--Lim;
for (int i = 1; i <= Lim; ++i){
comp.emplace_back(Lim / i);
}
sort(comp.begin(), comp.end());
comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
cnt[1][1] = 1;
for (int i = 1; i <= numRow; ++i){
for (int j = 1; j <= numCol; ++j) if(i != 1 || j != 1){
cnt[i][j] = (cnt[i][j - 1] + cnt[i - 1][j]) % Mod;
}
}
dp[0][1][(int)comp.size() - 1] = 1;
FOR(i, 1, numRow) {
memset(dp[1], 0, sizeof dp[1]);
FOR(j, 1, numCol) REP(f, (int)comp.size()){
int nxt = find(comp[f] / A[i][j]);
if(nxt < 0) continue;
dp[1][j][nxt] = (dp[1][j][nxt] + dp[0][j][f] + dp[1][j - 1][f]) % Mod;
}
swap(dp[1], dp[0]);
}
int ans = 0;
for (int i = 0; i < (int)comp.size(); ++i){
ans += dp[0][numCol][i];
ans %= Mod;
}
cout << (cnt[numRow][numCol] - ans + Mod) % Mod;
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
process();
return (0 ^ 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
11604 KB |
Output is correct |
2 |
Correct |
184 ms |
11604 KB |
Output is correct |
3 |
Correct |
406 ms |
18596 KB |
Output is correct |
4 |
Correct |
442 ms |
18628 KB |
Output is correct |
5 |
Correct |
394 ms |
18628 KB |
Output is correct |
6 |
Correct |
436 ms |
18620 KB |
Output is correct |
7 |
Correct |
205 ms |
19152 KB |
Output is correct |
8 |
Correct |
1756 ms |
19648 KB |
Output is correct |
9 |
Correct |
3033 ms |
19896 KB |
Output is correct |
10 |
Correct |
3005 ms |
19892 KB |
Output is correct |