SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <bits/stdc++.h> | |
| 2 | using namespace std; | |
| 3 | #define cin(vec) for(auto& i : vec) cin >> i | |
| 4 | #define cin_2d(vec, n, m) for(int i=0; i<n; i++) for(int j=0; j<m && cin >> vec[i][j]; j++); | |
| 5 | #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n"; | |
| 6 | #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++); | |
| 7 | #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " : " << s << "\n" | |
| 8 | #define matrix(grid, n, m) vector < vector <ll> > grid(n, vector <ll> (m)); | |
| 9 | #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n"; | |
| 10 | #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0)) | |
| 11 | #define fixed(n) cout << fixed << setprecision(n) | |
| 12 | #define Num_of_Digits(n) ((int)log10(n)+1) | |
| 13 | #define getline(s) getline(cin >> ws, s) | |
| 14 | #define to_decimal(bin) stoi(bin, nullptr, 2) | |
| 15 | #define TC int t; cin >> t; while(t--) | |
| 16 | #define rall(s) s.rbegin(), s.rend() | |
| 17 | #define all(s) s.begin(), s.end() | |
| 18 | #define sz(x) int(x.size()) | |
| 19 | #define Pair pair <int, int> | |
| 20 | #define fi first | |
| 21 | #define se second | |
| 22 | #define pb(x) push_back(x) | |
| 23 | #define ll long long | |
| 24 | #define PI acos(-1) | |
| 25 | #define Mod 1'000'000'007 | |
| 26 | #define INF 2'000'000'000 | |
| 27 | #define EPS 1e-9 | |
| 28 | ||
| 29 | void Anwar_Rizk(){
| |
| 30 | ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | |
| 31 | #ifndef ONLINE_JUDGE // Anwar Rizk π₯π€ | |
| 32 | freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
| |
| 33 | #endif | |
| 34 | Time | |
| 35 | } | |
| 36 | ||
| 37 | int n, m; | |
| 38 | vector < vector <int> > grid; | |
| 39 | ||
| 40 | bool isValid(int r, int c){
| |
| 41 | return r >= 0 && r < n && c >= 0 && c < m; | |
| 42 | } | |
| 43 | ||
| 44 | ll count(int i, int j){
| |
| 45 | if(!isValid(i, j) || grid[i][j] == 0) return 0; | |
| 46 | if(i == n - 1 && j == m - 1) return 1; | |
| 47 | - | return count(i + 1, j) + count(i, j + 1) + count(i - 1, j) + count(i, j - 1); |
| 47 | + | grid[i][j] = 0; |
| 48 | ll ans = count(i + 1, j) + count(i, j + 1) + count(i - 1, j) + count(i, j - 1); | |
| 49 | grid[i][j] = 1; | |
| 50 | return ans; | |
| 51 | } | |
| 52 | ||
| 53 | int main() | |
| 54 | { Anwar_Rizk();
| |
| 55 | ||
| 56 | cin >> n >> m; | |
| 57 | grid.resize(n, vector <int> (m)); | |
| 58 | cin_2d(grid, n, m); | |
| 59 | cout << count(0, 0); | |
| 60 | ||
| 61 | return 0; | |
| 62 | } |