fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <climits>
  5. #include <iomanip>
  6. #include <cmath>
  7. #include <vector>
  8. #include <utility>
  9. #include <map>
  10. #include <stack>
  11. #include <queue>
  12. #include <bits/stdc++.h>
  13. using namespace std;
  14. #define ll long long
  15. #define du double
  16. #define endl '\n'
  17.  
  18.  
  19. int main() {
  20. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  21. int n,m;
  22. cin>>n>>m;
  23. char r[n][m];
  24. bool r1[n][m]={0};
  25. for(int i=0;i<n;++i)
  26. {
  27. for(int j=0;j<m;++j)
  28. {
  29. cin>>r[i][j];
  30. r1[i][j]=0;
  31. }
  32. }
  33. int p=0;
  34. vector <int>v1;
  35. vector <int>v2;
  36. vector <int>v3;
  37. for(int i=0;i<n;++i)
  38. {
  39. for(int j=0;j<m;++j)
  40. {
  41. if(r[i][j]=='*')
  42. {
  43. int k=1;
  44.  
  45. while(i-k>=0&&j-k>=0&&j+k<m&&i+k<n)
  46. {
  47.  
  48. if(r[i-k][j]=='*'&&r[i+k][j]=='*'&&r[i][j-k]=='*'&&r[i][j+k]=='*')
  49. {
  50. ++p;
  51. v1.push_back(i+1);
  52. v2.push_back(j+1);
  53. v3.push_back(k);
  54. r1[i][j]=1;
  55. r1[i-k][j]=1;
  56. r1[i+k][j]=1;
  57. r1[i][j-k]=1;
  58. r1[i][j+k]=1;
  59. }
  60. else
  61. {
  62. break;
  63. }
  64. ++k;
  65. }
  66. }
  67. }
  68. }
  69. int f=0;
  70. for(int i=0;i<n;++i)
  71. {
  72. for(int j=0;j<m;++j)
  73. {
  74. if(r[i][j]=='*'&&r1[i][j]!=1)
  75. {
  76. f=1;
  77. break;
  78. }
  79. }
  80. if(f==1)
  81. break;
  82. }
  83. if(f==1)
  84. cout<<-1;
  85. else
  86. {
  87. cout<<p<<endl;
  88. for(int i=0;i<p;++i)
  89. {
  90. cout<<v1[i]<<" "<<v2[i]<<" "<<v3[i];
  91. if(i!=p-1)
  92. cout<<endl;
  93. }
  94. }
  95.  
  96. return 0;
  97.  
  98. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
0