# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
464692 |
2021-08-13T17:09:39 Z |
Hamed5001 |
Strah (COCI18_strah) |
C++14 |
|
1000 ms |
98884 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;
ll N, M;
char land[mxN][mxN];
ll cum[mxN][mxN], nxt[mxN][mxN];
ll calc(int i, int j) {
ll ret = 0;
if (land[i][j] == '#')
return ret;
ll pos = M+1;
for (ll ii = i; ii <= N && land[ii][j] != '#'; ii++) {
pos = min(pos, nxt[ii][j]);
ll len = pos - 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]);
}
}
for (int i = 1; i <= N; i++) {
int lst = M+1;
for (int j = M; j; j--) {
if (land[i][j] == '#')
lst = j;
nxt[i][j] = lst;
}
}
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 |
Correct |
14 ms |
32076 KB |
Output is correct |
2 |
Correct |
14 ms |
32076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
32096 KB |
Output is correct |
2 |
Correct |
15 ms |
32120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
36368 KB |
Output is correct |
2 |
Correct |
23 ms |
36460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
36428 KB |
Output is correct |
2 |
Correct |
23 ms |
36456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
36444 KB |
Output is correct |
2 |
Correct |
24 ms |
36396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
56644 KB |
Output is correct |
2 |
Correct |
286 ms |
82628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
76384 KB |
Output is correct |
2 |
Correct |
433 ms |
96792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
660 ms |
60516 KB |
Output is correct |
2 |
Correct |
311 ms |
85832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
54340 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
94800 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
98884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |