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;
const int N = 1005;
int n, m;
int a[N][N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cin >> a[i][j];
}
ll ans = 0;
for (int x = 1; x <= n; x++) {
vector<int> d(m + 1, 1);
for (int y = x; y <= n; y++) {
if (y > x) {
for (int j = 1; j <= m; j++) {
d[j] &= (a[y][j] == a[y - 1][j]);
}
}
for (int j = 1; j <= m; j++) {
if (!d[j]) continue;
int t = j;
while (t <= m && d[t] && a[y][t] == a[y][j]) t++;
ans += 1LL * (t - j) * (t - j + 1) / 2;
j = t - 1;
}
}
}
cout << ans;
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... |