# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042004 |
2024-08-02T12:01:09 Z |
Blagoj |
Bob (COCI14_bob) |
C++17 |
|
73 ms |
37700 KB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
const int mxn = 1e3 + 100;
ll a[mxn][mxn], h[mxn][mxn], c[mxn][mxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
h[i][j] = 1;
if (a[i][j] == a[i - 1][j]) h[i][j] += h[i - 1][j];
}
}
stack<int> s;
ll ans = 0;
for (int i = 1; i <= n; i++) {
while (s.size()) s.pop();
for (int j = 1; j <= m; j++) {
if (a[i][j] == a[i][j - 1]) {
while (s.size() && h[i][s.top()] > h[i][j]) s.pop();
c[i][j] = c[i][s.top()] + (j - s.top()) * h[i][j];
ans += c[i][j];
s.push(j);
}
else {
c[i][j - 1] = 0;
h[i][j - 1] = 0;
c[i][j] = h[i][j];
ans += c[i][j];
s.push(j - 1);
s.push(j);
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
20180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
20060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
34652 KB |
Output is correct |
2 |
Correct |
37 ms |
29948 KB |
Output is correct |
3 |
Correct |
54 ms |
29900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
37700 KB |
Output is correct |
2 |
Correct |
35 ms |
29768 KB |
Output is correct |
3 |
Correct |
36 ms |
29784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
37320 KB |
Output is correct |
2 |
Correct |
38 ms |
29760 KB |
Output is correct |
3 |
Correct |
35 ms |
29908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
37460 KB |
Output is correct |
2 |
Correct |
37 ms |
29912 KB |
Output is correct |
3 |
Correct |
35 ms |
29772 KB |
Output is correct |