이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
long long count_rectangles(vector<vector<int> > a)
{
int n=a.size();
int m=a[0].size();
int i, j, k, l;
long long ans=0;
vector<pair<int, int> >v[2510];
map<pair<int, int>, vector<int> >mp;
for(i=1;i<n-1;i++)
{
vector<int>V;
for(j=0;j<m;j++)
{
while(V.size()&&a[i][V.back()]<a[i][j])
{
if(V.back()+1<j)v[i].push_back({V.back(), j});
V.pop_back();
}
if(V.size()&&V.back()+1<j)v[i].push_back({V.back(), j});
V.push_back(j);
}
}
for(j=1;j<m-1;j++)
{
vector<int>V;
for(i=0;i<n;i++)
{
while(V.size()&&a[V.back()][j]<a[i][j])
{
if(V.back()+1<i)mp[{V.back(), i}].push_back(j);
V.pop_back();
}
if(V.size()&&V.back()+1<i)mp[{V.back(), i}].push_back(j);
V.push_back(i);
}
}
for(i=1;i<n-1;i++)
{
for(j=i;j<n-1;j++)
{
if(mp.find({i-1, j+1})==mp.end())continue;
vector<int>V=mp[{i-1, j+1}];
int A[2510]={};
for(k=0;k<V.size();k++)A[V[k]]++;
for(k=1;k<m;k++)
{
A[k]+=A[k-1];
}
map<pair<int, int>, int>mp2;
for(k=i;k<=j;k++)
{
for(l=0;l<v[k].size();l++)
{
mp2[v[k][l]]++;
}
}
map<pair<int, int>, int>::iterator it;
for(it=mp2.begin();it!=mp2.end();it++)
{
if(it->second==j-i+1)
{
if(A[it->first.second-1]-A[it->first.first]==it->first.second-1-it->first.first)ans++;
}
}
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(k=0;k<V.size();k++)A[V[k]]++;
| ~^~~~~~~~~
rect.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(l=0;l<v[k].size();l++)
| ~^~~~~~~~~~~~
# | 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... |