이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MAX 2502
int N, M;
vector<short> axis[2][MAX][MAX];
vector<short> endp[2][MAX][MAX];
short l[MAX][MAX];
short r[MAX][MAX];
short d[MAX][MAX];
short u[MAX][MAX];
int ans = 0; void chk(short r1, short c1, short r2, short c2) {
if (r1 > r2 || c1 > c2 || r2 >= N - 1 || c2 >= M - 1 || r1 <= 0 || c1 <= 0) return;
short ind1, ind2;
ind1 = lower_bound(axis[0][r1][r2].begin(), axis[0][r1][r2].end(), c1) - axis[0][r1][r2].begin();
ind2 = lower_bound(axis[0][r1][r2].begin(), axis[0][r1][r2].end(), c2) - axis[0][r1][r2].begin();
if (ind1 >= axis[0][r1][r2].size()) return;
if (ind2 >= axis[0][r1][r2].size()) return;
if (c1 != axis[0][r1][r2][ind1]) return;
if (c2 != axis[0][r1][r2][ind2]) return;
if (c2 - c1 != ind2 - ind1) return;
ind1 = lower_bound(axis[1][c1][c2].begin(), axis[1][c1][c2].end(), r1) - axis[1][c1][c2].begin();
ind2 = lower_bound(axis[1][c1][c2].begin(), axis[1][c1][c2].end(), r2) - axis[1][c1][c2].begin();
if (ind1 >= axis[1][c1][c2].size()) return;
if (ind2 >= axis[1][c1][c2].size()) return;
if (r1 != axis[1][c1][c2][ind1]) return;
if (r2 != axis[1][c1][c2][ind2]) return;
if (r2 - r1 != ind2 - ind1) return;
ans++;
}
long long count_rectangles(std::vector<std::vector<int> > A) {
N = A.size();
M = A[0].size();
int i, j;
memset(l, -1, sizeof(l));
memset(r, -1, sizeof(r));
memset(u, -1, sizeof(u));
memset(d, -1, sizeof(d));
for (i = 0; i < N; i++) {
vector<pii> st;
for (j = 0; j < M; j++) {
int cc = 1;
while (st.size() && st.back().first <= A[i][j]) {
if (st.back().first == A[i][j]) cc = 0;
if (st.back().second + 1 <= j) r[i][st.back().second] = j - 1;
if (st.back().second + 1 <= j - 1) {
axis[1][st.back().second + 1][j - 1].push_back(i);
endp[1][i][st.back().second + 1].push_back(j - 1);
}
st.pop_back();
}
if (st.size()) l[i][j] = st.back().second + 1;
if (cc && st.size() && st.back().second + 1 <= j - 1) {
axis[1][st.back().second + 1][j - 1].push_back(i);
endp[1][i][st.back().second + 1].push_back(j - 1);
}
st.emplace_back(A[i][j], j);
}
}
for (i = 0; i < M; i++) {
vector<pii> st;
for (j = 0; j < N; j++) {
int cc = 1;
while (st.size() && st.back().first <= A[j][i]) {
if (st.back().first == A[j][i]) cc = 0;
if (st.back().second + 1 <= j) d[st.back().second][i] = j - 1;
if (st.back().second + 1 <= j - 1) {
axis[0][st.back().second + 1][j - 1].push_back(i);
endp[0][st.back().second + 1][i].push_back(j - 1);
}
st.pop_back();
}
if (st.size()) u[j][i] = st.back().second + 1;
if (cc && st.size() && st.back().second + 1 <= j - 1) {
axis[0][st.back().second + 1][j - 1].push_back(i);
endp[0][st.back().second + 1][i].push_back(j - 1);
}
st.emplace_back(A[j][i], j);
}
}
vector<tuple<short, short, short, short>> v;
for (i = 1; i < N - 1; i++) for (j = 1; j < M - 1; j++) if (~l[i][j] && ~r[i][j] && ~u[i][j] && ~d[i][j]) v.emplace_back(l[i][j], u[i][j], r[i][j], d[i][j]);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (auto& [a, b, c, d] : v) chk(b, a, d, c);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'void chk(short int, short int, short int, short int)':
rect.cpp:20:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (ind1 >= axis[0][r1][r2].size()) return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:21:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (ind2 >= axis[0][r1][r2].size()) return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:27:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if (ind1 >= axis[1][c1][c2].size()) return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:28:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (ind2 >= axis[1][c1][c2].size()) return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |