QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91280 | #4378. Ball | Tobo | AC ✓ | 1343ms | 29356kb | C++20 | 1.3kb | 2023-03-28 10:13:35 | 2023-03-28 10:13:36 |
Judging History
answer
#include <bits/stdc++.h>
#define N 2005
using i64 = long long;
using namespace std;
int n, m, x[N], y[N];
int dis(int a, int b)
{
return abs(x[a] - x[b]) + abs(y[b] - y[a]);
}
struct node
{
int a, b, len;
bool operator<(const node &tmp) const
{
return len < tmp.len;
}
} num[N * N];
int pri[200505], vis[200505], tot;
bitset<N> s[N];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> x[i] >> y[i], s[i].reset();
int cnt = 0;
i64 ans = 0;
for (int i = 1; i < n; i++)
for (int j = i + 1; j <= n; j++)
num[++cnt] = {i, j, dis(i, j)};
sort(num + 1, num + cnt + 1);
for (int i = 1; i <= cnt; i++)
{
auto [u, v, w] = num[i];
if (!vis[w])
ans += (s[u] ^ s[v]).count();
s[u][v] = s[v][u] = 1;
}
cout << ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
vis[1] = 1;
for (int i = 2; i <= 200050; i++)
{
if (!vis[i])
pri[++tot] = i;
for (int j = 1; j <= tot && pri[j] * i <= 200050; j++)
{
vis[i * pri[j]] = 1;
if (i % pri[j] == 0)
break;
}
}
int t = 1;
cin >> t;
while (t--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1343ms
memory: 29356kb
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