# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
206315 | 2020-03-03T01:03:13 Z | luciocf | Strah (COCI18_strah) | C++14 | 165 ms | 4600 KB |
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; const int maxn = 1e3+10; typedef pair<int, int> pii; typedef long long ll; int n, m; char tab[maxn][maxn]; int h[maxn][maxn]; int l[maxn], r[maxn]; ll S[maxn]; int main(void) { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf(" %c", &tab[i][j]); for (int i = 1; i <= max(n, m); i++) S[i] = S[i-1] + (1ll*i*(i+1))/2ll; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (tab[i][j] == '#') h[i][j] = 0; else h[i][j] = h[i-1][j]+1; } } ll ans = 0; for (int i = 1; i <= n; i++) { stack<pii> stk; for (int j = 1; j <= m; j++) { while (stk.size() && stk.top().ff >= h[i][j]) stk.pop(); if (stk.size()) l[j] = stk.top().ss+1; else l[j] = 1; stk.push({h[i][j], j}); } while (stk.size()) stk.pop(); for (int j = m; j >= 1; j--) { while (stk.size() && stk.top().ff > h[i][j]) stk.pop(); if (stk.size()) r[j] = stk.top().ss-1; else r[j] = m; stk.push({h[i][j], j}); } for (int j = 1; j <= m; j++) { int a = j-l[j], b = r[j]-j; int tot = r[j]-l[j]+1; ans += 1ll*(h[i][j]*(h[i][j]+1)/2ll)*(S[tot] - S[a] - S[b]); } } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 1784 KB | Output is correct |
2 | Correct | 15 ms | 1784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 1784 KB | Output is correct |
2 | Correct | 14 ms | 1784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1784 KB | Output is correct |
2 | Correct | 14 ms | 1784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 121 ms | 4600 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 120 ms | 1272 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 165 ms | 4600 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 15 ms | 1272 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 146 ms | 1272 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |