# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
474252 | 2021-09-17T14:53:35 Z | Neos | Bob (COCI14_bob) | C++14 | 232 ms | 17848 KB |
#include <cstdio> #include <stack> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 1005; int n, m, k; int a[MAXN][MAXN]; int s[MAXN][MAXN]; typedef long long llint; struct t{ int cnt; int v, h; llint ms; t (int _cnt = 0, int _v = 0, int _h = 0, llint _ms = 0){ cnt = _cnt; v = _v; h = _h; ms = _ms; } }; llint ans; int main (void){ scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]); for (int i = 0; i < n; ++i){ stack < t > S; S.push(t(0, -1, 0, 0)); for (int j = 0; j < m; ++j){ s[i][j] = 1; if (i > 0 && a[i-1][j] == a[i][j]) s[i][j] += s[i-1][j]; int sum = 1; while (S.top().v == a[i][j] && S.top().h >= s[i][j]){ sum += S.top().cnt; S.pop(); } llint my_s = sum * (llint)s[i][j]; if (S.top().v == a[i][j]) my_s += S.top().ms; ans += my_s; S.push(t(sum, a[i][j], s[i][j], my_s)); } } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 4724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 5104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 5364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 5264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 149 ms | 14796 KB | Output is correct |
2 | Correct | 113 ms | 10092 KB | Output is correct |
3 | Correct | 116 ms | 10052 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 165 ms | 17848 KB | Output is correct |
2 | Correct | 123 ms | 10052 KB | Output is correct |
3 | Correct | 119 ms | 10096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 232 ms | 17652 KB | Output is correct |
2 | Correct | 111 ms | 9960 KB | Output is correct |
3 | Correct | 113 ms | 9992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 169 ms | 17776 KB | Output is correct |
2 | Correct | 116 ms | 10052 KB | Output is correct |
3 | Correct | 113 ms | 9984 KB | Output is correct |