#include <bits/stdc++.h>
#define ll long long
#define co cout<<
using namespace std;
//stuff
ll n,m;
ll arr[1005][1005]={};
ll l[1005][1005]={},r[1005][1005]={},u[1005][1005]={};
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>arr[i][j];
}
}
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(arr[i][j]==arr[i-1][j]) u[i][j]=u[i-1][j]+1;
else u[i][j]=1;
if(arr[i][j]==arr[i][j-1]&&u[i][j]<u[i][j-1]) l[i][j]=l[i][j-1]+1;
else l[i][j]=1;
}
for(int j=m;j>=1;j--){
if(arr[i][j]==arr[i][j+1]&&u[i][j]<=u[i][j+1]) r[i][j]=r[i][j+1]+1;
else r[i][j]=1;
ans+=u[i][j]*l[i][j]*r[i][j];
}
}
co ans;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int _=1;
// cin>>_;
while(_--) solve();
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... |