#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb push_back
string add(string a, string b) {
if(a.length() < b.length()) swap(a, b);
while(b.length() < a.length())
b = "0" + b;
string ans;
int carry = 0;
FORD(i, a.length() - 1, 0) {
int c = (a[i] - '0') + (b[i] - '0') + carry;
char num = (char) (c % 10 + (int)('0'));
ans = num + ans;
carry = c / 10;
}
if(carry) {
char num = (char) (carry + (int)('0'));
ans = num + ans;
}
return ans;
}
void solve()
{
int n;
cin >> n;
int a[n][n];
FOR(i, 0, n){
FOR(j, 0, n) {
cin >> a[i][j];
}
}
ll dp[n][n] = {};
dp[0][0] = 1;
FOR(i, 0, n) {
FOR(j, 0, n) {
if(a[i][j] == 0)
continue;
if(i + a[i][j] < n)
dp[i + a[i][j]][j] += dp[i][j];
if(j + a[i][j] < n)
dp[i][j + a[i][j]] += dp[i][j];
}
}
// FOR(i, 0, n) {
// FOR(j, 0, n){
// cout << dp[i][j] << " ";
// }
// cout << nl;
// }
cout << dp[n - 1][n - 1] << nl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |