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<iostream>
#include<algorithm>
using namespace std;
const int MAX_N=1000;
int n,m,a[MAX_N][MAX_N],h[MAX_N][MAX_N+1];
long long int ans;
int main(){
cin >> n >> m;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
cin >> a[i][j];
fill(h[0],h[0]+m,1);
for(int i=1; i<n; i++)
for(int j=0; j<m; j++)
h[i][j]=(a[i][j]==a[i-1][j])*h[i-1][j]+1;
int st1[MAX_N],st2[MAX_N];
for(int i=0; i<n; i++){
for(int j=0,top=0; j<=n; j++){
while(top&&(st1[top-1]>h[i][j]||a[i][st2[top-1]]!=a[i][j]))
ans+=st1[--top]*(j-st2[top]);
st1[top]=h[i][j];
st2[top++]=j;
}
}
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... |