이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
#define P push
#define MP make_pair
#define F first
#define S second
typedef long long ll;
long long count_rectangles(vector<vector<int> > a) {
int n=a.size();
int m=a[0].size();
int maxi=-1;
for(int i=0;i<n;i++)for(int j=0;j<m;j++)maxi=max(maxi,a[i][j]);
ll ans=0;
if(maxi<2){
bool flood[n][m];memset(flood,false,sizeof(flood));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(flood[i][j] || a[i][j]!=0)continue;
flood[i][j];
queue<pair<int,int> > q;q.P(MP(i,j));
int up,down,left,right;
up=left=3000;
down=right=-1;
int co=0;
while(!q.empty()){
int c=q.front().F,d=q.front().S;q.pop();
up=min(up,c);down=max(down,c);
left=min(left,d);right=max(right,d);
co++;
if(d<m-1 && a[c][d+1]==0 && !flood[c][d+1]){
flood[c][d+1];
q.P(MP(c,d+1));
}
if(d>0 && a[c][d-1]==0 && !flood[c][d-1]){
flood[c][d-1];
q.P(MP(c,d-1));
}
if(c<n-1 && a[c+1][d]==0 && !flood[c+1][d]){
flood[c+1][d];
q.P(MP(c+1,d));
}
if(c>0 && a[c-1][d]==0 && !flood[c-1][d]){
flood[c-1][d];
q.P(MP(c-1,d));
}
}
if(up==0 || down==n-1 || left==0 || right==m-1)continue;
if(co==(down-up+1)*(right-left+1))ans++;
}
}
return ans;
}
for(int i=0;i<n;i++){
int colmax[m];memset(colmax,-1,sizeof(colmax));
bool colvalid[m];memset(colvalid,false,sizeof(colvalid));
for(int j=i+2;j<n;j++){
for(int k=0;k<m;k++){
colmax[k]=max(colmax[k],a[j-1][k]);
if(colmax[k]>=a[i][k] || colmax[k]>=a[j][k])colvalid[k]=false;
else colvalid[k]=true;
}
for(int k=0;k<m;k++){
int rowmax[n];memset(rowmax,-1,sizeof(rowmax));
for(int l=k+2;l<m;l++){
if(colvalid[l-1]==false)break;
bool ok=true;
for(int p=i+1;p<=j-1;p++){
rowmax[p]=max(rowmax[p],a[p][l-1]);
if(rowmax[p]>=a[p][k] || rowmax[p]>=a[p][l])ok=false;
}
if(ok)ans++;
}
}
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:22:15: warning: statement has no effect [-Wunused-value]
22 | flood[i][j];
| ~~~~~~~~~~^
rect.cpp:37:19: warning: statement has no effect [-Wunused-value]
37 | flood[c][d+1];
| ~~~~~~~~~~~~^
rect.cpp:41:19: warning: statement has no effect [-Wunused-value]
41 | flood[c][d-1];
| ~~~~~~~~~~~~^
rect.cpp:45:19: warning: statement has no effect [-Wunused-value]
45 | flood[c+1][d];
| ~~~~~~~~~~~~^
rect.cpp:49:19: warning: statement has no effect [-Wunused-value]
49 | flood[c-1][d];
| ~~~~~~~~~~~~^
# | 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... |