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;
const int N=1e3+7, inf=1e9+7;
int m, n, a[N][N], b[N][N];
long long res=0;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>m>>n;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
cin>>a[i][j];
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++) b[i][j]=1;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
{
if(a[i][j]==a[i-1][j]) b[i][j]=b[i-1][j]+1;
}
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
{
int tmp=inf;
for(int k=j; k>=1; k--)
{
if(a[i][k]!=a[i][k+1]&&k!=j) break;
tmp=min(tmp, b[i][k]);
res+=tmp;
}
}
cout<<res;
}
# | 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... |