QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#47508#4378. Ballneko_nyaa#WA 1613ms39812kbC++202.4kb2022-09-10 13:39:342022-09-10 13:39:36

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-10 13:39:36]
  • 评测
  • 测评结果:WA
  • 用时:1613ms
  • 内存:39812kb
  • [2022-09-10 13:39:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MAX_PR = 5'000'000;
bitset<MAX_PR> isprime;
vi eratosthenesSieve(int lim) {
	isprime.set(); isprime[0] = isprime[1] = 0;
	for (int i = 4; i < lim; i += 2) isprime[i] = 0;
	for (int i = 3; i*i < lim; i += 2) if (isprime[i])
		for (int j = i*i; j < lim; j += i*2) isprime[j] = 0;
	vi pr;
	rep(i,2,lim) if (isprime[i]) pr.push_back(i);
	return pr;
}

int dist(pair<int, int> a, pair<int, int> b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

ll countTri(int n, vector<pair<int, int>> p) {
	ll ans = 0;
	vector<bitset<2000>> adj(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (dist(p[i], p[j]) == 2) {
				adj[i][j] = 1;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (adj[i][j]) {
				ans += (adj[i] & adj[j]).count();
			}
		}
	}
	return ans/3;
}

ll countFull(int n, int m, vector<pair<int, int>> p) {
	ll ans = 0;
	vector<vector<pair<int, int>>> pps(2*m + 1);
	vector<bitset<2000>> lo(n), hi(n);
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			hi[i][j] = hi[j][i] = 1;
			int d = dist(p[i], p[j]);
			pps[d].emplace_back(i, j);
		}
	}

	vector<int> deg(n);
	for (int d = 1; d <= 2*m; d++) {
		for (auto [i, j]: pps[d]) {
			hi[i][j] = hi[j][i] = 0;
		}

		if (isprime[d]) {
			for (auto [i, j]: pps[d]) {
				//cout << d << ' ' << i << ' ' << j << '\n';
				deg[i]++; deg[j]++;
				ans += (lo[i] & hi[j]).count();
				ans += (lo[j] & hi[i]).count();
			}
			for (int i = 0; i < n; i++) {
				ans += 1LL*deg[i]*(deg[i]-1)/2;
				deg[i] = 0;
			}
		}

		for (auto [i, j]: pps[d]) {
			lo[i][j] = lo[j][i] = 1;
		}
	}
	
	return ans;
}

void solve() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}

	ll ans = 0;
	ans -= countTri(n, p)*2;
	//cerr << "Tri: " << countTri(n, p) << '\n';
	ans += countFull(n, m, p);
	//cerr << "Ful: " << countFull(n, m, p) << '\n';

	cout << ans << '\n';
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); 
	eratosthenesSieve(200005);

	int t; cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1613ms
memory: 39812kb

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:

306096051
113711265
112644014
306051082
111920257
112598067
290929823
115277403
112743440
307025706

result:

wrong answer 1st lines differ - expected: '306097111', found: '306096051'