# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
854345 | | mzh | Bob (COCI14_bob) | C++17 | | 106 ms | 18708 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n = nxt(), m = nxt();
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
generate(all(a[i]), nxt);
}
vector<vector<int>> streak(n, vector<int>(m, 1));
for (int i = 0; i < n; i++) {
for (int j = 1; j < m; j++) {
if (a[i][j] == a[i][j - 1]) {
streak[i][j] += streak[i][j - 1];
}
}
}
ll ans = 0;
vector<priority_queue<int>> lengths(m);
vector<int> sum(m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i > 0 && a[i][j] != a[i - 1][j]) {
lengths[j] = priority_queue<int>();
sum[j] = 0;
}
while (!lengths[j].empty() && lengths[j].top() > streak[i][j]) {
sum[j] -= lengths[j].top() - streak[i][j];
lengths[j].pop();
}
lengths[j].push(streak[i][j]);
sum[j] += streak[i][j];
ans += sum[j];
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |