#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int, int> pii ;
typedef pair<int, long long> pil ;
typedef pair<long long, int> pli ;
typedef pair<long long, long long> pll ;
typedef vector<int> vi ;
typedef vector<long long> vll ;
#define bitc(n) (__builtin_popcountll(n))
#define clz(n) (__builtin_clzll(n))
#define ctz(n) (__builtin_ctzll(n))
#define lg(n) (63 - __builtin_clzll(n))
#define MASK(k) (1ll << (k))
#define getbit(n, k) ((n) >> (k) & 1)
#define flipbit(n, k) ((n) ^ (1ll << (k)))
#define ton(n, k) ((n) | (1ll << (k)))
#define toff(n, k) ((n) & ~(1ll << (k)))
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define lwb lower_bound
#define upb upper_bound
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define taskname "input"
template<class X, class Y> bool maximize(X &x, const Y &y) {return (x < y ? x = y, true : false) ;}
template<class X, class Y> bool minimize(X &x, const Y &y) {return (x > y ? x = y, true : false) ;}
template<class X>
void remove_dup(vector<X> &ve) {
sort(ve.begin(), ve.end()) ;
ve.resize(unique(ve.begin(), ve.end()) - ve.begin()) ;
}
const ll mod = 1e9 + 7 ;
const ll INF = 1e18 ;
const int inf = 1e9 ;
const int N = 2e3 + 5 ;
/* Some Peach Tea Is Great ;-; */
/* Author : Tuandq */
int n, m ;
char c[N][N] ;
namespace sub3 {
int h[N], l[N], r[N] ;
void solve() {
ll res = 0 ;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
h[j] = (c[i][j] == '.' ? h[j] + 1 : 0) ;
}
stack<int> s ;
s.emplace(0) ;
for(int j = 1; j <= m; j ++) {
while(!s.empty() && h[s.top()] > h[j]) s.pop() ;
l[j] = s.top() ; s.emplace(j) ;
}
while(!s.empty()) s.pop() ;
h[m + 1] = -1 ;
s.emplace(m + 1) ;
for(int j = m; j > 0; j --) {
while(!s.empty() && h[s.top()] >= h[j]) s.pop() ;
r[j] = s.top() ; s.emplace(j) ;
}
for(int j = 1; j <= m; j ++) {
int lenL = j - l[j] ;
int lenR = r[j] - j ;
ll sumH = 1ll * h[j] * (h[j] + 1) >> 1ll ;
ll sumL = 1ll * lenL * (lenL + 1) >> 1ll ;
ll sumR = 1ll * lenR * (lenR + 1) >> 1ll ;
res += 1ll * sumH * (sumL * lenR + sumR * lenL - lenL * lenR) ;
// cerr << i << ' ' << j << ' ' << lenL << ' ' << lenR << ' ' << h[j] << ' ' << res << endl ;
}
}
cout << res ;
}
}
signed main() {
ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
if(fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin) ;
freopen(taskname".out", "w", stdout) ;
}
cin >> n >> m ;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cin >> c[i][j] ;
}
}
return sub3::solve(), 0 ;
}
컴파일 시 표준 에러 (stderr) 메시지
strah.cpp: In function 'int main()':
strah.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(taskname".inp", "r", stdin) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strah.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(taskname".out", "w", stdout) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |