#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
vector<vector<int>>a;
int n, m;
namespace sub123{
bool check(int x, int y, int u, int v){
for(int i = x; i <= u; i++){
for(int j = y; j <= v; j++){
if(a[i][j] >= min({a[x - 1][j], a[u + 1][j], a[i][y - 1], a[i][v + 1]})){
return false;
}
}
}
return true;
}
ll solve(){
int ans = 0;
for(int x = 1; x < n; x++){
for(int y = 1; y < m; y++){
for(int u = x; u + 1 < n; u++){
for(int v = y; v + 1 < m; v++){
if(check(x, y, u, v)){
ans++;
}
}
}
}
}
return ans;
}
}
namespace sub5{
ll solve(){
int ans = 0;
for(int l = 1; l < m; l++){
for(int r = l, mv = 0; r + 1 < m; r++){
maximize(mv, a[1][r]);
if(a[1][r] > min(a[0][r], a[2][r]) || mv >= a[1][l - 1]){
break;
}
if(mv < a[1][r + 1]){
ans++;
}
}
}
return ans;
}
}
ll count_rectangles(vector<vector<int>>_a){
swap(a, _a);
if(max(n = a.size(), m = a[0].size()) <= 200){
return sub123::solve();
}
if(n <= 3){
return sub5::solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
64 | }
| ^| # | 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... |