fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. string s[2];
  6. long int ar[2][100005],u,d,n;
  7. long int func (long int l)
  8. {
  9. long int r[100005];
  10.  
  11.  
  12. for(long int i=0;i<n;i++)
  13. {
  14. if((s[0][i]=='*')&&(s[1][i]=='*'))
  15. {
  16. r[i]=3;
  17. }
  18. else if(s[0][i]=='*')
  19. {
  20. r[i]=1;
  21. }
  22. else if(s[1][i]=='*')
  23. {
  24. r[i]=2;
  25. }
  26. else
  27. {
  28. r[i]=0;
  29. }
  30.  
  31.  
  32. }
  33.  
  34. stack <long int> s;
  35. //s.push(r[min(u,d)]);
  36.  
  37. for(long int i=0;i<n;i++)
  38. {
  39. if(r[i]!=0)
  40. {
  41. if(s.empty())
  42. {
  43. s.push(r[i]);
  44. }
  45. else
  46. {
  47. if((s.top()!=r[i])&&(s.top()!=3)&&(r[i]!=3)&&(s.size()<2))
  48. {
  49. s.push(r[i]);
  50.  
  51. }
  52. else
  53. {
  54. while(!s.empty())
  55. {
  56. s.pop();
  57. }
  58. s.push(r[i]);
  59. l++;
  60. //cout<<" i="<<i<<" l="<<l<<endl;
  61. }
  62. }
  63. }
  64. }
  65. return l;
  66.  
  67. }
  68.  
  69. int main() {
  70. long int t,i,k,l;
  71.  
  72. cin>>t;
  73. while(t--)
  74. { u=-1;d=-1;l=0;
  75. for(i=0;i<n+1;i++)
  76. {
  77. ar[1][i]=0;
  78. ar[0][i]=0;
  79. }
  80. cin>>n;
  81. cin>>s[0];
  82. cin>>s[1];
  83. if(s[0][0]=='*')
  84. ar[0][0]=1;
  85. else
  86. ar[0][0]=0;
  87. if(s[1][0]=='*')
  88. ar[1][0]=1;
  89. else
  90. ar[1][0]=0;
  91.  
  92. for(i=0;i<n;i++)
  93. {
  94. if((s[0][i]=='*')&&(u<0))
  95. u=i;
  96. if((s[1][i]=='*')&&(d<0))
  97. d=i;
  98. if(i>0)
  99. {
  100. if(s[0][i]=='*')
  101. ar[0][i]=ar[0][i-1]+1;
  102. else
  103. ar[0][i]=ar[0][i-1];
  104.  
  105. if(s[1][i]=='*')
  106. ar[1][i]=ar[1][i]+1;
  107. else
  108. ar[1][i]=ar[1][i];
  109.  
  110. }
  111.  
  112. }
  113. if((u>-1)&&(d>-1))
  114. {l=1;
  115. cout<<func(l)<<endl;
  116.  
  117. }
  118. else if ((u==-1)&&(d==-1))
  119. {
  120. cout<<0<<endl;
  121. }
  122. else
  123. {
  124. k=max(ar[0][n-1],ar[1][n-1]);
  125. cout<<k-1<<endl;
  126. }
  127.  
  128.  
  129. }
  130. return 0;
  131. }
Success #stdin #stdout 0s 16800KB
stdin
1
5
.....
*..*.
stdout
-1