#include <iostream>
#include <algorithm>
using namespace std;
int n, a[110][110];
string ans[150][150];
string add(string s, string t) {
int tmp;
string answer = "";
if (s.length() > t.length()) {
reverse(t.begin(),t.end());
tmp = t.length();
for (int i = tmp; i < s.length(); i++) t += '0';
reverse(t.begin(),t.end());
} else if (s.length() < t.length()) {
reverse(s.begin(),s.end());
tmp = s.length();
for (int i = tmp; i < t.length(); i++) s += '0';
reverse(s.begin(),s.end());
}
tmp = 0;
for (int i = s.length()-1; i >= 0; i--) {
answer += ((s[i]-48)+(t[i]-48)+tmp)%10+48;
tmp = ((s[i]-48)+(t[i]-48)+tmp)/10;
}
if (tmp) answer += tmp+48;
reverse(answer.begin(),answer.end());
return answer;
}
int main() {
cin >> n;
for (int i = 1; i <= 140; i++) for (int j = 1; j <= 140; j++) ans[i][j] = "0";
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> a[i][j];
ans[1][1] = "1";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j] != 0) {
ans[i+a[i][j]][j] = add(ans[i+a[i][j]][j],ans[i][j]);
ans[i][j+a[i][j]] = add(ans[i][j+a[i][j]],ans[i][j]);
}
}
}
cout << ans[n][n] << endl;
}
Compilation message
jump.cpp: In function 'std::string add(std::string, std::string)':
jump.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = tmp; i < s.length(); i++) t += '0';
| ~~^~~~~~~~~~~~
jump.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = tmp; i < t.length(); i++) s += '0';
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1148 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
5 ms |
1452 KB |
Output is correct |
19 |
Correct |
4 ms |
1372 KB |
Output is correct |
20 |
Correct |
7 ms |
1628 KB |
Output is correct |