QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85920#5369. 时间旅行tricyzhkx8 4ms3736kbC++142.1kb2023-03-08 21:14:512023-03-08 21:15:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 21:15:18]
  • 评测
  • 测评结果:8
  • 用时:4ms
  • 内存:3736kb
  • [2023-03-08 21:14:51]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k,mch[310],tmch[310],vec[310];
ll mn[310],mx[310];
bool G[310][310],vis[310];
vector<ll> a[310];
mt19937 Rand(0);
bool dfs(int u)
{
	if(vis[u]) return false;
	vis[u]=1;
	vector<int> vec;
	for(int v=1;v<=n+1;v++)
		if(G[u][v]) vec.push_back(v);
	shuffle(vec.begin(),vec.end(),Rand);
	for(int v:vec)
	{
		int w=mch[v];
		mch[u]=v;mch[v]=u;mch[w]=0;
		if(!w || dfs(w)) return true;
		mch[u]=0;mch[v]=w;mch[w]=v;
	}
	return false;
}
bool aug(int u)
{
	for(int T=0;T<5;T++)
	{
		bool ok=dfs(u);
		memset(vis+1,0,sizeof(int)*(n+1));
		if(ok) 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+=aug(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)) continue;
		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+=aug(i)+aug(j)-1;
		}
		else if(!mch[i]) ans+=aug(i);
		if(!mch[n+1]) ans+=aug(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;
	for(int i=1;i<=n;i++)
	{
		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: 0ms
memory: 3712kb

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:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'

Subtask #2:

score: 8
Accepted

Test #4:

score: 8
Accepted
time: 0ms
memory: 3588kb

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:

392388416

result:

ok single line: '392388416'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3536kb

input:

15 3
2 638683108 412097665
2 83585363 50407490
2 843046135 358173578
1 663325200
2 608604244 118346780
2 802365081 329993762
2 507345539 849824533
2 130234046 104894823
2 203433503 491790497
2 257479357 356611715
2 393337689 968844221
2 637493087 938737497
2 165665517 338554501
2 32482910 142430578
...

output:

461498682

result:

ok single line: '461498682'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

15 7
2 4067 4163
2 3780 4073
2 4060 4132
2 4115 4095
2 3801 4137
2 3767 4097
1 3976
1 4074
2 4141 4153
2 3965 4092
2 4080 3902
2 3863 4136
2 4153 4057
2 4045 3789
2 4117 4093

output:

198

result:

ok single line: '198'

Test #7:

score: 0
Accepted
time: 4ms
memory: 3736kb

input:

15 1
1 873331282220671423
2 735219904810912770 161751845932907141
2 25004270082210777 318839217154000771
2 674996277812508140 449008857311902192
2 472769470430097478 397080345283004274
2 47924412360460752 498222902664554012
2 564253525446680521 853694259885512872
2 656010667051096953 815344423905298...

output:

458440019518723706

result:

ok single line: '458440019518723706'

Test #8:

score: 0
Accepted
time: 4ms
memory: 3592kb

input:

15 13
2 896348312198404671 869762298
2 131322200859472553 156263978028639571
2 519956577 38
1 160595875
2 945987587 50986789140245249
2 41 241229344708873674
2 608655655392127091 41
1 40
2 806584170 50835315064131334
2 3623574246181054 976074155891825784
2 58183525 937860538
2 998266378 826367056
2 ...

output:

430005287589733910

result:

ok single line: '430005287589733910'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Dangerous Syscalls

Dependency #2:

100%
Accepted

Test #22:

score: 0
Dangerous Syscalls

input:

97 3
2 355271459380040532 547563913925852132
2 501938321780836726 747940481178452472
2 397422061492707294 74967044201975790
2 377923940791121468 378164526846394284
2 264704309452054653 529171612856996754
2 316250711337645385 284323194941392101
2 358629778571158126 368864454575116270
2 38360271038026...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%