/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
const ll modulo = 1e4;
//#define int ll
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.in","r",stdin);
// freopen("haybales.out","w",stdout);
ll n;
cin >> n;
vector<vector<ll>> arr(n,vector<ll>(n));
vector<vector<ll>> DP(n,vector<ll>(n));
DP[0][0]=1;
for(auto&i:arr)for(ll&j:i)cin>>j;
for (ll i = 0; i < n; i++) { // i is row
for (ll j = 0; j < n; j++) { // j is column
if(arr[i][j]==0)continue;
if(arr[i][j]+j<n){
DP[i][j+arr[i][j]]+=DP[i][j];
}
if(arr[i][j]+i<n){
DP[i+arr[i][j]][j]+=DP[i][j];
}
}
}
cout << DP[n-1][n-1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |