QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559029 | #8669. 正方形计数 | guosoun | 35 | 1054ms | 3768kb | C++20 | 2.0kb | 2024-09-11 19:47:12 | 2024-09-11 19:47:17 |
Judging History
answer
#include <bits/stdc++.h>
template <class T>
void chkmin(T &x, const T &y) {
if (x > y) x = y;
}
template <class T>
void chkmax(T &x, const T &y) {
if (x < y) x = y;
}
using ll = long long;
const int N = 2010;
struct point {
int x, y;
point operator-(const point &rhs) const { return {x - rhs.x, y - rhs.y}; }
bool operator==(const point &rhs) const { return x == rhs.x && y == rhs.y; }
};
ll cross(const point &a, const point &b) {
return (ll)a.x * b.y - (ll)a.y * b.x;
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int n;
std::cin >> n;
std::vector<point> a(n);
for (auto &[x, y] : a) std::cin >> x >> y;
std::array<int, N> rowl, rowr, coll, colr;
rowl.fill(1e9), rowr.fill(-1e9), coll.fill(1e9), colr.fill(-1e9);
auto check = [&](point u) {
for (int i = 0; i < n; i++) {
auto l = a[i ? i - 1 : n - 1], m = a[i], r = a[(i + 1) % n];
auto v1 = l - m, v2 = r - m;
if (cross(v1, v2) == 0) continue;
if (cross(v1, v2) < 0) std::swap(v1, v2);
if (cross(v1, u - m) < 0) return false;
if (cross(u - m, v2) < 0) return false;
}
return true;
};
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (check({i, j})) {
chkmin(rowl[i], j), chkmax(rowr[i], j);
chkmin(coll[j], i), chkmax(colr[j], i);
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (rowl[i] > rowr[i]) continue;
for (int j = i + 1; j < N; j++) {
if (rowl[j] > rowr[j]) continue;
int d = j - i;
for (int k = 0; k + d < N; k++) {
if (coll[k] > colr[k]) continue;
if (coll[k + d] > colr[k + d]) continue;
int l1 = rowl[i] - k, r1 = rowr[i] - k;
int l2 = k + d - rowr[j], r2 = k + d - rowl[j];
int l3 = j - colr[k], r3 = j - coll[k];
int l4 = coll[k + d] - i, r4 = colr[k + d] - i;
ans += std::max(
0, std::min({r1, r2, r3, r4, d}) - std::max({l1, l2, l3, l4, 1}) + 1);
}
}
}
std::cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
4 131 603 131 1828 1919 1828 1919 603
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
input:
3 131 603 131 1828 1919 603
output:
result:
Subtask #3:
score: 15
Accepted
Test #11:
score: 15
Accepted
time: 21ms
memory: 3560kb
input:
8 0 13 4 15 15 15 15 6 13 1 12 0 5 0 0 6
output:
4047
result:
ok 1 number(s): "4047"
Test #12:
score: 15
Accepted
time: 28ms
memory: 3616kb
input:
8 0 4 1 15 2 15 15 14 15 4 14 0 1 0 0 2
output:
4200
result:
ok 1 number(s): "4200"
Test #13:
score: 15
Accepted
time: 17ms
memory: 3560kb
input:
5 7 15 15 13 15 0 3 0 0 15
output:
3635
result:
ok 1 number(s): "3635"
Test #14:
score: 15
Accepted
time: 26ms
memory: 3768kb
input:
8 0 12 2 14 7 15 13 15 15 10 15 1 8 0 0 0
output:
4511
result:
ok 1 number(s): "4511"
Test #15:
score: 15
Accepted
time: 27ms
memory: 3760kb
input:
6 0 11 3 15 7 15 15 12 10 0 0 0
output:
3006
result:
ok 1 number(s): "3006"
Test #16:
score: 15
Accepted
time: 28ms
memory: 3768kb
input:
5 0 0 0 2 1 2 2 1 2 0
output:
4
result:
ok 1 number(s): "4"
Subtask #4:
score: 20
Accepted
Dependency #3:
100%
Accepted
Test #17:
score: 20
Accepted
time: 115ms
memory: 3764kb
input:
8 49 299 144 300 300 260 250 15 115 0 30 0 23 19 0 85
output:
443602646
result:
ok 1 number(s): "443602646"
Test #18:
score: 20
Accepted
time: 127ms
memory: 3616kb
input:
8 0 133 103 300 130 300 257 294 297 227 300 150 277 40 161 4
output:
351466521
result:
ok 1 number(s): "351466521"
Test #19:
score: 20
Accepted
time: 114ms
memory: 3496kb
input:
8 76 286 114 300 300 300 300 205 291 0 47 0 4 57 2 235
output:
605026927
result:
ok 1 number(s): "605026927"
Test #20:
score: 20
Accepted
time: 129ms
memory: 3628kb
input:
8 0 102 40 274 282 300 300 234 267 0 34 0 6 57 0 86
output:
497330741
result:
ok 1 number(s): "497330741"
Test #21:
score: 20
Accepted
time: 117ms
memory: 3764kb
input:
7 0 288 156 300 212 300 265 176 300 86 278 0 0 36
output:
446722651
result:
ok 1 number(s): "446722651"
Subtask #5:
score: 0
Wrong Answer
Dependency #4:
100%
Accepted
Test #22:
score: 0
Wrong Answer
time: 1054ms
memory: 3556kb
input:
5 257 800 766 800 800 353 667 0 42 0
output:
1701500430
result:
wrong answer 1st numbers differ - expected: '18881369614', found: '1701500430'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%