QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47482#4378. Ballzzxzzx123AC ✓1453ms57176kbC++171.7kb2022-09-10 10:32:412022-09-10 10:32:44

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:32:44]
  • 评测
  • 测评结果:AC
  • 用时:1453ms
  • 内存:57176kb
  • [2022-09-10 10:32:41]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define inf 0x3f3f3f3f
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define mod (int)1e9+7
#define NO puts("NO")
#define YES puts("YES")
#define No puts("No")
#define Yes puts("Yes")
using namespace std;
typedef pair<int,int>PII;
typedef long long ll;
const int N=2010,M=N*N;
int n,m;
int a[N],b[N];
bitset<N>bset[N];//表示当前枚举了哪些边
struct P{
    int a,b,w;
    bool operator<(const P&x)const{
        return w<x.w;
    }
}p[M];
int prim[M],tot;
bool vis[M];
void prime(int M){
    vis[1]=1;//注意把1判定为非质数
    for(int i=2;i<=M;i++){
        if(!vis[i]) prim[tot++]=i;
        for(int j=0;prim[j]<=M/i;j++){
            vis[i*prim[j]]=1;
            if(i%prim[j]==0) break;
        }
    }
}
int get(int i,int j){
    return abs(a[i]-a[j])+abs(b[i]-b[j]);
}
inline void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++) bset[i].reset();
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            p[cnt++]={i,j,get(i,j)};
        }
    }
    sort(p,p+cnt);
    int ans=0;
    for(int i=0;i<cnt;i++){
        int a=p[i].a,b=p[i].b,w=p[i].w;
        if(!vis[w]) ans+=(bset[a]^bset[b]).count();
        bset[a][b]=bset[b][a]=1;
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    mp.reserve(1024);
//    mp.max_load_factor(0.25);
    prime(M);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1453ms
memory: 57176kb

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