# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250676 | kingfran1907 | Bob (COCI14_bob) | C++14 | 162 ms | 17912 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;
typedef long long llint;
const int maxn = 1010;
int n, m;
int niz[maxn][maxn];
int cn[maxn][maxn];
vector< int > v;
int sol[maxn];
stack< llint > p, q;
llint cal() {
while (!q.empty()) {q.pop(); p.pop();}
llint out = 0;
llint tren = 0;
for (int i = 0; i < v.size(); i++) {
llint cnt = 1;
while (!p.empty() && p.top() >= v[i]) {
llint ac = q.top(); q.pop();
llint val = p.top(); p.top();
cnt += ac;
tren -= ac * (val - v[i]);
}
tren += v[i];
out += tren;
}
v.clear();
return out;
}
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]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i == 0) cn[i][j] = 1;
else {
if (niz[i][j] == niz[i - 1][j]) cn[i][j] = 1 + cn[i - 1][j];
else cn[i][j] = 1;
}
}
}
llint sol = 0;
for (int i = 0; i < n; i++) {
v.push_back(cn[i][0]);
for (int j = 1; j < m; j++) {
if (niz[i][j - 1] != niz[i][j]) sol += cal();
v.push_back(cn[i][j]);
}
sol += cal();
}
printf("%d", 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... |