Submission #720323

#TimeUsernameProblemLanguageResultExecution timeMemory
720323Yell0Jump (BOI06_jump)C++17
100 / 100
8 ms1132 KiB
#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 timeMemoryGrader output
Fetching results...