QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56580#4378. BallqinjianbinAC ✓1323ms28960kbC++171.1kb2022-10-20 11:00:132022-10-20 11:00:15

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-20 11:00:15]
  • 评测
  • 测评结果:AC
  • 用时:1323ms
  • 内存:28960kb
  • [2022-10-20 11:00:13]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a) ; i < (b); i++)
#define _for(i, a, b) for(int i = (a) ; i <= (b); i++)
using namespace std;

typedef long long ll;
const int M = 2e5 + 10;
const int N = 2e3 + 10;
bool vis[M];
vector<int> p;
bitset<N> g[N];
int x[N], y[N], n, m;

struct Edge
{
	int u, v, w;
	bool operator < (const Edge& rhs) const
	{
		return w < rhs.w;
	}
};
vector<Edge> e;

void init()
{
	vis[0] = vis[1] = 1;
	_for(i, 2, 2e5)
	{
		if(!vis[i]) p.push_back(i);
		for(int x: p)
		{
			if(i * x > 2e5) break;
			vis[i * x] = 1;
			if(i % x == 0) break;
		}
	}
}
 
int main()
{
	init();

	int T; scanf("%d", &T);
	while(T--)
	{
		e.clear();
		scanf("%d%d", &n, &m);
		_for(i, 1, n) scanf("%d%d", &x[i], &y[i]), g[i].reset();

		_for(i, 1, n)
			_for(j, i + 1, n)
				e.push_back({i, j, abs(x[i] - x[j]) + abs(y[i] - y[j])});
		sort(e.begin(), e.end());

		ll ans = 0;
		for(auto [u, v, w] : e)
		{
			if(!vis[w]) ans += (g[u] ^ g[v]).count();
			g[u][v] = g[v][u] = 1;
		}
		printf("%lld\n", ans);
	}
 
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1323ms
memory: 28960kb

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