| 比赛 |
2026.3.14 |
评测结果 |
AAEETATTTTTTTTEEEEEEEE |
| 题目名称 |
Circle of Cows |
最终得分 |
12 |
| 用户昵称 |
RpUtl |
运行时间 |
29.303 s |
| 代码语言 |
C++ |
内存使用 |
3.49 MiB |
| 提交时间 |
2026-03-14 12:54:41 |
显示代码纯文本
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N=105;
const int M=10005;
int n,c,k;
int l[N];
int g[N][N];
int match[N],pre[N],base[N],p[N],vis[N];
queue<int> q;
int find(int x){
return x==base[x]?x:base[x]=find(base[x]);
}
int lca(int x,int y){
static int used[N],tim=0;
while(++tim){
if(x!=-1){
x=find(x);
if(used[x]==tim)return x;
used[x]=tim;
x=pre[match[x]];
}
swap(x,y);
}
}
void mark(int x,int y,int b){
while(find(x)!=b){
pre[x]=y;
y=match[x];
if(p[y]==1){
p[y]=0;
q.push(y);
}
base[x]=base[y]=b;
x=pre[y];
}
}
int bfs(int s){
for(int i=1;i<=n;i++){
base[i]=i;
pre[i]=-1;
p[i]=-1;
}
while(!q.empty())q.pop();
q.push(s);
p[s]=0;
while(!q.empty()){
int u=q.front();
q.pop();
for(int v=1;v<=n;v++){
if(!g[u][v])continue;
if(find(u)==find(v)||p[v]==1)continue;
if(p[v]==-1){
p[v]=1;
pre[v]=u;
if(match[v]==-1){
while(v!=-1){
int t=match[pre[v]];
match[v]=pre[v];
match[pre[v]]=v;
v=t;
}
return 1;
}
p[match[v]]=0;
q.push(match[v]);
}else{
int b=lca(u,v);
mark(u,v,b);
mark(v,u,b);
}
}
}
return 0;
}
int max_match(){
int res=0;
memset(match,-1,sizeof(match));
for(int i=1;i<=n;i++){
if(match[i]==-1)res+=bfs(i);
}
return res;
}
int check(int D){
memset(g,0,sizeof(g));
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int d=l[j]-l[i];
d=d<c-d?d:c-d;
if(d>=D){
g[i][j]=1;
g[j][i]=1;
}
}
}
return max_match();
}
int solve(int k){
int L=0,R=c,ans=0;
while(L<=R){
int mid=(L+R)/2;
if(check(mid)>=k){
ans=mid;
L=mid+1;
}else{
R=mid-1;
}
}
return ans;
}
int main(){
freopen("Cows.in","r",stdin);
freopen("Cows.out","w",stdout);
int T=1;
while(T--){
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++){
scanf("%d",&l[i]);
}
k=n/2;
for(int i=1;i<=k;i++){
printf("%d",solve(i));
if(i<k)printf(" ");
}
printf("\n");
}
return 0;
}