fork download
  1. #ifndef LOCAL
  2. #define NDEBUG
  3. #endif
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. using i64 = int64_t;
  8.  
  9. void setIO(string s) {
  10. freopen((s+".in").c_str(), "r", stdin);
  11. freopen((s+".out").c_str(), "w", stdout);
  12. }
  13.  
  14. const int MAXN = 310;
  15. int N;
  16. char G[MAXN][MAXN];
  17.  
  18. bool isGood(int x, int y) {
  19. return 0 <= x && x < N && 0 <= y && y < N && G[x][y] == '*';
  20. }
  21.  
  22. i64 ans = 0;
  23. void go() {
  24. for (int a = 0; a < 2*N-1; a++) {
  25. int st = max(0, a-N+1), en = min(a, N-1); // inclusive
  26.  
  27. for (int b = a+2, d = 1; b < 2*N-1; b += 2, d += 1) {
  28. int curVal = 0;
  29. for (int x = 1, y = b-a-1; x <= y; x++, y--) {
  30. curVal += isGood(st+x, (a-st)+y) && isGood(st+x+d, (a-st)+y-d);
  31. }
  32. for (int i = st; i <= en; i++) {
  33. assert(0 <= i && i < N);
  34. assert(0 <= a-i && a-i < N);
  35. if (G[i][a-i] == '*') ans += curVal;
  36. curVal -= isGood(i+1, b-(i+1)) && isGood(i+1+d, b-(i+1+d));
  37. curVal += isGood(i+1+d, b-(i+1+d)) && isGood(i+1+d+d, b-(i+1+d+d));
  38. }
  39. }
  40. }
  41. }
  42.  
  43. char tmp[MAXN][MAXN];
  44.  
  45. void rot90() {
  46. for (int i = 0; i < N; i++) {
  47. for (int j = 0; j < N; j++) {
  48. tmp[N-1-j][i] = G[i][j];
  49. }
  50. }
  51. for (int i = 0; i < N; i++) {
  52. for (int j = 0; j < N; j++) {
  53. G[i][j] = tmp[i][j];
  54. }
  55. }
  56. }
  57.  
  58. int main() {
  59. ios::sync_with_stdio(0), cin.tie(0);
  60.  
  61. cin >> N;
  62. for (int i = 0; i < N; i++) {
  63. cin >> G[i];
  64. }
  65.  
  66. for (int z = 0; z < 4; z++) {
  67. go();
  68. rot90();
  69. }
  70. cout << ans << '\n';
  71.  
  72. return 0;
  73. }
  74.  
Success #stdin #stdout 0s 4248KB
stdin
3
***
***
***
stdout
8