# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
634897 | vendx_greyback | Jump (BOI06_jump) | C++14 | 10 ms | 1140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int,int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
string add(string num1, string num2){
while(num1.size() < num2.size())
num1.push_back('0');
while(num1.size() > num2.size())
num2.push_back('0');
string ans;
int carry = 0;
for(int i = 0; i < num1.size(); i++){
int curr = (num1[i] - '0') + (num2[i] - '0') + carry;
ans.push_back((curr % 10) + '0');
carry = curr / 10;
}
if(carry)
ans.push_back(carry + '0');
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int grid[n][n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin>>grid[i][j];
string dp[n][n];
for(int i = n-1; i >= 0; i--){
for(int j = n-1; j >= 0; j--){
if(i == n-1 && j == n-1){
dp[i][j] = "1";
continue;
}
dp[i][j] = "0";
if(i + grid[i][j] < n)
dp[i][j] = add(dp[i][j], dp[i + grid[i][j]][j]);
if(j + grid[i][j] < n)
dp[i][j] = add(dp[i][j], dp[i][j + grid[i][j]]);
}
}
reverse(all(dp[0][0]));
cout<<dp[0][0];
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |