QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#178065 | #4378. Ball | jrjyy# | AC ✓ | 2334ms | 52228kb | C++20 | 1.4kb | 2023-09-13 17:45:14 | 2023-09-13 17:45:16 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 2000, M = 2e5;
std::vector<int> pri;
std::vector<bool> vis;
void solve() {
int n, m;
std::cin >> n >> m;
std::vector<std::pair<int, int>> a(n);
for (auto &[x, y] : a) {
std::cin >> x >> y;
}
std::vector<std::tuple<int, int, int>> edges;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int x = std::abs(a[i].first - a[j].first) + std::abs(a[i].second - a[j].second);
edges.emplace_back(x, i, j);
}
}
std::sort(edges.begin(), edges.end());
std::vector<std::bitset<N>> adj(n);
i64 ans = 0;
for (auto [w, u, v] : edges) {
if (!vis[w]) {
ans += (adj[u] ^ adj[v]).count();
}
adj[u].set(v);
adj[v].set(u);
}
std::cout << ans << "\n";
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
vis.resize(M + 1);
vis[1] = true;
for (int i = 2; i <= M; ++i) {
if (!vis[i]) {
pri.push_back(i);
}
for (auto p : pri) {
if (i * p > M) {
break;
}
vis[i * p] = true;
if (i % p == 0) {
break;
}
}
}
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2334ms
memory: 52228kb
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