QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47473#4378. Ballzzxzzx123TL 0ms0kbC++141.3kb2022-09-10 10:03:522022-09-10 10:03:53

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-10 10:03:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-09-10 10:03:52]
  • 提交

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...

output:


result: