# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200554 | Kalam | Bob (COCI14_bob) | C++11 | 207 ms | 18424 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.
// KALAM
# include<bits/stdc++.h>
# define debug(x) cerr << #x << " = " << x << endl
using namespace std;
const int N = 1000 + 77;
int n , m , a[N][N] , up[N][N] , c[N];
int cur , f[N] , L[N] , R[N];
long long A;
inline void Calc() {
f[0] = f[cur + 1] = 0;
for(int i = 1;i <= cur;++ i) {
L[i] = i - 1;
while(f[L[i]] >= f[i])
L[i] = L[L[i]];
}
for(int i = cur;i > 0;-- i) {
R[i] = i + 1;
while(f[R[i]] > f[i])
R[i] = R[R[i]];
A += 1ll * (i - L[i]) * (R[i] - i) * f[i];
}
cur = 0;
}
int main() {
scanf("%d %d" , & n , & m);
for(int i = 1;i <= n;++ i) {
for(int j = 1;j <= m;++ j)
scanf("%d" , & a[i][j]) , up[i][j] = (a[i][j] == a[i - 1][j] ? up[i - 1][j] : i - 1) , c[j] = i - up[i][j];
f[++ cur] = c[1];
for(int j = 2;j <= m;++ j) {
if(a[i][j] != a[i][j - 1])
Calc();
f[++ cur] = c[j];
}
Calc();
}
printf("%lld\n" , A);
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... |