QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#47507 | #4378. Ball | neko_nyaa# | WA | 1596ms | 39728kb | C++ | 2.3kb | 2022-09-10 13:37:03 | 2022-09-10 13:37:06 |
Judging History
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]) {
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] = 0;
}
}
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;
ans += countFull(n, m, p);
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: 1596ms
memory: 39728kb
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:
10497053 3328 3233 10350787 3303 3185 7847778 3093 3595 10453574
result:
wrong answer 1st lines differ - expected: '306097111', found: '10497053'