이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
//#include "grader.cpp"
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>>RE(2501);
vector<vector<pair<int,int>>>RE2(2501);
int sparseR[2501][2501][12],sparseC[2501][2501][12],n,m,LOG[2501];
vector<vector<int>>A;
bool DP[701][701][701],DP2[701][701][701];
void BUILD(){
for(int i=0;i<n;i++)
for(int l=0;l<m;l++)
sparseR[i][l][0]=A[i][l];
for(int i=0;i<n;i++)
for(int l=0;l<m;l++)
sparseC[l][i][0]=A[i][l];
for(int i=0;i<n;i++){
for(int x=1;x<12;x++){
for(int l=0;l+(1<<(x))<=m;l++){
sparseR[i][l][x]=max(sparseR[i][l][x-1],sparseR[i][l+(1<<(x-1))][x-1]);
}
}
}
for(int i=0;i<m;i++){
for(int x=1;x<12;x++){
for(int l=0;l+(1<<(x))<=n;l++){
sparseC[i][l][x]=max(sparseC[i][l][x-1],sparseC[i][l+(1<<(x-1))][x-1]);
}
}
}
}
bool check(int x1,int x2,int y1,int y2){
int F=max(sparseC[y1][x1][LOG[x2-x1+1]],sparseC[y1][x2-(1<<LOG[x2-x1+1])+1][LOG[x2-x1+1]]);
if((F>=A[x1-1][y1])||(F>=A[x2+1][y1]))
return 0;
return 1;
}
bool check2(int x1,int x2,int y1,int y2){
int F=max(sparseR[x1][y1][LOG[y2-y1+1]],sparseR[x1][y2-(1<<LOG[y2-y1+1])+1][LOG[y2-y1+1]]);
if((F>=A[x1][y1-1])||(F>=A[x1][y2+1]))
return 0;
return 1;
}
long long count_rectangles(vector<vector<int>>a){
LOG[1]=0;
for(int i=2;i<=2500;i++)
LOG[i]=LOG[i/2]+1;
A=a;
n=a.size(),m=a[0].size();
BUILD();
for(int i=1;i<n-1;i++){
for(int l=1;l<m-1;l++){
for(int x=l;x<m-1;x++){
if(check2(i,i,l,x)){
RE[i].push_back({l,x});
}
}
}
}
for(int i=1;i<m-1;i++){
for(int l=1;l<n-1;l++){
for(int x=l;x<n-1;x++){
if(check(l,x,i,i)){
RE2[i].push_back({l,x});
}
}
}
}
int CNT=0;
for(int i=1;i<n-1;i++){
for(int x=0;x<RE[i].size();x++){
for(int l=i;l<n-1;l++){
if(!check2(l,l,RE[i][x].first,RE[i][x].second))
break;
DP[i][l][x]=1;
}
}
}
for(int i=1;i<m-1;i++){
for(int x=0;x<RE2[i].size();x++){
for(int l=i;l<m-1;l++){
if(!check(RE2[i][x].first,RE2[i][x].second,l,l))
break;
DP2[i][l][x]=1;
}
}
}
for(int i=1;i<n-1;i++){
for(int l=0;l<RE[i].size();l++){
for(int x=0;x<RE2[RE[i][l].first].size();x++){
if(i==RE2[RE[i][l].first][x].first)
if(DP[i][RE2[RE[i][l].first][x].second][l]&DP2[RE[i][l].first][RE[i][l].second][x])
CNT++;
}
}
}
return CNT;
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:76:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int x=0;x<RE[i].size();x++){
| ~^~~~~~~~~~~~~
rect.cpp:85:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int x=0;x<RE2[i].size();x++){
| ~^~~~~~~~~~~~~~
rect.cpp:94:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int l=0;l<RE[i].size();l++){
| ~^~~~~~~~~~~~~
rect.cpp:95:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int x=0;x<RE2[RE[i][l].first].size();x++){
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |