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;
int n,m, arr[1001][1001], dp1[1001][1001], dp2[1001][1001], ans;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for(int i = 1; i<=n; ++i) for(int j = 1; j<=m; ++j) cin >> arr[i][j];
for(int i = 1; i<=n; ++i){
for(int j = 1; j<=m; ++j){
if(arr[i][j] == arr[i][j - 1]) dp1[i][j] = dp1[i][j - 1] + 1;
else dp1[i][j] = 1;
}
}
for(int j = 1; j<=m; ++j){
for(int i = 1; i<=n; ++i){
if(arr[i][j] == arr[i - 1][j]) dp2[i][j] = dp2[i - 1][j] + 1;
else dp2[i][j] = 1;
}
}
for(int i = 1; i<=n; ++i){
for(int j = 1; j<=m; ++j){
int M = dp1[i][j], N = dp2[i][j], k = j - 1;
ans+=N;
while(k > j - M){
N = min(N, dp2[i][k]);
ans+=N;
k--;
}
}
}
cout << ans;
}
# | 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... |