QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47473 | #4378. Ball | zzxzzx123 | TL | 0ms | 0kb | C++14 | 1.3kb | 2022-09-10 10:03:52 | 2022-09-10 10:03:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2010;
int x[N],y[N];
struct node{
int i,j,val;
bool operator<(const node& a)const {
return val<a.val;
}
}e[N*N];
bitset<N>ma[N],mi[N];
int vis[N*N],pri[N*N],cnt;
void init(){
vis[1]=1;
for(int i=2;i<N;i++){
if(!vis[i]){
pri[++cnt]=i;
}
for(int j=1;j<=cnt&&(ll)i*pri[j]<N;j++){
int v=i*pri[j];
vis[v]=1;
if(!(i%pri[j])){
break;
}
}
}
}
int get_val(int i,int j){
return abs(x[i]-x[j])+abs(y[i]-y[j]);
}
int main(){
int t;
scanf("%d",&t);
init();
while(t--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d%d",&x[i],&y[i]);
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
e[++cnt]={i,j,get_val(i,j)};
}
}
sort(e+1,e+cnt+1);
for(int i=1;i<=n;i++){
mi[i].reset();//全部都比你小
ma[i].set();//全部都比你大
mi[i][i]=ma[i][i]=0;
}
ll ans=0;
for(int i=1;i<=cnt;i++){
int u=e[i].i,v=e[i].j,val=e[i].val;//获得你的编号
if(!vis[val])
ans+=(ma[u]&mi[v]).count()+(ma[v]&mi[u]).count();
//接下来考虑删除和添加
mi[u][v]=1;
mi[v][u]=1;
ma[u][v]=ma[v][u]=0;
}
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
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...