# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
464671 |
2021-08-13T16:10:42 Z |
Hamed5001 |
Strah (COCI18_strah) |
C++14 |
|
1000 ms |
55548 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
dp[i][j] = potential value in range (i, j) -> (N, M);
dp[i][j] = dp[i+1][j] + dp[i][j+1] - dp[i+1][j+1] + (sum())
*/
const int mxN = 2e3+10;
int N, M;
char land[mxN][mxN];
int cum[mxN][mxN];
int query(int r1, int c1, int r2, int c2) {
return cum[r2][c2] + cum[r1-1][c1-1] - cum[r2][c1-1] - cum[r1-1][c2];
}
bool ok(int i, int j, int ii, int mid) {
return query(i, j, ii, mid) == 0;
}
int maxLen(int i, int ii, int j) {
int l = 1, r = M, mid;
while(l < r) {
mid = (l + r + 1) >> 1;
if (ok(i, j, ii, mid)) l = mid;
else r = mid - 1;
}
return l - j + 1;
}
ll calc(int i, int j) {
ll ret = 0;
if (land[i][j] == '#')
return ret;
for (int ii = i; ii <= N && land[ii][j] != '#'; ii++) {
ll len = maxLen(i, ii, j);
ret += (len*(len+1)/2) * (ii-i+1);
}
return ret;
}
void solve() {
cin >> N >> M;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
cin >> land[i][j];
cum[i][j] += ((land[i][j] == '#') + cum[i-1][j] + cum[i][j-1] - cum[i-1][j-1]);
}
}
vector<vector<ll>> dp(mxN, vector<ll>(mxN, 0));
dp[N][M] = (land[N][M] != '#');
for (int i = N; i; i--) {
for (int j = M; j; j--) {
dp[i][j] = dp[i+1][j] + dp[i][j+1] - dp[i+1][j+1] + calc(i, j);
}
}
cout << dp[1][1];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
32076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
31972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
34368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
34156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
34280 KB |
Output is correct |
2 |
Incorrect |
63 ms |
34212 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
217 ms |
41292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
494 ms |
47540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
41840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
44208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
55548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |