Advertisement
kxcoze

cringe6

Oct 27th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1.   #include "bits/stdc++.h"
  2.  
  3.   using namespace std;
  4.  
  5.   #define foreach(i, n) for(auto &i : (n))
  6.   #define all(x) (x).begin(), (x).end()
  7.   #define pb push_back    
  8.   #define mp make_pair    
  9.   #define ll long long    
  10.  
  11.   const ll MOD = 1e9 + 7;
  12.   const int inf = 1e9;
  13.   const double pi = acos(-1.0);
  14.  
  15.   int n, m, k, ans = 0;
  16.  
  17. >>void findword(vector<string> &mapp, vector<auto> &us, string req, int cur, int x, int y) {
  18.       if (req.size()-1 == cur) {
  19.           ans++;
  20.           return;
  21.       }
  22.  
  23.       cout << req << ' ' << cur << ' ' << x << ' ' << y << '\n';
  24.       if (y-1 > 0 && !us[x][y-1] && mapp[x][y-1] == req[cur]) {
  25.           us[x][y-1] = 1;
  26.           findword(mapp, us, req, cur++, x, y-1);
  27.       } else if (x-1 > 0 && !us[x-1][y] && mapp[x-1][y] == req[cur]) {
  28.           us[x-1][y] = 1;
  29.           findword(mapp, us, req, cur++, x-1, y);
  30.       } else if (y+1 < m && !us[x][y+1] && mapp[x][y+1] == req[cur]) {
  31.           us[x][y+1] = 1;
  32.           findword(mapp, us, req, cur++, x, y+1);
  33.       } else if (x+1 < n && !us[x+1][y] && mapp[x+1][y] == req[cur]) {
  34.           us[x+1][y] = 1;
  35.           findword(mapp, us, req, cur++, x+1, y);
  36.       } else
  37.           return;
  38.   }
  39.  
  40. >>void solve(vector <string> &mapp, vector<auto> &us, string req, int cur) {
  41.       for (int i = 0; i < m; i++) {
  42.           for (int j = 0; j < n; j++) {
  43.               if (mapp[i][j] == req[cur]) {
  44.                   us[i][j] = 1;
  45.                   findword(mapp, us, req, cur++, i, j);
  46.               }
  47.           }
  48.       }
  49.   }
  50.  
  51.   int main() {
  52.       cin >> m >> n >> k;
  53.       vector <string> f(m), stu(k);
  54.       for (int i = 0; i < m; i++) {
  55.           cin >> f[i];
  56.       }
  57.       for (int i = 0; i < k; i++) {
  58.           cin >> stu[i];
  59.       }
  60.  
  61.       for (int i = 0; i < k; i++) {
  62.           vector <vector<int>> used(m, vector<int> (n, 0));
  63.           solve(f, used, stu[i], 0);
  64.       }
  65.       cout << ans << '\n';
  66.       return 0;
  67.   }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement