이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "grader.cpp"
#include "rect.h"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,m;
const int N=2500;
int a[N][N],l[N][N],r[N][N];
int mx[N];
int L[N],R[N];
int x[N],y[N];
int A[N][N];
int s(int x1,int y1,int x2,int y2){
x1--;
y1--;
return A[x2][y2]-A[x1][y2]-A[x2][y1]+A[x1][y1];
}
int d[N][N],rr[N][N];
ll count_rectangles(vector<vector<int> > vv) {
int Mx=0;
n=vv.size(),m=vv[0].size();
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
a[i][j]=vv[i-1][j-1];
A[i][j]=a[i][j]+A[i][j-1];
Mx=max(Mx,a[i][j]);
}
for (int j=1;j<=m;j++) A[i][j]+=A[i-1][j];
}
for (int i=1;i<=n;i++){
rr[i][m+1]=m+1;
for (int j=m;j>=1;j--){
if (a[i][j]) rr[i][j]=j;
else rr[i][j]=rr[i][j+1];
}
}
for (int i=1;i<=m;i++){
d[n+1][i]=n+1;
for (int j=n;j>=1;j--){
if (a[j][i]) d[j][i]=j;
else d[j][i]=d[j+1][i];
}
}
if (Mx<=1){
ll res=0ll;
for (int i=1;i<=n-2;i++){
for (int j=1;j<=m-2;j++){
if (a[i+1][j+1]) continue;
if (a[i][j]==0) continue;
int x=d[i+1][j+1];
int y=rr[i+1][j+1];
if (s(i,j,x,j)==x-i+1 && s(i,j,i,y)==y-j+1 && s(x,j,x,y)==y-j+1 && s(i,y,x,y)==x-i+1 && s(i+1,j+1,x-1,y-1)==0) res++;
}
}
return res;
}
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
l[i][j]=0;
for (int t=j-1;t>=1;t=l[i][t]){
if (a[i][t]>=a[i][j]){
l[i][j]=t;
break;
}
}
}
for (int j=m;j>=1;j--){
r[i][j]=m+1;
for (int t=j+1;t<=m;t=r[i][t]){
if (a[i][t]>=a[i][j]){
r[i][j]=t;
break;
}
}
}
}
ll res=0ll;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) mx[j]=0,L[j]=1,R[j]=m;
for (int j=i+2;j<=n;j++){
for (int t=1;t<=m;t++) {
mx[t]=max(mx[t],a[j-1][t]);
L[t]=max(L[t],l[j-1][t]);
R[t]=min(R[t],r[j-1][t]);
}
vector<int>bad;
bad.push_back(0);
for (int t=1;t<=m;t++){
if (mx[t]>=min(a[i][t],a[j][t])) bad.push_back(t);
}
bad.push_back(m+1);
for (int t=1;t<bad.size();t++){
for (int k=bad[t-1];k<bad[t];k++){
y[k]=min(R[k],bad[t]);
}
for (int k=bad[t-1]+1;k<=bad[t];k++){
x[k]=max(L[k],bad[t-1]);
}
}
for (int t=1;t<=m;t++){
if (t+2>y[t]) continue;
if (x[y[t]]<=t) res++;
// for (int k=t+2;k<y[t];k++){
// if (t>=x[k]) res++;
// }
}
for (int t=1;t<=m;t++){
if (t-2<x[t]) continue;
if (y[x[t]]>t) res++;
}
}
}
// x[k]==t
return res;
}
/**
6 5
4 8 7 5 6
7 4 10 3 5
9 7 20 14 2
9 14 7 3 6
5 7 5 2 7
4 5 13 5 6
**/
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int t=1;t<bad.size();t++){
| ~^~~~~~~~~~~
# | 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... |