#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 100005
#define MOD ll(1e9 + 7)
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[305][305], dp[305][305], f[305][305], n, m, s, ans;
int mk[305][305];
vector <int> g[305][305];
vector <pair <int, ll> > vr;
void dfs(int x, int y)
{
if (mk[x][y] == sz(vr)) return;
mk[x][y] = sz(vr);
if ((x + 1 != n && a[x + 1][y] != 1) || (y + 1 != m && a[x][y + 1] != 1)) g[x][y].pb(sz(vr) - 1);
if (x + 1 != n && a[x + 1][y] == 1) dfs(x + 1, y);
if (y + 1 != m && a[x][y + 1] == 1) dfs(x, y + 1);
}
void rec(int x, int y, ll sm, ll kol)
{
sm *= a[x][y];
if (sm >= s) {ans = (ans + (kol * dp[x][y]) % MOD) % MOD; return;}
if (a[x][y] == 1) {vr.pb({sm, kol}); dfs(x, y); return;}
if (x + 1 != n) rec(x + 1, y, sm, kol);
if (y + 1 != m) rec(x, y + 1, sm, kol);
}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> s;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
dp[n - 1][m - 1] = 1;
for (int i = n - 1; i >= 0; i--)
for (int j = m - 1; j >= 0; j--)
{
if (i + 1 != n) dp[i][j] += dp[i + 1][j];
if (j + 1 != m) dp[i][j] += dp[i][j + 1];
dp[i][j] %= MOD;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (a[i][j] != 1) continue;
if ((i == 0 || a[i - 1][j] != 1) && (j == 0 || a[i][j - 1] != 1)) f[i][j] = 1;
else
{
if (i != 0 && a[i - 1][j] == 1) f[i][j] = (f[i - 1][j] + f[i][j]) % MOD;
if (j != 0 && a[i][j - 1] == 1) f[i][j] = (f[i][j - 1] + f[i][j]) % MOD;
}
}
rec(0, 0, 1, 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (a[i][j] != 1) continue;
if (i + 1 != n && a[i + 1][j] != 1)
for (auto it : g[i][j])
rec(i + 1, j, vr[it].F, (vr[it].S * f[i][j]) % MOD);
if (j + 1 != m && a[i][j + 1] != 1)
for (auto it : g[i][j])
rec(i, j + 1, vr[it].F, (vr[it].S * f[i][j]) % MOD);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
501 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Runtime error |
574 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Runtime error |
467 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Runtime error |
464 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
434 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
426 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
381 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
363 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
453 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
427 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |