QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632047#9457. Prime Setucup-team1004#AC ✓68ms12692kbC++172.6kb2024-10-12 11:38:352024-10-13 18:37:59

Judging History

你现在查看的是测评时间为 2024-10-13 18:37:59 的历史记录

  • [2024-10-13 19:27:30]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:57ms
  • 内存:12168kb
  • [2024-10-13 19:27:24]
  • hack成功,自动添加数据
  • (/hack/967)
  • [2024-10-13 18:37:59]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:100
  • 用时:68ms
  • 内存:12692kb
  • [2024-10-13 18:24:51]
  • hack成功,自动添加数据
  • (/hack/965)
  • [2024-10-13 18:17:54]
  • hack成功,自动添加数据
  • (/hack/963)
  • [2024-10-12 11:38:35]
  • 评测
  • 测评结果:100
  • 用时:77ms
  • 内存:12504kb
  • [2024-10-12 11:38:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=3e3+10,M=2e6+10;
int T,n,k,m,a[N],b[N];
int cnt,pri[148935];
bitset<M>vis;
const int INF=1e9;
namespace Flow{
	const int V=N*2,E=1e7;
	int s,t,kk,head[V],d[V],cur[V];
	struct edges{
		int to,c,nex;
	}edge[E];
	void init(int x,int y){
		s=x,t=y,kk=1;
		fill(head+s,head+1+t,0);
	}
	bool chk(int i){
		return !edge[i].c;
	}
	int add(int u,int v,int c){
		// debug(u,v,c);
		edge[++kk]={v,c,head[u]},head[u]=kk;
		edge[++kk]={u,0,head[v]},head[v]=kk;
		return kk-1;
	}
	bool bfs(){
		queue<int>q;
		q.push(s);
		copy(head+s,head+1+t,cur+s);
		fill(d+s,d+1+t,-1),d[s]=0;
		for(int u;!q.empty();){
			u=q.front(),q.pop();
			for(int i=head[u];i;i=edge[i].nex){
				int v=edge[i].to;
				if(edge[i].c&&!~d[v])d[v]=d[u]+1,q.push(v);
			}
		}
		return ~d[t];
	}
	int dfs(int u,int lim=INF){
		if(u==t)return lim;
		int flow=0;
		for(int i=cur[u];i&&flow<lim;i=edge[i].nex){
			cur[u]=i;
			int v=edge[i].to,c=edge[i].c;
			if(!c||d[v]!=d[u]+1)continue;
			int f=dfs(v,min(lim-flow,c));
			if(!f)d[v]=-1;
			edge[i].c-=f,edge[i^1].c+=f,flow+=f;
		}
		return flow;
	}
	int dinic(){
		int flow=0;
		for(;bfs();)flow+=dfs(s);
		return flow;
	}
}
void init(int n=M-1){
	vis[1]=1;
	for(int i=2;i<=n;i++){
		if(!vis[i])pri[++cnt]=i;
		for(int j=1;j<=cnt&&i*pri[j]<=n;j++){
			vis[i*pri[j]]=1;
			if(i%pri[j]==0)break;
		}
	}
	// debug(cnt);
}
void get(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]==a[cnt])b[cnt]++;
		else a[++cnt]=a[i],b[cnt]=1;
	}
	n=cnt,cnt=0;
	for(int i=1;i<=n;i++){
		if([&](){
			for(int j=1;j<=n;j++){
				if(i!=j&&!vis[a[i]+a[j]])return true;
			}
			return a[i]==1&&b[i]>1;
		}())cnt+=b[i];
	}
	int s=0,t=n+1;
	Flow::init(s,t);
	for(int i=1;i<=n;i++)if(a[i]!=1){
		if(a[i]&1)Flow::add(s,i,b[i]);
		else Flow::add(i,t,b[i]);
	}
	for(int i=1;i<=n;i++)if(a[i]%2==1){
		for(int j=1;j<=n;j++)if(a[j]%2==0){
			if(!vis[a[i]+a[j]])Flow::add(i,j,INF);
		}
	}
	int res=Flow::dinic();
	if(a[1]==1){
		Flow::add(s,1,b[1]);
		int x=Flow::dinic();
		res+=x+(b[1]-x)/2;
	}
	// debug(res,ary(a,1,n),ary(b,1,n));
	if(k<=res)printf("%d\n",k*2);
	else printf("%d\n",min(res+k,cnt));
}
int main(){
	for(init(),scanf("%d",&T);T--;)get();
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 4952kb

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: 68ms
memory: 12692kb

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