fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. char arr[1002][1002];
  4. int dp[1002][1002];
  5. int main(){
  6. #ifndef ONLINE_JUDGE
  7. freopen("inp.txt", "r", stdin);
  8. #endif // ONLINE_JUDGE
  9. //ios::sync_with_stdio(false);
  10. //cin.tie(0);
  11. int l, r, q;
  12. scanf("%d %d %d", &l, &r, &q);
  13. //cout<<l<<" "<<r<<endl;
  14. for(int i=0; i<l; ++i)
  15. for(int j=0; j<r;++j)
  16. cin>>arr[i][j];
  17. //for(int i=0; i<l; ++i)
  18. //puts(arr[i]);
  19. bool M[10002];
  20. for(int i=1; i<l+2; ++i)
  21. for(int j=1; j<r+2; ++j){
  22. if(arr[i-1][j-1] == 'M'){
  23. dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1])) + 1;
  24. M[dp[i][j]] = true;
  25. }
  26. else
  27. dp[i][j] = 0;
  28.  
  29. }
  30. for(int i=0; i<l+1; ++i)
  31. for(int j=0; j<r+1; ++j)
  32. dp[i][j] = 0;
  33. bool F[10002];
  34. for(int i=1; i<l+2; ++i)
  35. for(int j=1; j<r+2; ++j){
  36. if(arr[i-1][j-1] == 'F'){
  37. dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1])) + 1;
  38. F[dp[i][j]] = true;
  39. }
  40. else
  41. dp[i][j] = 0;
  42.  
  43. }
  44. while(q--){
  45. char x;
  46. int val, chk;
  47. bool flag = false;
  48. scanf("%d %c", &val, &x);
  49. if(x == 'M')
  50. flag = M[val];
  51. else
  52. flag = F[val];
  53. /*
  54.   for(int i=0; i<l+2; ++i){
  55.   for(int j=0; j<r+2; ++j)
  56.   cout<<dp[i][j]<<" ";
  57.   cout<<endl;
  58.   }
  59.   */
  60. if(flag)
  61. printf("yes\n");
  62. else
  63. printf("no\n");
  64. }
  65. }
Success #stdin #stdout 0s 8360KB
stdin
Standard input is empty
stdout
Standard output is empty