QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47062#4378. BallAsukaKyle#AC ✓1400ms27704kbC++1.6kb2022-09-03 16:41:062022-09-03 16:41:07

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-03 16:41:07]
  • 评测
  • 测评结果:AC
  • 用时:1400ms
  • 内存:27704kb
  • [2022-09-03 16:41:06]
  • 提交

answer

// Author:  HolyK
// Created: Sat Sep  3 16:14:19 2022
#include <bits/stdc++.h>

template <class T, class U>
inline bool smin(T &x, const U &y) {
  return y < x ? x = y, 1 : 0;
}
template <class T, class U>
inline bool smax(T &x, const U &y) {
  return x < y ? x = y, 1 : 0;
}

using LL = long long;
using PII = std::pair<int, int>;
using namespace std;
const int N = 2001, M = 2e5 + 1;

struct node {
  int x, y;
  
  void in() {
    cin >> x >> y;
  }
} a[N];
struct pr {
  int d, i, j;

  friend bool operator < (const pr &a, const pr &b) {
    return a.d < b.d;
  }
} z[N * N];
bitset<N> s[N], o, p;
bool v[M];

void solve() {
  int n, m; cin >> n >> m;
  for(int i = 1; i <= n; i++) {
    a[i].in();
  }
  int tp = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      int d = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      z[++tp] = {d, i, j};
    }
  }
  sort(z + 1, z + tp + 1);
  for(int i = 1; i <= n; i++) s[i].reset();
  o.reset();
  for(int i = 1; i <= n; i++) o.set(i);
  int ans = 0;
  for(int i = 1; i <= tp; i++) {
    if(!v[z[i].d]) {
      ans += (s[z[i].i] ^ s[z[i].j]).count();
    }
    s[z[i].i][z[i].j] = s[z[i].j][z[i].i] = 1;
  }
  cout << ans << '\n';
}

int main() {
  // freopen("t.in", "r", stdin);
  
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int t = 1;
  
  std::cin >> t;
  v[1] = 1;
  for(int i = 2; i < M; i++) {
    if(v[i]) continue;
    for(int j = 2 * i; j < M; j += i) v[j] = 1;
  }
  
  while (t--) {
    solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1400ms
memory: 27704kb

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