Advertisement
Guest User

Tinkoff B

a guest
Apr 23rd, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define e1 first
  4. #define e2 second
  5. #define pb push_back
  6. #define mp make_pair
  7. #define boost ios_base::sync_with_stdio(false)
  8. #define eb emplace_back
  9. #define OUT(x) {cout << x; exit(0); }
  10. #define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
  11. typedef long long ll;
  12. typedef unsigned long long ull;
  13. typedef pair <int, int> PII;
  14. typedef pair <ll, ll> PLL;
  15. typedef pair <PLL, PLL> PP;
  16. typedef unsigned int ui;
  17. const int inf = 1e9+9;
  18. const ll MOD = 1e9+696969;
  19. const ll INF = 1e18;
  20. int n, m, a, b, k,c;
  21. #define maxn 1010
  22. char s[1010][1010];
  23. int pref[maxn][maxn];
  24.  
  25. inline int sum(int a, int b, int c, int d)
  26. {
  27.     if (b > d) swap(a, c), swap(b, d);
  28.     if (a > c) swap(a, c), swap(b, d);
  29.     return pref[c][d] - pref[a-1][d] - pref[c][b-1] + pref[a-1][b-1];
  30. }
  31.  
  32. int main()
  33. {
  34.     scanf("%d%d", &n, &m);
  35.     FOR(i, 1, n) scanf("%s", s[i] +1);
  36.     int X1, Y1, Y2, X2;
  37.     bool ans = 0;
  38.     FOR(i, 1, n)
  39.         FOR(j, 1, m)
  40.         {
  41.             int aa = 0;
  42.             if (s[i][j] == 'S') X1 = i, Y1 = j;
  43.             if (s[i][j] == 'T') X2 = i, Y2 = j;
  44.             if (s[i][j] == '*') aa = 1;
  45.             pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + aa;
  46.         }
  47.    
  48.     FOR(i, 1, m)
  49.     {
  50.         int s1 = sum(X1, Y1, X1, i) + sum(X1, i, X2, i) + sum(X2, i, X2, Y2);
  51.         if (s1 == 0) ans = 1;
  52.     }
  53.     FOR(i, 1, n)
  54.     {
  55.         int s1 = sum(X1, Y1, i, Y1) + sum(i, Y1, i, Y2) + sum(i, Y2, X2, Y2);
  56.         if (s1 == 0) ans = 1;
  57.     }
  58.     if (ans) cout << "YES";
  59.     else cout << "NO";
  60.        
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement