#include <iostream>
#include <vector>
//#include <bits/stdc++.h>
using namespace std;
struct bigint{
vector<int> d;
bigint(){
}
bigint(int x){
while (x > 0){
d.push_back(x % 10);
x /= 10;
}
if (d.empty()){
d.push_back(0);
}
}
int operator [](int k){
return d[k];
}
int size(){
return d.size();
}
};
ostream& operator <<(ostream& os, bigint x){
int N = x.size();
for (int i = N - 1; i >= 0; i--){
os << x[i];
}
return os;
}
bigint operator +(bigint A, bigint B){
int N1 = A.size();
int N2 = B.size();
int N = max(N1, N2) + 1;
bigint C;
C.d = vector<int>(N, 0);
for (int i = 0; i < N1; i++){
C.d[i] += A[i];
}
for (int i = 0; i < N2; i++){
C.d[i] += B[i];
}
for (int i = 0; i < N - 1; i++){
if (C[i] >= 10){
C.d[i + 1]++;
C.d[i] -= 10;
}
}
if (C.size() >= 2 && C[N - 1] == 0){
C.d.pop_back();
}
return C;
}
int main(){
int n;
cin >> n;
vector<vector<int>> A(n, vector<int>(n));
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin >> A[i][j];
}
}
vector<vector<bigint>> dp(n, vector<bigint>(n, 0));
dp[0][0] = 1;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (A[i][j] > 0){
if (i + A[i][j] < n){
dp[i + A[i][j]][j] = dp[i + A[i][j]][j] + dp[i][j];
}
if (j + A[i][j] < n){
dp[i][j + A[i][j]] = dp[i][j + A[i][j]] + dp[i][j];
}
}
}
}
cout << dp[n - 1][n - 1] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
5 ms |
1108 KB |
Output is correct |
17 |
Correct |
4 ms |
852 KB |
Output is correct |
18 |
Correct |
6 ms |
1364 KB |
Output is correct |
19 |
Correct |
5 ms |
1108 KB |
Output is correct |
20 |
Correct |
7 ms |
1620 KB |
Output is correct |