이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#include "rect.h"
using namespace std;
constexpr static int MXN = 2505;
int pf[MXN][MXN]
bitset<MXN> visited[MXN];
void check_try(int i, int j, queue<array<int, 2>>& q, vector<vector<int32_t>>& a)
{
if (i < a.size() && i >=0 && j < a[0].size() && j >= 0!visited[i][j] && a[i][j] == 0)
{
visited[i][j] = true;
q.push({i, j});
}
}
long long count_rectangles(vector<vector<int32_t>> a)
{
for (int i = 1; i <= a.size(); i++)
for (int j = 1; j <= a[0].size(); j++)
pf[i][j] = pf[i][j-1] + pf[i-1][j] - pf[i-1][j-1] + a[i][j];
int res = 0;
for (int i = 0; i < a.size(); i++)
{
for (int j = 0; j < a[0].size(); j++)
{
if (visited[i][j] || a[i][j] == 1)
continue;
queue<array<int, 2>> q;
q.push({i, j});
int up = MXN;
int down = -1;
int left = MXN;
int right = -1;
while (q.size())
{
auto [ii, jj] = q.top();
q.pop();
check_try(ii+1, jj, q, a);
check_try(ii, jj+1, q, a);
check_try(ii, jj-1, q,a );
check_try(ii-1, jj, q,a );
up = min(up, ii);
down = max(down, ii);
left = min(left, jj);
right = max(right, jj);
}
if (pf[down+1][right+1] - pf[down+1][left] - pf[up][right+1] - pf[up][left] == 0 && down < a.size()&& up > 0 && right < a[0].size() && left > 0)
res++;
}
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp:12:1: error: expected initializer before 'bitset'
12 | bitset<MXN> visited[MXN];
| ^~~~~~
rect.cpp: In function 'void check_try(int64_t, int64_t, std::queue<std::array<long int, 2> >&, std::vector<std::vector<int> >&)':
rect.cpp:16:8: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (i < a.size() && i >=0 && j < a[0].size() && j >= 0!visited[i][j] && a[i][j] == 0)
| ~~^~~~~~~~~~
rect.cpp:16:33: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (i < a.size() && i >=0 && j < a[0].size() && j >= 0!visited[i][j] && a[i][j] == 0)
| ~~^~~~~~~~~~~~~
rect.cpp:16:56: error: expected ')' before '!' token
16 | if (i < a.size() && i >=0 && j < a[0].size() && j >= 0!visited[i][j] && a[i][j] == 0)
| ~ ^
| )
rect.cpp:18:3: error: 'visited' was not declared in this scope
18 | visited[i][j] = true;
| ^~~~~~~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 1; i <= a.size(); i++)
| ~~^~~~~~~~~~~
rect.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int j = 1; j <= a[0].size(); j++)
| ~~^~~~~~~~~~~~~~
rect.cpp:29:4: error: 'pf' was not declared in this scope; did you mean 'pb'?
29 | pf[i][j] = pf[i][j-1] + pf[i-1][j] - pf[i-1][j-1] + a[i][j];
| ^~
| pb
rect.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
rect.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int j = 0; j < a[0].size(); j++)
| ~~^~~~~~~~~~~~~
rect.cpp:35:8: error: 'visited' was not declared in this scope
35 | if (visited[i][j] || a[i][j] == 1)
| ^~~~~~~
rect.cpp:48:23: error: 'class std::queue<std::array<long int, 2> >' has no member named 'top'; did you mean 'pop'?
48 | auto [ii, jj] = q.top();
| ^~~
| pop
rect.cpp:60:8: error: 'pf' was not declared in this scope; did you mean 'pb'?
60 | if (pf[down+1][right+1] - pf[down+1][left] - pf[up][right+1] - pf[up][left] == 0 && down < a.size()&& up > 0 && right < a[0].size() && left > 0)
| ^~
| pb
rect.cpp:60:93: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if (pf[down+1][right+1] - pf[down+1][left] - pf[up][right+1] - pf[up][left] == 0 && down < a.size()&& up > 0 && right < a[0].size() && left > 0)
| ~~~~~^~~~~~~~~~
rect.cpp:60:122: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if (pf[down+1][right+1] - pf[down+1][left] - pf[up][right+1] - pf[up][left] == 0 && down < a.size()&& up > 0 && right < a[0].size() && left > 0)
| ~~~~~~^~~~~~~~~~~~~