//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
char getcharr() {
char ch;
cin >> ch;
return ch;
}
#define ONLINE_JUDGE
void solve() {
int n, m;
cin >> n >> m;
vector <vector <int>> pref(n +1, vector <int> (m +1, 0));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(getcharr() == '#') {
pref[i][j]++;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
pref[i][j] += pref[i][j -1] + pref[i -1][j] - pref[i -1][j -1];
}
}
auto get = [&](int x1, int y1, int x2, int y2) -> int {
x1--;
y1--;
return pref[x2][y2] + pref[x1][y1] - pref[x2][y1] - pref[x1][y2];
};
auto check = [&](int k, int l, int a, int mid) -> bool {
return get(k, l, a, mid) == 0;
};
i64 res = 0;
for(int k = 1; k <= n; k++) {
for(int l = 1; l <= m; l++) {
for(int a = k; a <= n; a++) {
int _l = l, _r = m, ans = m;
while(_l <= _r) {
//cerr << _l << " " << _r;
int mid = (_l + _r) / 2;
if(check(k, l, a, mid)) {
//cerr << "...";
_l = mid +1;
ans = mid;
} else {
//cerr << "!!!";
_r = mid -1;
}
//cerr << "\n";
}
if(check(k, l, a, ans)) {
//cerr << k << " " << l << " " << a << " " << ans << " :: ";
ans = ans - l +1;
i64 x = (a - k +1) * 1LL * (ans) * (ans +1) / 2;
//cerr << x << "\n";
res += x;
}
}
}
}
cout << res << "\n";
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
804 KB |
Output is correct |
2 |
Correct |
111 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
604 KB |
Output is correct |
2 |
Correct |
111 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
800 KB |
Output is correct |
2 |
Correct |
112 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1099 ms |
10072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
6492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1020 ms |
1624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
15964 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |