#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=2010;
ll n, m, k, u, v, x, y, t, a, b, ans;
int A[N][N];
ll L[N], R[N];
ll sum[N];
ll C2(ll x){
return x*(x+1)/2;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin>>n>>m;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
char ch;
cin>>ch;
if (ch=='.') A[i][j]=(A[i-1][j]+1);
}
for (int i=1; i<=n; i++) for (int j=1; j<=i; j++) sum[i]+=j*(i-j+1ll);
for (int i=1; i<=n; i++){
for (int j=1; j<=m; j++) for (L[j]=j-1; L[j] && A[i][L[j]]>=A[i][j]; L[j]=L[L[j]]);
for (int j=m; j; j--) for (R[j]=j+1; R[j]<=m && A[i][R[j]]>A[i][j]; R[j]=R[R[j]]);
for (int j=1; j<=m; j++) ans+=1ll*C2(A[i][j])*(sum[R[j]-L[j]-1]-sum[R[j]-j-1]-sum[j-L[j]-1]);
}
cout<<ans<<'\n';
return 0;
}
/*
2 3
.#.
..#
*/
Compilation message
strah.cpp: In function 'int main()':
strah.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
~^~~
strah.cpp:40:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
~^~~
strah.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<=n; i++) for (int j=1; j<=i; j++) sum[i]+=j*(i-j+1ll);
~^~~
strah.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<=n; i++){
~^~~
strah.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=1; j<=m; j++) for (L[j]=j-1; L[j] && A[i][L[j]]>=A[i][j]; L[j]=L[L[j]]);
~^~~
strah.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=1; j<=m; j++) ans+=1ll*C2(A[i][j])*(sum[R[j]-L[j]-1]-sum[R[j]-j-1]-sum[j-L[j]-1]);
~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
2 |
Correct |
8 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
2 |
Correct |
9 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1920 KB |
Output is correct |
2 |
Correct |
8 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
7160 KB |
Output is correct |
2 |
Correct |
100 ms |
12280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
10872 KB |
Output is correct |
2 |
Correct |
152 ms |
15616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
7168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
8704 KB |
Output is correct |
2 |
Correct |
106 ms |
15096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
16208 KB |
Output is correct |
2 |
Correct |
171 ms |
16120 KB |
Output is correct |