fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  7. #define endl '\n'
  8.  
  9. const int N = 55;
  10.  
  11. char a[N][N];
  12.  
  13. signed main(){
  14. FAST;
  15. int n, m; cin >> n >> m;
  16. for(int i=1; i<=n; i++){
  17. for(int j=1; j<=m; j++){
  18. cin >> a[i][j];
  19. }
  20. }
  21. string s; cin >> s;
  22. string s2 = s; reverse(s2.begin(), s2.end());
  23. for(int i=1; i<=n; i++){
  24. string t = "";
  25. for(int j=1; j<=m; j++){
  26. t += a[i][j];
  27. if(t.find(s) != string::npos
  28. || t.find(s2) != string::npos){
  29. cout << "YES";
  30. return 0;
  31. }
  32. }
  33. }
  34. for(int i=1; i<=m; i++){
  35. string t = "";
  36. for(int j=1; j<=n; j++){
  37. t += a[j][i];
  38. if(t.find(s) != string::npos
  39. || t.find(s2) != string::npos){
  40. cout << "YES";
  41. return 0;
  42. }
  43. }
  44. }
  45. cout << "NO";
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
NO