# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
854653 |
2023-09-28T10:24:10 Z |
DAleksa |
Strah (COCI18_strah) |
C++17 |
|
1000 ms |
71680 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, m;
string a[N];
long long dp[N][N];
int mn_left[N][N], mn_right[N][N];
long long calc(int l, int r) {
if(l == r) {
long long ans = 0;
int lst = -1;
for(int i = 0; i < n; i++) {
if(a[i][l] == '#') lst = i;
ans += (i - lst) * 1LL * (i - lst + 1) / 2;
}
return ans;
}
int mid = (l + r) / 2;
vector<int> left(n, 0), right(n, 0);
for(int i = 0; i < n; i++) {
for(int j = mid; j >= l; j--) {
if(a[i][j] == '.') left[i]++;
else break;
}
for(int j = mid + 1; j <= r; j++) {
if(a[i][j] == '.') right[i]++;
else break;
}
}
for(int i = 0; i < n; i++) {
mn_left[i][i] = left[i];
mn_right[i][i] = right[i];
}
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
mn_left[i][j] = min(mn_left[i][j - 1], left[j]);
mn_right[i][j] = min(mn_right[i][j - 1], right[j]);
}
}
long long ans = 0;
for(int i = 0; i < n; i++) for(int j = i; j < n; j++) ans += (j - i + 1) * 1LL * dp[mn_left[i][j]][mn_right[i][j]];
return ans + calc(l, mid) + calc(mid + 1, r);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++) for(int j = 1; j <= m; j++) dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + i + j;
for(int i = 0; i < n; i++) cin >> a[i];
cout << calc(0, m - 1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
10840 KB |
Output is correct |
2 |
Correct |
48 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
10952 KB |
Output is correct |
2 |
Correct |
47 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
10844 KB |
Output is correct |
2 |
Correct |
48 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
37868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
58296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1028 ms |
49152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
877 ms |
32612 KB |
Output is correct |
2 |
Execution timed out |
1012 ms |
63772 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
71680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |