编辑代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=1e3+5;
int n,now,ans;
int map[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            char input;
            cin>>input;
            if(input=='W')
                map[j]++;
            else
                map[j]=0;
        }
        for(int j=1;j<=n;j++){
            now=map[j];
            for(int k=j;k<=n;k++){
                if(!map[k])
                    break;
                now=min(now,map[k]);
                ans+=now;
            }
        }
    }
    cout<<ans;
    return 0;
}