#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define MOD ll(1e9 + 7)
using namespace std;
typedef long long ll;
ll dp[2][301][2005], a[301][301];
vector <ll> vr;
int opr(int x) {if (vr[sz(vr) - 2] <= x) return sz(vr) - 2; return upper_bound(vr.begin(), vr.end(), x) - vr.begin() - 1;}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vr.pb(k);
for (ll i = 1; i <= k; i++)
{
ll val = vr.back();
while ((val - 1) * i >= k) val--;
if (vr.back() != val) vr.pb(val);
}
sort(vr.begin(), vr.end());
for (ll i = 0; i < n; i++)
for (ll j = 0; j < m; j++) cin >> a[i][j];
dp[0][0][opr(min(k, a[0][0]))] = 1;
for (ll i = 0; i < n; i++)
{
for (ll j = 0; j < m; j++)
for (ll u = 0; u < sz(vr) - 1; u++)
{
if (dp[0][j][u] == 0) continue;
ll val = vr[u];
if (i + 1 != n) dp[1][j][opr(min(k, val * a[i + 1][j]))] = (dp[1][j][opr(min(k, val * a[i + 1][j]))] + dp[0][j][u]) % MOD;
if (j + 1 != m) dp[0][j + 1][opr(min(k, val * a[i][j + 1]))] = (dp[0][j + 1][opr(min(k, val * a[i][j + 1]))] + dp[0][j][u]) % MOD;
}
if (i + 1 != n)
{
for (ll j = 0; j < m; j++)
for (ll u = 0; u < sz(vr) - 1; u++) {dp[0][j][u] = dp[1][j][u]; dp[1][j][u] = 0;}
}
}
cout << dp[0][m - 1][sz(vr) - 2];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
94 ms |
3704 KB |
Output isn't correct |
2 |
Correct |
100 ms |
3584 KB |
Output is correct |
3 |
Incorrect |
661 ms |
3832 KB |
Output isn't correct |
4 |
Incorrect |
701 ms |
3832 KB |
Output isn't correct |
5 |
Incorrect |
1640 ms |
3832 KB |
Output isn't correct |
6 |
Incorrect |
1596 ms |
3832 KB |
Output isn't correct |
7 |
Incorrect |
614 ms |
2808 KB |
Output isn't correct |
8 |
Execution timed out |
6062 ms |
7808 KB |
Time limit exceeded |
9 |
Execution timed out |
6091 ms |
10368 KB |
Time limit exceeded |
10 |
Execution timed out |
6071 ms |
10496 KB |
Time limit exceeded |