# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
854651 |
2023-09-28T10:22:46 Z |
DAleksa |
Strah (COCI18_strah) |
C++17 |
|
1000 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, m;
string a[N];
long long dp[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;
}
}
int mn_left[n][n], mn_right[n][n];
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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
10076 KB |
Output is correct |
2 |
Correct |
62 ms |
10072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
10180 KB |
Output is correct |
2 |
Correct |
63 ms |
10072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
10352 KB |
Output is correct |
2 |
Correct |
61 ms |
10180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
82124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
186460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1036 ms |
95400 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
209528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
220 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |