QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#771858#5369. 时间旅行Flamire28 4500ms4160kbC++172.9kb2024-11-22 16:04:082024-11-22 16:04:08

Judging History

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

  • [2024-11-22 16:04:08]
  • 评测
  • 测评结果:28
  • 用时:4500ms
  • 内存:4160kb
  • [2024-11-22 16:04:08]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define s1 first
#define s2 second
#define TIME chrono::steady_clock::now().time_since_epoch().count()
using namespace std;
int n,k;
ll S=TIME;
vector<ll> vv[311];
ll calc(vector<ll> V)
{
	ll ans=1e18;
	for(int i=0;i+V.size()/2<V.size();++i)ans=min(ans,V[i+V.size()/2]-V[i]);
	return ans;
}
ll solve(vector<ll> V)
{
	sort(V.begin(),V.end());
	int x=n-(k-1);
	ll ans=-1e18;
	for(int i=x/2;i<n-(x/2);++i)
	{
		vector<ll> V1;
		for(int _=0;_<x/2;++_)V1.push_back(V[_]);
		V1.push_back(V[i]);
		for(int _=n-(x/2);_<n;++_)V1.push_back(V[_]);
		ans=max(ans,calc(V1));
	}
	return ans;
}
vector<ll> cV;ll ans=-1e18;
void dfs(int u)
{
	if(u==n+1){ans=max(ans,solve(cV));return;}
	for(int _=0;_<vv[u].size();++_)
	{
		cV.push_back(vv[u][_]);
		dfs(u+1);
		cV.pop_back();
	}
}
ll l[311],r[311];
mt19937 rnd(801);
void poppo()
{
	while((TIME-S)/1e9<4.5)
	{
		for(int x=1;x<=n;++x)
		{
			static vector<pii> vl,vr;
			static bool in[311];
			vl.clear();vr.clear();
			for(int i=1;i<=n;++i)in[i]=0;in[x]=1;
			for(int i=1;i<=n;++i)
			{
				vl.push_back({l[i],i});
				vr.push_back({r[i],i});
			}
			sort(vl.begin(),vl.end());
			sort(vr.begin(),vr.end(),greater<pii>());
			static vector<ll> V;
			V.clear();
			int ptl=0,ptr=0,cntl=0,cntr=0;
			while(cntl<k/2||cntr<k/2)
			{
				while(in[vl[ptl].s2])++ptl;
				while(in[vr[ptr].s2])++ptr;
				if((rnd()&1)&&cntl<k/2||cntr==k/2)
				{
					if(rnd()%100==0)swap(vl[ptl],vl[ptl+1]);
					else
					{
						V.push_back(vl[ptl].s1);
						++cntl,++ptl;
					}
				}
				else
				{
					if(rnd()%100==0)swap(vr[ptr],vr[ptr+1]);
					else
					{
						V.push_back(vr[ptr].s1);
						++cntr;++ptr;
					}
				}
				// if(vl[ptl].s2==vr[ptr].s2&&(rnd()&1))
				// {
				// 	V.push_back(vr[ptr].s1);in[vr[ptr].s2]=1;
				// 	while(in[vl[ptl].s2])++ptl;
				// 	V.push_back(vl[ptl].s1);in[vl[ptl].s2]=1;
				// }
				// else
				// {
				// 	V.push_back(vl[ptl].s1);in[vl[ptl].s2]=1;
				// 	while(in[vr[ptr].s2])++ptr;
				// 	V.push_back(vr[ptr].s1);in[vr[ptr].s2]=1;
				// }
			}
			ll mx=0,mn=1e18;
			for(ll x:V)mx=max(mx,x),mn=min(mn,x);
			ll val=-2e18,ty=-1;
			for(ll y:vv[x])if(min(y-mn,mx-y)>val)val=min(y-mn,mx-y),ty=y;
			V.push_back(ty);
			sort(V.begin(),V.end());
			// printf("V:");for(ll x:V)printf("%lld ",x);putchar(10);
			ans=max(ans,calc(V));
		}
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	int mxt=0;
	for(int i=1;i<=n;++i)
	{
		int t;
		scanf("%d",&t);vv[i].resize(t);
		l[i]=1e18;r[i]=0;
		for(int j=0;j<t;++j)scanf("%lld",&vv[i][j]),mxt=max(mxt,(int)vv[i].size()),l[i]=min(l[i],vv[i][j]),r[i]=max(r[i],vv[i][j]);
	}
	if(n%2!=k%2)printf("Impossible\n");
	else
	{
		if(n<=15||mxt==1)dfs(1);
		else
		{
			k=n-(k-1);
			poppo();
		}
		printf("%lld\n",ans);
	}
	fclose(stdin);fclose(stdout);return 0;
}

详细

Subtask #1:

score: 3
Accepted

Test #1:

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

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:

6

result:

ok single line: '6'

Test #2:

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

input:

101 1
1 71
1 95
1 1
1 4
1 85
1 11
1 94
1 29
1 99
1 41
1 59
1 51
1 79
1 67
1 13
1 84
1 16
1 43
1 55
1 18
1 92
1 10
1 77
1 86
1 49
1 20
1 8
1 32
1 72
1 40
1 52
1 76
1 39
1 61
1 82
1 66
1 44
1 3
1 35
1 37
1 48
1 15
1 96
1 33
1 83
1 2
1 30
1 75
1 54
1 70
1 22
1 63
1 60
1 88
1 97
1 34
1 9
1 17
1 57
1 80
...

output:

50

result:

ok single line: '50'

Test #3:

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

input:

291 1
1 1
1 243
1 31
1 188
1 77
1 101
1 20
1 177
1 58
1 12
1 201
1 152
1 89
1 205
1 203
1 214
1 225
1 94
1 147
1 100
1 235
1 103
1 196
1 216
1 192
1 143
1 6
1 259
1 215
1 51
1 234
1 2
1 102
1 17
1 157
1 82
1 52
1 211
1 176
1 264
1 149
1 74
1 105
1 202
1 172
1 226
1 165
1 271
1 78
1 285
1 262
1 88
1 ...

output:

145

result:

ok single line: '145'

Subtask #2:

score: 8
Accepted

Test #4:

score: 8
Accepted
time: 1ms
memory: 3876kb

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: 8
Accepted
time: 8ms
memory: 3884kb

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: 8
Accepted
time: 8ms
memory: 3892kb

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: 8
Accepted
time: 0ms
memory: 4072kb

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: 8
Accepted
time: 9ms
memory: 3896kb

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: 5
Accepted

Dependency #1:

100%
Accepted

Test #9:

score: 5
Accepted
time: 0ms
memory: 3864kb

input:

287 1
1 173840701363378004
1 743361258032855446
1 746614854489854642
1 56541606566914354
1 420238720727662982
1 851742472173310082
1 663095483358412253
1 909940213272622771
1 793226013158281220
1 545752184531876147
1 428168322861170312
1 445062401949703086
1 781910693870313013
1 656624250154096657
1...

output:

449906768878285431

result:

ok single line: '449906768878285431'

Test #10:

score: 5
Accepted
time: 0ms
memory: 3912kb

input:

291 1
1 200467876183364735
1 226128802768594222
1 30992945592387546
1 131773707522781490
1 237517614711585543
1 767178437925265104
1 476367111669121061
1 569219147773036356
1 307153686500641679
1 256093763487190540
1 489553827811869668
1 665158752209826021
1 821778345278263808
1 591434397265270731
1...

output:

413750515661326196

result:

ok single line: '413750515661326196'

Test #11:

score: 5
Accepted
time: 0ms
memory: 4148kb

input:

299 1
1 196564096074155356
1 215761209458809063
1 229199188828066663
1 207442460325459123
1 147931408833032623
1 165208810879220961
1 156890061745871023
1 281031394966631680
1 190804962058759240
1 165848714658709418
1 274632357171747109
1 178006886468990102
1 183126116704897759
1 263753992920443339
...

output:

95345663143780088

result:

ok single line: '95345663143780088'

Test #12:

score: 5
Accepted
time: 0ms
memory: 4116kb

input:

291 1
1 33421439583378802
1 58525406002796904
1 59037731848091151
1 71845877980447328
1 54939125085737173
1 56305327339855169
1 59720832975150147
1 42814080080439994
1 38886248599850767
1 34446091273967295
1 80213866786920026
1 80384642068684774
1 58866956566326401
1 74919833052212806
1 674057206545...

output:

24762415855888600

result:

ok single line: '24762415855888600'

Test #13:

score: 5
Accepted
time: 0ms
memory: 4160kb

input:

299 1
1 65691845888395612
1 216175196973785149
1 60434785588469342
1 137319292474891070
1 61749050663450912
1 160976063824559296
1 86720087088100703
1 218803727123748287
1 169518786811939488
1 153747605912160670
1 165575991586994780
1 141919220237326556
1 35463749163819549
1 188575630399172220
1 145...

output:

97912748086126811

result:

ok single line: '97912748086126811'

Subtask #4:

score: 12
Accepted

Dependency #3:

100%
Accepted

Test #14:

score: 12
Accepted
time: 0ms
memory: 3916kb

input:

298 12
1 645886088791049540
1 426745180837601651
1 979147412433797722
1 922061238106952073
1 274440630526214995
1 424124977235014990
1 204894438049963221
1 764943184717907334
1 779533900124364741
1 454823872376348471
1 487382439634807111
1 591648739045233572
1 53460960257864384
1 392937311085787220
...

output:

446040287477110394

result:

ok single line: '446040287477110394'

Test #15:

score: 12
Accepted
time: 1ms
memory: 3920kb

input:

285 3
1 915828826922386175
1 908205342117914832
1 873896977912303819
1 656558831677725931
1 576889220915038574
1 104013515132123991
1 706177613718527725
1 198684931909293626
1 494902099840825229
1 89161767331355640
1 178478456398904787
1 115932633756444471
1 138418817497444484
1 414147023206092509
1...

output:

402109191950085563

result:

ok single line: '402109191950085563'

Test #16:

score: 12
Accepted
time: 0ms
memory: 3936kb

input:

290 8
1 87958755742337433
1 257381168536262370
1 937989408112804408
1 194798272982765279
1 498991322819486370
1 977524249586089037
1 912136601439828528
1 500742285087273119
1 33135176968228980
1 940337323147451787
1 646963258773910853
1 826406775797523718
1 235531045573726392
1 952251530552011077
1 ...

output:

381364661745038978

result:

ok single line: '381364661745038978'

Test #17:

score: 12
Accepted
time: 0ms
memory: 3840kb

input:

286 2
1 275543708198154703
1 249566763748953083
1 144254826792730280
1 189187919894052009
1 270629151140197641
1 194102476952009076
1 246056365850412323
1 263608355343116123
1 262906275763407971
1 250268843328661233
1 160402657126017777
1 210250307285296570
1 225696058038875911
1 150573543010103650
...

output:

99695300318557576

result:

ok single line: '99695300318557576'

Test #18:

score: 12
Accepted
time: 0ms
memory: 4152kb

input:

300 12
1 164380439043062353
1 124158335088338941
1 96965926780920306
1 64108433409456117
1 119626267037102508
1 57876839839006013
1 197804440920931095
1 166646473068680572
1 178543151703176224
1 100931486325752192
1 52211754774960459
1 177410134690367115
1 114527690479461513
1 204036034491381198
1 2...

output:

81577224922255913

result:

ok single line: '81577224922255913'

Test #19:

score: 12
Accepted
time: 0ms
memory: 4112kb

input:

298 28
1 16543256762872223
1 121361510921749171
1 207046274242100976
1 214533292396306476
1 34012965789351713
1 199559256087895478
1 139663110854251503
1 90581547398904360
1 157964710786753830
1 52314565721854039
1 183753328873461653
1 219524637832443472
1 120529620015726343
1 105555583707315354
1 1...

output:

112305272313082450

result:

ok single line: '112305272313082450'

Test #20:

score: 12
Accepted
time: 0ms
memory: 3856kb

input:

297 15
1 85560496741181875
1 17311353112525522
1 60060816704101475
1 10561437808592475
1 43936019033594759
1 18061343701851415
1 56685859052134946
1 31561174309717505
1 66060741418708627
1 56685859052134940
1 96060364991744387
1 39061080202976448
1 47310976685561281
1 92310412045114920
1 14311390755...

output:

52874336547475521

result:

ok single line: '52874336547475521'

Test #21:

score: 12
Accepted
time: 0ms
memory: 3888kb

input:

285 103
1 28285744248308508
1 23382557245297071
1 31472815800266028
1 36621162153427957
1 20195485693339633
1 41769508506589971
1 31472815800265949
1 31472815800265982
1 48388810960655417
1 31472815800266030
1 31472815800266002
1 31472815800265910
1 49124289011107128
1 31472815800265915
1 3147281580...

output:

22309500863702045

result:

ok single line: '22309500863702045'

Subtask #5:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #22:

score: 0
Wrong Answer
time: 4500ms
memory: 3976kb

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:

372997432997019311

result:

wrong answer 1st lines differ - expected: '372997432997019308', found: '372997432997019311'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

0%