QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707945#4378. Ballhejinming983282#AC ✓1483ms54360kbC++231.9kb2024-11-03 18:18:282024-11-03 18:18:28

Judging History

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

  • [2024-11-03 18:18:28]
  • 评测
  • 测评结果:AC
  • 用时:1483ms
  • 内存:54360kb
  • [2024-11-03 18:18:28]
  • 提交

answer

// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);
#define maxn 2005
#define maxm 200005
using namespace std;
inline int read() {
    int now = 0, nev = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
    return now * nev;
}
void write(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
struct node {
    int u, v, w;
    bool operator < (const node &x) const {
        return w < x.w;
    }
};
int n, m, cnt, X[maxn];
int Y[maxn], prime[maxm];
bool is[maxm];
vector <node> vec;
bitset <maxn> Set[maxn];
int dis(int x, int y) {
    return abs(X[x] - X[y]) + abs(Y[x] - Y[y]);
}
signed main() {
    quickio
    quickin
    quickout
    n = 2e5, is[0] = is[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!is[i]) prime[++cnt] = i;
        for(int j = 1; j <= cnt && i * prime[j] <= n; j++) {
            is[i * prime[j]] = 1;
            if(i % prime[j] == 0) break ;
        }
    }
    int T = read();
    while(T--) {
        int n = read(), m = read();
        vec.clear();
        for(int i = 0; i < n; i++) {
            X[i] = read(), Y[i] = read();
            for(int j = 0; j < i; j++)
                vec.push_back((node) {j, i, dis(i, j)});
            Set[i].reset();
        }
        sort(vec.begin(), vec.end());
        int ans = 0;
        for(auto i : vec) {
            int u = i.u, v = i.v, w = i.w;
            if(!is[w]) ans += (Set[u] ^ Set[v]).count();
            Set[u][v] = Set[v][u] = 1;
        }
        write(ans), putchar(10);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1483ms
memory: 54360kb

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