# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
720323 | Yell0 | Jump (BOI06_jump) | C++17 | 8 ms | 1132 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;
int N,gr[102][102];
string dp[102][102];
inline string add(string x,string y) {
if(x=="0") return y;
if(y=="0") return x;
string ret="";
reverse(x.begin(),x.end());
reverse(y.begin(),y.end());
if(x.size()<y.size()) swap(x,y);
int c=0,d;
for(int i=0;i<(int)x.size();++i) {
if(i>=(int)y.size()) d=x[i]-'0'+c;
else d=x[i]-'0'+y[i]-'0'+c;
c=d/10;
ret.push_back(d%10+'0');
}
if(c) ret.push_back(c+'0');
reverse(ret.begin(),ret.end());
return ret;
}
inline bool chk(int r,int c) {return r>0&&c>0&&r<=N&&c<=N;}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin>>N;
dp[1][1]="1";
for(int i=1;i<=N;++i) for(int j=1;j<=N;++j) {
cin>>gr[i][j];
if(!gr[i][j]) continue;
if(chk(i+gr[i][j],j)) dp[i+gr[i][j]][j]=add(dp[i+gr[i][j]][j],dp[i][j]);
if(chk(i,j+gr[i][j])) dp[i][j+gr[i][j]]=add(dp[i][j+gr[i][j]],dp[i][j]);
}
cout<<(dp[N][N].size()?dp[N][N]:"0")<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |