이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2505;
ll res=0;
int N,M,mat[maxn][maxn];
int L[maxn],R[maxn];
stack<int> S;
map<pair<int,int>,int> mapa[maxn];
vector<pair<int,int>> getinterval(vector<int> V){
vector<pair<int,int>> res;
while(S.size())
S.pop();
S.push(0);
L[0]=-1;
for(int i=1;i<V.size();i++){
while(S.size()){
if(V[S.top()]>V[i])
break;
S.pop();
}
if(S.size()==0)
L[i]=-1;
else
L[i]=S.top()+1;
S.push(i);
}
while(S.size())
S.pop();
S.push(V.size()-1);
for(int i=V.size()-2;i>=1;i--){
while(S.size()){
if(V[S.top()]>V[i])
break;
S.pop();
}
if(S.size()==0)
R[i]=-1;
else
R[i]=S.top()-1;
S.push(i);
}
for(int i=1;i<V.size()-1;i++){
if(L[i]==-1)
continue;
if(R[i]==-1)
continue;
res.push_back({L[i],R[i]});
}
vector<pair<int,int>> r2;
if(res.size()){
sort(res.begin(),res.end());
r2.push_back(res[0]);
for(int i=1;i<res.size();i++)
if(res[i]!=res[i-1])
r2.push_back(res[i]);
}
return r2;
}
struct prav{
int u,d,l,r;
};
vector<prav> A,B;
bool seseku(prav a,prav b){
swap(a,b);
if(a.l>b.l)
return false;
if(a.r<b.r)
return false;
if(b.u>a.u)
return false;
if(b.d<a.d)
return false;
return true;
}
ll count_rectangles(std::vector<std::vector<int> > inp) {
N=inp.size();
M=inp[0].size();
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
mat[i][j]=inp[i][j];
/// Vertikalni
for(int i=N-2;i>=1;i--){
vector<int> V;
for(int j=0;j<M;j++)
V.push_back(mat[i][j]);
auto I = getinterval(V);
for(auto x:I){
if(mapa[i+1].find(x)!=mapa[i+1].end()){
mapa[i][x]=mapa[i+1][x]+1;
mapa[i+1].erase(x);
}
else
mapa[i][x]=1;
}
}
for(int i=1;i<=N-2;i++)
for(auto it=mapa[i].begin();it!=mapa[i].end();it++){
prav pp;
pp.u=i;
pp.d=(it->second)+i-1;
pp.l=(it->first).first;
pp.r=(it->first).second;
A.push_back(pp);
}
/// Horizontalni
for(int i=0;i<=M;i++)
mapa[i].clear();
for(int i=M-2;i>=1;i--){
vector<int> V;
for(int j=0;j<N;j++)
V.push_back(mat[j][i]);
auto I = getinterval(V);
for(auto x:I){
if(mapa[i+1].find(x)!=mapa[i+1].end()){
mapa[i][x]=mapa[i+1][x]+1;
mapa[i+1].erase(x);
}
else
mapa[i][x]=1;
}
}
for(int i=1;i<=M-2;i++)
for(auto it=mapa[i].begin();it!=mapa[i].end();it++){
prav pp;
pp.l=i;
pp.r=(it->second)+i-1;
pp.u=(it->first).first;
pp.d=(it->first).second;
B.push_back(pp);
}
/* cout<<"VERTIKALNI"<<endl;
for(prav a:A){
cout<<a.u<<" "<<a.l<<" "<<a.d<<" "<<a.r<<endl;
}
cout<<"HORIZONTALNI"<<endl;
for(prav a:B){
cout<<a.u<<" "<<a.l<<" "<<a.d<<" "<<a.r<<endl;
}*/
int res=0;
for(prav a:A)
for(prav b:B)
if(seseku(a,b))
res++;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'std::vector<std::pair<int, int> > getinterval(std::vector<int>)':
rect.cpp:17:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=1;i<V.size();i++){
| ~^~~~~~~~~
rect.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=1;i<V.size()-1;i++){
| ~^~~~~~~~~~~
rect.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=1;i<res.size();i++)
| ~^~~~~~~~~~~
# | 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... |