이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "rect.h"
using namespace std;
using ll=long long;
const ll TAILLE_MAX=2505;
ll rep,nbLig,nbCol;
ll val[TAILLE_MAX][TAILLE_MAX];
ll limite[TAILLE_MAX][TAILLE_MAX][2];
ll limCalc[TAILLE_MAX][2];
bool checkCol(ll col,ll ligHaut,ll ligBas) {
for (ll i=ligHaut;i<=ligBas;i++) {
if (val[i][col]>=val[ligHaut-1][col] or val[i][col]>=val[ligBas+1][col]) {
return false;
}
}
return true;
}
void calc(ll ligHaut,ll ligBas,ll colGau,ll colDroi) {
//cout<<ligHaut<<" "<<ligBas<<" "<<colGau<<" "<<colDroi<<" : ";
for (ll i=colGau-1;i<=colDroi+1;i++) {
limCalc[i][0]=0;
for (ll j=ligHaut;j<=ligBas;j++) {
limCalc[i][0]=max(limCalc[i][0],limite[j][i][0]);
}
limCalc[i][1]=nbCol-1;
for (ll j=ligHaut;j<=ligBas;j++) {
limCalc[i][1]=min(limCalc[i][1],limite[j][i][1]);
}
//cout<<i<<" "<<limCalc[i][0]<<" "<<limCalc[i][1]<<" ";
}
//cout<<endl;
for (ll i=colGau;i<=colDroi;i++) {
for (ll j=i;j<=colDroi;j++) {
if (limCalc[i-1][1]>=j and limCalc[j+1][0]<=i) {
//cout<<"! "<<ligHaut<<" "<<ligBas<<" "<<i<<" "<<j<<endl;
rep++;
}
}
}
}
ll count_rectangles(vector<vector<int>> a) {
nbLig=a.size();
nbCol=a[0].size();
if (nbLig<=2 or nbCol<=2) {
return 0;
}
for (ll i=0;i<nbLig;i++) {
for (ll j=0;j<nbCol;j++) {
val[i][j]=a[i][j];
}
}
ll deb,pos;
for (ll i=0;i<nbLig;i++) {
for (ll j=0;j<nbCol;j++) {
pos=j;
while (pos>0 and val[i][j]>val[i][pos-1]) {
pos--;
}
limite[i][j][0]=pos;
pos=j;
while (pos<nbCol-1 and val[i][j]>val[i][pos+1]) {
pos++;
}
limite[i][j][1]=pos;
//cout<<i<<" "<<j<<" : "<<limite[i][j][0]<<" "<<limite[i][j][1]<<endl;
}
}
for (ll ligHaut=1;ligHaut<nbLig-1;ligHaut++) {
for (ll ligBas=ligHaut;ligBas<nbLig-1;ligBas++) {
pos=1;
while (pos<nbCol-1) {
deb=pos;
while (pos<nbCol-1 and checkCol(pos,ligHaut,ligBas)) {
pos++;
}
if (pos>deb) {
calc(ligHaut,ligBas,deb,pos-1);
}
pos++;
}
}
}
return rep;
}
# | 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... |