이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 >> m >> n;
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... |