Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(vec) for(auto& i : vec) cin >> i
- #define cin_2d(vec, n, m) for(int i=0; i<n; i++) for(int j=0; j<m && cin >> vec[i][j]; j++);
- #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
- #define cout_2d(vec, r, c) for(int i=0; i<r; i++, cout << "\n") for(int j=0; j<c && cout << vec[i][j] << " "; j++);
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " : " << s << "\n"
- #define matrix(grid, n, m) vector < vector <ll> > grid(n, vector <ll> (m));
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
- #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define fixed(n) cout << fixed << setprecision(n)
- #define Num_of_Digits(n) ((int)log10(n)+1)
- #define getline(s) getline(cin >> ws, s)
- #define to_decimal(bin) stoi(bin, nullptr, 2)
- #define TC int t; cin >> t; while(t--)
- #define rall(s) s.rbegin(), s.rend()
- #define all(s) s.begin(), s.end()
- #define sz(x) int(x.size())
- #define Pair pair <int, int>
- #define fi first
- #define se second
- #define pb(x) push_back(x)
- #define ll long long
- #define PI acos(-1)
- #define Mod 1'000'000'007
- #define INF 2'000'000'000
- #define EPS 1e-9
- void Anwar_Rizk(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE // Anwar Rizk 🥇🖤
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- Time
- }
- int n, m, cnt = 0;
- vector < vector <int> > grid;
- bool isValid(int r, int c){
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- void count_paths(int r, int c){
- if(r == n - 1 && c == m - 1){
- cnt++;
- return;
- }
- if(isValid(r + 1, c) && grid[r + 1][c] != 0)
- count_paths(r + 1, c);
- if(isValid(r, c + 1) && grid[r][c + 1] != 0)
- count_paths(r, c + 1);
- if(isValid(r - 1, c) && grid[r - 1][c] != 0)
- count_paths(r - 1, c);
- if(isValid(r, c - 1) && grid[r][c - 1] != 0)
- count_paths(r, c - 1);
- }
- int main()
- { Anwar_Rizk();
- cin >> n >> m;
- grid.resize(n, vector <int> (m));
- cin_2d(grid, n, m);
- count_paths(0, 0);
- cout << cnt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement