QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86044 | #5369. 时间旅行 | tricyzhkx | 0 | 2ms | 3428kb | C++14 | 2.6kb | 2023-03-09 10:03:25 | 2023-03-09 10:03:29 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k,le,ri,curt,tim[310],fa[310],que[310],pre[310],mch[310],tmch[310],col[310];
ll mn[310],mx[310];
bool G[310][310];
vector<ll> a[310];
int getF(int x){return fa[x]==x?x:fa[x]=getF(fa[x]);}
int lca(int u,int v)
{
for(curt++;tim[u=getF(u)]!=curt;v?swap(u,v):void()) tim[u]=curt,u=pre[mch[u]];
return u;
}
void blossom(int u,int v,int w)
{
for(;getF(u)!=w;u=pre[v])
{
pre[u]=v;v=mch[u];
fa[u]=fa[v]=w;
if(col[v]<0) col[v]=1,que[ri++]=v;
}
}
bool bfs(int s)
{
memset(col+1,0,sizeof(int)*(n+1));
iota(fa+1,fa+n+2,1);
le=ri=0;que[ri++]=s;col[s]=1;
while(le<ri)
{
int u=que[le++],w;
for(int v=1;v<=n+1;v++)if(G[u][v])
{
if(col[v]<0 || getF(u)==getF(v)) continue;
if(col[v]>0) w=lca(u,v),blossom(u,v,w),blossom(v,u,w);
else
{
pre[v]=u;col[v]=-1;
if(mch[v]) col[mch[v]]=1,que[ri++]=mch[v];
else
{
for(;v;v=w) u=pre[v],w=mch[u],mch[u]=v,mch[v]=u;
return true;
}
}
}
}
return false;
}
bool judge(ll lim)
{
int ans=0,tans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)if(i!=j)
G[i][j]=(mx[i]-mn[j]>=lim || mx[j]-mn[i]>=lim);
for(int i=1;i<=n;i++) G[i][n+1]=G[n+1][i]=0;
memset(mch+1,0,sizeof(int)*(n+1));
for(int i=1;i<=n;i++)
if(!mch[i]) ans+=bfs(i);
for(int i=1;i<=n;i++)for(ll v:a[i])
{
int d1=0,d2=0,v1=0,v2=0;
for(int j=1;j<=n;j++)if(i!=j)
{
G[i][j]=G[j][i]=(mn[j]<=v-lim);
G[n+1][j]=G[j][n+1]=(mx[j]>=v+lim);
if(G[i][j]) d1++,v1=j;
if(G[n+1][j]) d2++,v2=j;
}
if(d1 && d2 && (d1>1 || d2>1 || v1!=v2))
{
tans=ans;memcpy(tmch+1,mch+1,sizeof(int)*(n+1));
if(mch[i] && !G[i][mch[i]])
{
int j=mch[i];mch[i]=mch[j]=0;ans--;
if(!mch[i]) ans+=bfs(i);
if(!mch[j]) ans+=bfs(j);
}
else if(!mch[i]) ans+=bfs(i);
if(!mch[n+1]) ans+=bfs(n+1);
if(ans>=k) return true;
ans=tans;memcpy(mch+1,tmch+1,sizeof(int)*(n+1));
}
for(int j=1;j<=n;j++)if(i!=j)
G[i][j]=G[j][i]=(mx[i]-mn[j]>=lim || mx[j]-mn[i]>=lim),
G[n+1][j]=G[j][n+1]=0;
}
return false;
}
int main()
{
cin>>n>>k;
if((n-k)&1) return puts("Impossible"),0;
k=(n-k+2)/2;
mt19937_64 Rand(0);
for(int i=1;i<=n;i++)
{
ll v=Rand()%(ll)1e18;
a[i].push_back(v);mn[i]=mx[i]=v;
continue;
int x;
scanf("%d",&x);a[i].resize(x);
for(ll &j:a[i]) scanf("%lld",&j);
sort(a[i].begin(),a[i].end());
mn[i]=a[i][0];mx[i]=a[i][x-1];
}
ll l=0,r=1e18,mid;
while(l<r)
{
mid=(l+r+1)/2;
if(judge(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3428kb
input:
13 1 1 13 1 2 1 9 1 11 1 8 1 5 1 6 1 4 1 10 1 7 1 12 1 1 1 3
output:
410703111749212376
result:
wrong answer 1st lines differ - expected: '6', found: '410703111749212376'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3420kb
input:
14 2 2 844974872 196961856 2 282529753 793092789 1 450615292 2 894675938 183278191 2 134804124 988858141 1 440476238 2 892091463 453193625 2 918614039 267044448 1 91126449 2 699070127 177282394 2 365458732 596469725 2 789994620 379428523 2 758349986 369167103 2 227448762 297426831
output:
410703111749212376
result:
wrong answer 1st lines differ - expected: '392388416', found: '410703111749212376'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%