QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#633081 | #9457. Prime Set | ucup-team3161# | AC ✓ | 72ms | 9224kb | C++20 | 1.4kb | 2024-10-12 14:31:01 | 2024-10-13 19:27:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=3e3+5,M=2e6+5;
int T,n,n1,n2,n3,m,a[N],a1[N],a2[N],p[M];bool vs[M];
int w,w1,mch[N];bitset<N> tg,e[N];
void sieve(int n)
{
for(int i=2;i<=n;++i)
{
if(!vs[i]) p[++p[0]]=i;
for(int j=1;i*p[j]<=n;++j)
{vs[i*p[j]]=1;if(!(i%p[j])) break;}
}
}
bool dfs(int u)
{
while(1)
{
bitset<N> z=e[u]&tg;int v=z._Find_first();
if(v==N) return 0;tg.reset(v);
if(!mch[v] || dfs(mch[v])) {mch[v]=u;return 1;}
}
}
void slv()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n1;++i) e[i].reset();
n1=n2=n3=w=w1=0;
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
if(a[i]==1) ++n3;
else if(a[i]&1) a1[++n1]=a[i];else a2[++n2]=a[i];
}
for(int i=1;i<=n1;++i) for(int j=1;j<=n2;++j)
if(!vs[a1[i]+a2[j]]) e[i].set(j);
fill(mch+1,mch+n2+1,0);
for(int i=1;i<=n1;++i) tg.set(),w+=dfs(i);
w1=max(w1,w+n3/2);
for(int i=1;i<=n3;++i)
{
a1[++n1]=1;
for(int j=1;j<=n2;++j) if(!vs[a2[j]+1]) e[n1].set(j);
tg.set();w+=dfs(n1);w1=max(w1,w+(n3-i)/2);
}
w=0;
for(int i=1;i<=n;++i)
{
bool fl=0;
for(int j=1;j<=n;++j)
if(i!=j && !vs[a[i]+a[j]]) {fl=1;break;}w+=fl;
}
printf("%d\n",m<=w1?m*2:min(m+w1,w));
}
int main()
{
sieve(2e6);scanf("%d",&T);
while(T--) slv();return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 6492kb
input:
4 4 2 2 3 4 5 5 3 3 4 12 3 6 6 3 1 3 6 8 1 1 1 0 1
output:
4 3 6 0
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 72ms
memory: 9224kb
input:
110 3 3 2 2 2 3 1 1 1 1 3 2 1 1 1 3 3 1 1 1 4 2 1 1 1 1 10 7 1 1 1 2 4 6 8 10 12 14 18 1 10 5 9 4 10 7 2 4 9 1 6 1 4 9 2 4 9 7 19 5 1 6 1 8 8 1 5 10 9 2 10 2 1 9 6 10 4 3 6 14 4 6 6 8 9 5 3 4 9 2 2 1 10 10 1 15 10 5 4 2 4 10 1 8 4 10 3 10 3 7 10 4 17 5 10 7 2 4 3 1 10 8 2 8 3 4 1 1 1 1 1 20 6 8 4 6 ...
output:
0 2 3 3 4 8 2 10 8 15 10 12 10 10 12 16 10 10 12 16 14 13 13 14 17 0 19 12 12 11 16 10 19 2 12 10 5 14 10 10 13 2 18 2 4 4 11 8 11 8 0 10 10 0 10 0 8 15 12 11 13 18 10 17 9 8 20 19 13 6 4 6 11 9 13 11 6 2 8 12 17 14 6 2 20 2 18 17 6 2 10 0 7 16 2 2 0 2 18 14 11 8 4 6 0 19 890 204 2746 2372
result:
ok 110 lines
Extra Test:
score: 0
Extra Test Passed