# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250680 | kingfran1907 | Bob (COCI14_bob) | C++14 | 179 ms | 10232 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;
const int maxn = 1010;
int n, m;
int niz[maxn][maxn];
int pref[maxn][maxn];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
scanf("%d", &niz[i][j]);
long long sol = 0;
for (int i = 0; i < n; i++) {
vector<int> his;
for (int j = 0; j < m; j++) {
if (i == 0) pref[i][j] = 1;
else pref[i][j] = (niz[i - 1][j] == niz[i][j] ? pref[i - 1][j] + 1 : 1);
his.push_back(pref[i][j]);
}
stack< pair<int, pair<int, long long> > > s;
//printf("histogram: "); for (int i = 0; i < m; i++) printf("%d ", his[i]); printf("\n");
for (int j = 0; j < m; j++) {
if (j > 0 && niz[i][j] != niz[i][j - 1]) {while (!s.empty()) s.pop();}
int cnt = 1;
while (!s.empty() && his[s.top().first] >= his[j]) {
cnt += s.top().second.first;
s.pop();
}
//printf("debug: %d %d\n", his[j], cnt);
long long tren = (long long)cnt * his[j];
if (!s.empty()) tren += s.top().second.second;
sol += tren;
s.push(make_pair(j, make_pair(cnt, tren)));
}
}
printf("%lld", sol);
return 0;
}
Compilation message (stderr)
# | 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... |