1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include<bits/stdc++.h> using namespace std; #pragma GCC optimize(2) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
const int N=610;
int n; char A[N][N],B[N][N]; int S[N][N]; int D[N],C;
int main() { scanf("%d",&n); rep(i,1,n) { scanf("%s",A[i]+1); rep(j,1,n) if(A[i][j]=='*') B[i+j][i-j+n]=1; } int ans=0; rep(i,1,n*2) rep(j,1,n*2) S[i][j]=S[i][j-1]+B[i][j]; rep(i,1,n*2) { C=0; rep(x,1,n*2) if(B[i][x]) D[++C]=x; rep(a,1,C) rep(b,a+1,C) { int d=D[b]-D[a]; i-d>=1 && (ans+=S[i-d][D[b]]-S[i-d][D[a]-1]); i+d<=n*2 && (ans+=S[i+d][D[b]]-S[i+d][D[a]-1]); } } rep(i,1,n*2) rep(j,1,n*2) S[i][j]=S[i][j-1]+B[j][i]; rep(i,1,n*2) { C=0; rep(x,1,n*2) if(B[x][i]) D[++C]=x; rep(a,1,C) rep(b,a+1,C) { int d=D[b]-D[a]; i-d>=1 && (ans+=S[i-d][D[b]-1]-S[i-d][D[a]]); i+d<=n*2 && (ans+=S[i+d][D[b]-1]-S[i+d][D[a]]); } } printf("%d\n",ans); }
|