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>
#define ll long long
using namespace std;
ll n,m;
ll grid[1005][1005];
ll solve(int target) {
ll cnt = 0;
for (int l=1;l<=m;l++) {
vector<ll> heights(n+1, 0);
for (int r=l;r<=m;r++) {
for (int i=1;i<=n;i++) {
if (grid[i][r] == target) {
heights[i]++;
} else {
heights[i] = 0;
}
}
ll cur = 0;
for (int i=1;i<=n;i++) {
if (heights[i] == r - l + 1) {
cur++;
}
else {
cnt += 1LL*cur*(cur+1) /2;
cur = 0;
}
}
cnt += cur*(cur+1) / 2;
}
}
return cnt;
}
int main() {
cin >> n >> m;
for (int i=1;i<=n;i++) {
for (int j=1;j<=m;j++) {
cin >> grid[i][j];
}
}
cout << solve(1) + solve(2);
return 0;
}
# | 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... |