QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#47729#4378. Ballckiseki#AC ✓2503ms52480kbC++1.4kb2022-09-10 16:27:112022-09-10 16:27:13

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 16:27:13]
  • 评测
  • 测评结果:AC
  • 用时:2503ms
  • 内存:52480kb
  • [2022-09-10 16:27:11]
  • 提交

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;
}

详细

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