QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634534#9457. Prime Setucup-team4717#AC ✓402ms14004kbC++171.9kb2024-10-12 17:32:262024-10-13 19:27:55

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 19:27:55]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:402ms
  • 内存:14004kb
  • [2024-10-13 19:27:24]
  • hack成功,自动添加数据
  • (/hack/967)
  • [2024-10-13 18:38:49]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:100
  • 用时:413ms
  • 内存:13404kb
  • [2024-10-13 18:24:51]
  • hack成功,自动添加数据
  • (/hack/965)
  • [2024-10-13 18:17:54]
  • hack成功,自动添加数据
  • (/hack/963)
  • [2024-10-12 17:32:26]
  • 评测
  • 测评结果:100
  • 用时:413ms
  • 内存:13364kb
  • [2024-10-12 17:32:26]
  • 提交

answer

#include<bits/stdc++.h>
#define inl inline
using namespace std;
const int N=3005,IB=1<<21; char IN[IB],*IS=IN+IB,*IT=IS;
#define getchar() (IS==IT&&(IT=IN+fread(IS=IN,1,IB,stdin)),IS==IT?EOF:*IS++)
int n,T,mt[N],un[N],fr[N],vs[N],vt[N]; vector<int> e[N]; queue<int> q;
inl int Read()
{
	int s=0; char c; while(!isdigit(c=getchar()));
	for(;isdigit(c);c=getchar()) s=s*10+c-'0'; return s;
}
inl int Uni(int p) {return p==un[p]?p:un[p]=Uni(un[p]); }
inl int LCA(int x,int y)
{
	for(++T,x=Uni(x),y=Uni(y);vt[x]!=T;vt[x]=T,x=Uni(fr[mt[x]]),y&&(x^=y^=x^=y));
	return x;
}
inl void BLS(int x,int y,int t)
{
	for(;Uni(x)!=t;x=fr[y])
	{
		fr[x]=y; vs[y=mt[x]]==2&&(q.push(y),vs[y]=1);
		x==Uni(x)&&(un[x]=t); y==Uni(y)&&(un[y]=t);
	}
}
inl int Find(int p)
{
	while(!q.empty()) q.pop(); for(int i=1;i<=n;++i) vs[un[i]=i]=0;
	q.push(p); vs[p]=1; for(int u,t;!q.empty();q.pop())
		for(int v:e[u=q.front()]) if(Uni(u)!=Uni(v)&&vs[v]!=2)
		{
			if(vs[v]) BLS(u,v,t=LCA(u,v)), BLS(v,u,t);
			else
			{
				vs[v]=2; fr[v]=u; if(mt[v]) q.push(mt[v]), vs[mt[v]]=1;
				else {for(;v;v=t) t=mt[fr[v]], mt[mt[v]=fr[v]]=v; return 1; }
			}
		}
	return 0;
}
int k;
int a[N];
bool vis[2000005];
void init(int x){
	for(int i=2;i<=x;i++)
		for(int j=i+i;j<=x;j+=i)
			vis[j]=1;
}
void sol(){
	n=Read(),k=Read();
	for(int i=1;i<=n;i++)a[i]=Read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			if(!vis[a[i]+a[j]])
				e[i].push_back(j);
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i) ans+=!mt[i]&&Find(i);
	int sum=0;for(int i=1;i<=n;i++)if(e[i].size())sum++;
	if(k<=ans)cout<<k*2<<'\n';
	else cout<<min(k+ans,sum)<<'\n';
	while(!q.empty())q.pop();
	fill(mt+1,mt+n+2,0);
	fill(un+1,un+n+2,0);
	fill(fr+1,fr+n+2,0);
	fill(vs+1,vs+n+2,0);
	fill(vt+1,vt+n+2,0);
	for(int i=1;i<=n+1;i++)e[i].clear();
	n=T=0;
}
signed main()
{
	init(2e6);
	int TT=Read();
	while(TT--)sol();
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 36ms
memory: 6916kb

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: 402ms
memory: 14004kb

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