Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <numeric>
  6. #include <functional>
  7. #include <cmath>
  8. #include <queue>
  9. #include <stack>
  10. #include <set>
  11. #include <map>
  12. #include <sstream>
  13. #include <string>
  14.  
  15. #define repd(i,a,b) for (int i=(a);i<(b);i++)
  16. #define rep(i,n) repd(i,0,n)
  17. #define var auto
  18. #define mod 1000000007
  19. #define inf 2147483647
  20. typedef long long ll;
  21.  
  22. using namespace std;
  23.  
  24. int inputValue(){
  25. int a;
  26. cin >> a;
  27. return a;
  28. }
  29.  
  30. template <typename T>
  31. void output(T a, int precision) {
  32. if(precision > 0){
  33. cout << fixed << setprecision(precision) << a << "\n";
  34. }
  35. else{
  36. cout << a << "\n";
  37. }
  38. }
  39.  
  40. // end of template
  41.  
  42. bool t[111][3];
  43. bool isVis[111][3];
  44.  
  45. int main() {
  46. // source code
  47.  
  48. int N = inputValue();
  49.  
  50. rep(a, N){
  51.  
  52. rep(i, 111){
  53. rep(j, 3){
  54. t[i][j] = false;
  55. }
  56. }
  57.  
  58. int row = inputValue();
  59. int train = inputValue();
  60.  
  61. string s[3];
  62.  
  63. rep(i, 3){
  64. cin >> s[i];
  65. s[i] += "..";
  66. }
  67.  
  68. int start;
  69.  
  70. rep(i, 3){
  71. if (s[i][0] == 's') {
  72. start = i;
  73. }
  74. }
  75.  
  76. rep(i, row + 2){
  77. rep(j, 3){
  78. t[i][j] = (s[j][i] == '.') ? true : false;
  79. isVis[i][j] = false;
  80. }
  81. }
  82.  
  83. priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  84.  
  85. pq.push(make_pair(0, start));
  86.  
  87. while (!pq.empty() && pq.top().first < row - 1) {
  88. var pqt = pq.top();
  89. pq.pop();
  90.  
  91. if (pqt.second >= 1) {
  92. if (t[pqt.first + 1][pqt.second] && t[pqt.first + 1][pqt.second - 1] && t[pqt.first + 2][pqt.second - 1] && t[pqt.first + 3][pqt.second - 1] && !isVis[pqt.first + 3][pqt.second - 1]) {
  93. isVis[pqt.first + 3][pqt.second - 1] = true;
  94. pq.push(make_pair(pqt.first + 3, pqt.second - 1));
  95. }
  96. }
  97.  
  98. if (pqt.second <= 1) {
  99. if (t[pqt.first + 1][pqt.second] && t[pqt.first + 1][pqt.second + 1] && t[pqt.first + 2][pqt.second + 1] && t[pqt.first + 3][pqt.second + 1] && !isVis[pqt.first + 3][pqt.second + 1]) {
  100. isVis[pqt.first + 3][pqt.second + 1] = true;
  101. pq.push(make_pair(pqt.first + 3, pqt.second + 1));
  102. }
  103. }
  104.  
  105. if (t[pqt.first + 1][pqt.second] && t[pqt.first + 2][pqt.second] && t[pqt.first + 3][pqt.second] && !isVis[pqt.first + 3][pqt.second]) {
  106. isVis[pqt.first + 3][pqt.second] = true;
  107. pq.push(make_pair(pqt.first + 3, pqt.second));
  108. }
  109. }
  110.  
  111. output((!pq.empty()) ? "YES" : "NO", 0);
  112.  
  113.  
  114. }
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement