QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724957 | #4378. Ball | XfJbUhpyzgaW# | WA | 1712ms | 29112kb | C++14 | 2.3kb | 2024-11-08 15:42:11 | 2024-11-08 15:42:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
struct ed{int x,y,d;}e[2000*2001/2+5];
int pr[N+5],p[N+5],cnt=0;
int x[2005],y[2005];
int d[2005];
int T,n,m,tot;
bitset<2005> gr[2005],le[2005];
int main(){
// freopen("a.in","r",stdin);
pr[1]=1;
for (int i=2;i<=N;++i){
if (!pr[i]) p[++cnt]=i;
for (int j=1;j<=cnt && 1ll*i*p[j]<=N;++j){
pr[i*p[j]]=1;
if (i%p[j]==0) break;
}
}
// for (int i=1;i<=20;++i) printf("%d",pr[i]);
for (scanf("%d",&T);T;--T){
scanf("%d%d",&n,&m);tot=0;
for (int i=1;i<=n;++i) scanf("%d%d",&x[i],&y[i]),gr[i].reset(),le[i].reset();
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
if (j!=i)
gr[i].set(j);
for (int i=1;i<=n;++i)
for (int j=i+1;j<=n;++j)
e[++tot]=(ed){i,j,abs(x[i]-x[j])+abs(y[i]-y[j])};
sort(e+1,e+1+tot,[](ed a,ed b){return a.d<b.d;});
// for (int i=1;i<=tot;++i) printf("%d %d %d\n",e[i].x,e[i].y,e[i].d);
int ans=0;
for (int i=1,it1=1,it2=1;i<=tot;++i){
while (it1<=tot && e[it1].d<e[i].d){
le[e[it1].x].set(e[it1].y);
le[e[it1].y].set(e[it1].x);
++it1;
}
while (it2<=tot && e[it2].d<=e[i].d){
gr[e[it2].x].flip(e[it2].y);
gr[e[it2].y].flip(e[it2].x);
++it2;
}
if (!pr[e[i].d]){
bitset<2005> t=(le[e[i].x]&gr[e[i].y])|(gr[e[i].x]&le[e[i].y]);
ans+=t.count();
// printf("%d %d %d ",e[i].x,e[i].y,e[i].d);
// for (int j=1;j<=n;++j)
// putchar(t[j]+'0');
// puts("");
}
}
for (int i=1,j=1;i<=tot;){
int tmp=0;
while (j<=tot && e[j].d==e[i].d){
tmp+=d[e[j].x]+d[e[j].y];
++d[e[j].x],++d[e[j].y];
++j;
}
// printf("%d %d %d\n",i,j,tmp);
if (!pr[e[i].d]) ans+=tmp;
while (i<j){
--d[e[i].x],--d[e[i].y];
++i;
}
}
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1712ms
memory: 29112kb
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:
306098171 113711265 112644014 306053030 111920257 112598067 290930495 115277403 112743440 307027850
result:
wrong answer 1st lines differ - expected: '306097111', found: '306098171'