QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47729 | #4378. Ball | ckiseki# | AC ✓ | 2503ms | 52480kb | C++ | 1.4kb | 2022-09-10 16:27:11 | 2022-09-10 16:27:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
static constexpr int maxn = 2000 + 5;
static constexpr int maxc = 200000 + 5;
bool notprime[maxc];
bitset<maxn> pre[maxn], suf[maxn];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
notprime[0] = notprime[1] = true;
for (int i = 2; i < maxc; ++i) {
if (notprime[i]) continue;
for (int j = i + i; j < maxc; j += i)
notprime[j] = true;
}
int t; cin >> t;
while (t--) {
int n, m; cin >> n >> m;
vector<pair<int, int>> a(n);
for (auto &[x, y] : a) cin >> x >> y;
vector<tuple<int, int, int>> v;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int d = abs(a[i].first - a[j].first) + abs(a[i].second - a[j].second);
v.emplace_back(d, i, j);
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
pre[i].reset();
for (int j = 0; j < n; ++j)
if (i != j) suf[i][j] = true;
}
sort(v.begin(), v.end());
for (auto [d, i, j] : v) {
if (not notprime[d]) {
ans += (pre[i] & suf[j]).count();
ans += (pre[j] & suf[i]).count();
}
pre[i][j] = true;
pre[j][i] = true;
suf[i][j] = false;
suf[j][i] = false;
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2503ms
memory: 52480kb
input:
10 2000 80 9 25 39 66 5 63 59 17 45 19 41 21 21 75 21 61 1 65 29 61 11 23 38 51 1 3 41 59 41 61 61 33 45 65 80 49 38 49 45 79 66 60 61 41 56 33 65 57 26 17 36 1 77 11 13 28 25 41 33 23 66 16 4 73 1 1 57 61 32 11 31 29 42 21 37 69 53 59 1 66 54 70 21 57 65 49 49 18 6 5 11 1 1 67 78 49 43 30 27 1 57 7...
output:
306097111 113711265 112644014 306052056 111920257 112598067 290930159 115277403 112743440 307026778
result:
ok 10 lines