QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561240#3588. Hamilton - The MusicalYaremaAC ✓18ms5380kbC++201.9kb2024-09-12 21:25:272024-09-12 21:25:27

Judging History

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

  • [2024-09-12 21:25:27]
  • 评测
  • 测评结果:AC
  • 用时:18ms
  • 内存:5380kb
  • [2024-09-12 21:25:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

const LL LINF = 1e18;

LL hungarian(const vector<vector<LL>>& a)
{
	int n = SZ(a), m = SZ(a[0]);
	assert(n <= m);
	VL u(n + 1), v(m + 1);
	VI p(m + 1, n), way(m + 1);
	FOR (i, 0, n)
	{
		p[m] = i;
		int j0 = m;
		VL minv(m + 1, LINF);
		VI used(m + 1);
		while (p[j0] != n)
		{
			used[j0] = true;
			int i0 = p[j0], j1 = -1;
			LL delta = LINF;
			FOR (j, 0, m)
			{
				if (!used[j])
				{
					LL cur = a[i0][j] - u[i0] - v[j];
					if (cur < minv[j])
					{
						minv[j] = cur;
						way[j] = j0;
					}
					if (minv[j] < delta)
					{
						delta = minv[j];
						j1 = j;
					}
				}
			}
			assert(j1 != -1);
			FOR (j, 0, m + 1)
			{
				if (used[j])
				{
					u[p[j]] += delta;
					v[j] -= delta;
				}
				else
					minv[j] -= delta;
			}
			j0 = j1;
		}
		while (j0 != m)
		{
			int j1 = way[j0];
			p[j0] = p[j1];
			j0 = j1;
		}
	}
	VI ans(n + 1);
	FOR (j, 0, m)
		ans[p[j]] = j;
	LL res = 0;
	FOR (i, 0, n)
		res += a[i][ans[i]];
	assert(res == -v[m]);
	return res;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<VI> v(n, VI(n));
	FOR (i, 0, n)
		FOR (j, 0, n)
			cin >> v[i][j];
	
	int m = (n + 1) / 2;
	vector<VL> a(m, VL(m));
	FOR (i, 0, n)
	{
		FOR (j, 0, n)
		{
			if (j)
				a[i / 2][j / 2] += 1000ll * v[i][j - 1];
			if (j != n - 1)
				a[i / 2][j / 2] += 1000ll * v[i][j + 1];
			j++;
		}
		i++;
	}
	cout << hungarian(a) / 1000 << '\n';
	
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

input:

4
0 3 2 13
3 0 8 9
2 8 0 5
13 9 5 0

output:

16

result:

ok single line: '16'

Test #2:

score: 0
Accepted
time: 14ms
memory: 4896kb

input:

455
0 71154840 37432199 724743679 761809953 949789082 725973225 28455138 924138757 574256423 297516452 223475432 693485895 699629134 731875885 697643903 595490098 206757530 965177624 178416136 103223719 474785234 322984824 510200285 656185874 993023494 973542087 511171280 465648799 836547414 8145240...

output:

25287020967

result:

ok single line: '25287020967'

Test #3:

score: 0
Accepted
time: 17ms
memory: 4940kb

input:

470
0 825773262 213123312 958735588 875262080 529965815 647258178 589187724 150554396 639675837 505431833 241926753 676024923 951655606 751190042 900088699 505896341 480504640 860229682 343579317 594095469 760186193 7251119 439955409 331946374 859232943 172319278 560487784 205703803 554409035 314581...

output:

25826474937

result:

ok single line: '25826474937'

Test #4:

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

input:

480
0 638279197 953395101 315841589 190876825 172202947 822281654 835528012 43378954 217314869 888606228 294040143 507542160 515152746 537213903 560414322 802474060 640698231 312153029 558028614 732105506 930600004 606966802 419394315 250138936 41739180 748344895 242251937 734936255 142469718 102354...

output:

26336795106

result:

ok single line: '26336795106'

Test #5:

score: 0
Accepted
time: 17ms
memory: 5144kb

input:

500
0 271055505 467823142 624225824 294558633 174506982 338830867 295282133 24033584 663300399 845976062 5370597 990574201 995095221 954249676 464565017 984175133 419079 496291632 140804088 171417245 513380843 317620894 627584068 104424012 588544968 281299375 118971040 832469586 168989422 729952331 ...

output:

25612699451

result:

ok single line: '25612699451'

Test #6:

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

input:

5
0 6 8 5 7
6 0 6 5 2
8 6 0 6 7
5 5 6 0 2
7 2 7 2 0

output:

15

result:

ok single line: '15'

Test #7:

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

input:

20
0 18 17 13 9 5 14 6 11 11 10 8 11 15 9 10 12 6 8 6
18 0 15 8 7 6 10 6 18 13 16 8 8 6 17 15 11 14 20 11
17 15 0 18 15 20 19 20 20 20 17 6 20 9 19 17 16 10 9 7
13 8 18 0 12 10 12 11 9 11 13 16 11 11 12 11 8 19 16 7
9 7 15 12 0 9 18 5 9 15 10 18 19 6 5 11 6 8 8 6
5 6 20 10 9 0 20 5 19 6 8 19 18 18 1...

output:

164

result:

ok single line: '164'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

115
0 865 34 987 777 734 527 366 816 42 440 365 81 640 401 363 878 671 418 327 51 330 429 249 109 903 846 48 555 191 369 225 90 786 654 689 859 604 279 828 418 945 783 644 293 271 612 811 62 838 794 221 757 488 516 106 906 410 899 123 713 715 111 709 720 828 816 927 835 55 319 978 107 71 355 793 645...

output:

13442

result:

ok single line: '13442'

Test #9:

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

input:

220
0 708055136 558153752 803780811 981999328 865616773 598692339 766818310 937322566 627412534 962093305 226953666 151728158 68579122 277664598 976466269 224792777 578004771 285120404 235088218 870261374 724892344 899063685 358339369 241472780 71976192 165580673 322334942 922436874 757041442 182629...

output:

16871810222

result:

ok single line: '16871810222'

Test #10:

score: 0
Accepted
time: 9ms
memory: 4276kb

input:

350
0 421998352 523603040 796382092 91424421 464787607 902495820 125896606 404187895 384025663 699034829 18384263 56425709 125752656 497399609 191876238 238124796 932044340 90985717 628792974 541316819 821873170 451288918 594813049 750309929 996720702 78898583 40085413 223043435 290684194 208376004 ...

output:

21842464629

result:

ok single line: '21842464629'

Test #11:

score: 0
Accepted
time: 18ms
memory: 5140kb

input:

500
0 792995023 553875768 182354107 302743850 723186733 783697344 963306331 343718682 420747326 772514449 510043133 468199618 626546646 837859489 46956583 810591469 620840830 507432307 885703699 894446089 341962012 619520244 449708344 137169264 856682700 462462183 490094730 586061684 626198973 73871...

output:

24720849408

result:

ok single line: '24720849408'

Test #12:

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

input:

5
0 4 7 4 5
4 0 4 2 8
7 4 0 7 8
4 2 7 0 2
5 8 8 2 0

output:

14

result:

ok single line: '14'

Test #13:

score: 0
Accepted
time: 14ms
memory: 5080kb

input:

500
0 723821412 343258393 132979091 265916958 702165482 740799254 28158360 830572003 797445180 71977672 898666079 535051096 406011707 972518590 659013123 770875627 522693906 998659141 80354392 962815250 862684644 746570655 976335397 333656534 643674799 37641561 8182557 546607515 810928481 496648361 ...

output:

25956063077

result:

ok single line: '25956063077'

Test #14:

score: 0
Accepted
time: 17ms
memory: 5084kb

input:

500
0 124415645 212951846 199098405 212995717 344517367 94556575 784826747 786137126 146652983 173549414 389679115 811694968 365318584 453510445 142878109 118308948 48194378 879015335 308208699 200747783 808800603 84684629 383615373 405103042 963965806 790504463 88911469 485916357 322779326 10674067...

output:

26913162644

result:

ok single line: '26913162644'

Test #15:

score: 0
Accepted
time: 14ms
memory: 5380kb

input:

500
0 785257150 527635995 690768698 174424922 149350289 546533239 898420788 638562012 885563953 647059319 355978500 312513279 45822504 638454554 40421610 749816190 868908917 566710764 114576434 271622154 427412836 582795779 500808179 429883276 142796516 126727054 689740232 757525277 779017848 188332...

output:

26325954680

result:

ok single line: '26325954680'

Test #16:

score: 0
Accepted
time: 13ms
memory: 5084kb

input:

500
0 789165900 393830829 428278008 508855324 461586964 231990857 434280242 462194681 413195465 381235544 379607426 753211530 219563549 522589713 590318872 892829850 180796460 312485394 535395347 222315046 759396724 95580421 414432859 706955872 140569583 734938767 282811209 620566707 913051132 97789...

output:

26500309412

result:

ok single line: '26500309412'

Test #17:

score: 0
Accepted
time: 18ms
memory: 5120kb

input:

500
0 260616932 594072267 47176563 195468577 31844420 718424026 359911602 519221177 80611021 310162253 51397898 394859678 740775001 338849616 678010847 424817666 446281885 294349921 750239745 407378522 436151882 259813867 663713759 755897100 474144904 545251784 793475429 612104554 516694561 92666247...

output:

24961709513

result:

ok single line: '24961709513'

Test #18:

score: 0
Accepted
time: 17ms
memory: 5076kb

input:

500
0 817469787 850353548 756189933 549650666 188521921 728304681 27792651 962034252 39427936 787473640 874481357 398831694 768376067 594446197 844542961 283667519 579548917 297292351 287285670 511701348 263831288 398916267 982635698 105746460 444544398 709526391 149112023 435969194 14529804 6356764...

output:

25908588927

result:

ok single line: '25908588927'

Test #19:

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

input:

5
0 11 13 15 11
11 0 10 10 10
13 10 0 12 13
15 10 12 0 15
11 10 13 15 0

output:

47

result:

ok single line: '47'

Test #20:

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

input:

25
0 81 83 81 85 83 87 83 88 87 85 83 82 87 82 82 83 86 81 80 88 86 88 87 86
81 0 87 85 82 84 80 84 85 85 85 84 87 86 83 86 80 86 81 83 86 85 81 88 82
83 87 0 85 88 80 83 81 82 88 81 83 80 85 83 84 80 82 85 82 81 84 88 80 85
81 85 85 0 80 87 87 85 80 86 83 80 85 81 82 86 80 84 88 88 84 88 80 82 81
8...

output:

1951

result:

ok single line: '1951'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

80
0 92 91 93 92 91 92 90 92 91 91 90 90 90 92 91 90 90 93 92 91 93 93 90 92 90 93 92 90 90 93 90 90 93 93 90 92 93 92 92 91 93 90 90 93 93 91 91 92 91 92 92 92 91 91 92 93 91 93 93 90 93 93 92 90 93 91 92 92 93 93 91 90 91 90 92 92 92 91 93
92 0 90 93 92 93 91 92 91 91 92 91 92 91 92 93 93 90 92 92...

output:

7119

result:

ok single line: '7119'

Test #22:

score: 0
Accepted
time: 2ms
memory: 3824kb

input:

150
0 13358 13373 13363 13357 13369 13367 13357 13371 13376 13359 13378 13372 13370 13371 13370 13362 13358 13371 13363 13374 13351 13376 13358 13374 13364 13350 13378 13377 13374 13359 13352 13367 13357 13354 13370 13355 13364 13354 13357 13353 13360 13376 13367 13374 13349 13368 13371 13371 13376 ...

output:

1989368

result:

ok single line: '1989368'

Test #23:

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

input:

20
0 19 5 15 15 13 8 14 17 14 13 20 18 18 8 12 13 12 18 10
19 0 14 5 15 12 12 19 19 16 14 7 12 14 8 18 10 20 12 13
5 14 0 6 8 20 13 7 9 5 11 12 17 12 15 15 15 8 13 13
15 5 6 0 15 8 10 20 20 20 16 20 7 18 16 13 9 20 13 12
15 15 8 15 0 17 19 13 10 20 13 13 9 16 6 20 6 12 16 20
13 12 20 8 17 0 13 18 8 ...

output:

168

result:

ok single line: '168'

Test #24:

score: 0
Accepted
time: 2ms
memory: 3900kb

input:

200
0 569 627 594 611 610 575 654 631 551 607 648 605 560 561 614 590 638 606 633 573 630 586 583 598 656 623 616 660 620 634 645 654 571 636 620 652 597 587 646 552 617 645 650 584 577 633 609 565 649 599 583 594 571 649 646 617 554 619 571 593 621 602 613 638 601 591 553 652 607 600 554 579 657 64...

output:

111273

result:

ok single line: '111273'

Test #25:

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

input:

250
0 14 15 15 13 14 15 17 17 17 14 15 15 14 16 14 17 14 17 15 13 16 14 15 17 17 13 15 14 13 13 17 14 13 14 14 14 13 16 14 14 17 14 15 13 13 15 16 14 15 14 16 14 17 14 16 17 16 15 16 14 13 13 16 17 14 16 16 14 14 14 13 16 14 17 14 16 15 13 16 14 13 14 15 17 13 13 13 16 16 13 17 14 13 14 16 16 17 17 ...

output:

3239

result:

ok single line: '3239'

Test #26:

score: 0
Accepted
time: 6ms
memory: 4272kb

input:

337
0 211 123 220 167 112 87 77 70 96 55 167 25 92 148 220 25 180 51 159 119 40 163 183 35 77 173 118 53 113 65 143 213 107 209 90 189 121 150 28 80 154 177 93 63 98 166 132 103 50 176 111 195 103 121 30 47 64 24 195 187 141 131 170 62 189 133 196 43 192 65 83 69 105 56 214 141 102 130 129 76 182 14...

output:

11259

result:

ok single line: '11259'

Test #27:

score: 0
Accepted
time: 9ms
memory: 4580kb

input:

399
0 15723 15705 15819 15710 15733 15798 15773 15808 15673 15609 15862 15891 15555 15793 15610 15691 15718 15610 15686 15773 15767 15898 15897 15543 15893 15692 15846 15794 15793 15898 15652 15542 15549 15682 15902 15793 15720 15602 15584 15737 15611 15683 15752 15556 15725 15661 15774 15765 15712 ...

output:

6179498

result:

ok single line: '6179498'

Test #28:

score: 0
Accepted
time: 13ms
memory: 4748kb

input:

429
0 999997882 999999529 999998725 999999698 999998408 999998536 999999457 999997794 999997434 999997956 999998382 999997801 999998819 999999566 999997978 999999362 999997731 999997606 999999979 999998323 999998262 999997072 999997889 999997322 999997975 999997477 999998673 999999020 999998930 9999...

output:

427998787309

result:

ok single line: '427998787309'

Test #29:

score: 0
Accepted
time: 18ms
memory: 5116kb

input:

500
0 999397296 999397311 999397269 999397071 999397647 999397373 999397442 999397425 999397126 999397246 999397820 999397085 999397788 999397780 999397424 999397053 999397184 999397321 999397378 999397680 999397152 999397558 999397288 999397636 999397027 999397504 999397777 999397162 999397113 9993...

output:

498699123296

result:

ok single line: '498699123296'

Test #30:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

115
0 684 711 566 170 492 545 770 15 332 869 2 597 38 948 673 945 89 35 245 513 159 621 45 859 199 913 494 61 944 382 300 520 434 137 943 367 211 189 150 899 339 915 308 200 181 920 185 738 209 114 805 433 880 186 493 905 560 880 2 701 140 213 974 646 897 388 78 19 76 477 872 601 619 368 333 68 947 ...

output:

12407

result:

ok single line: '12407'

Test #31:

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

input:

220
0 154790186 816945465 492356879 425095241 412833653 87979923 632698505 567713212 615080363 216737790 648065152 565594360 39011126 89290839 388785942 853456654 992721322 622881847 899144559 849170618 260546883 246657404 260529834 832257178 582358576 538409250 978580094 245609501 181215738 9565529...

output:

17027827260

result:

ok single line: '17027827260'

Test #32:

score: 0
Accepted
time: 9ms
memory: 4384kb

input:

350
0 685570452 941005518 247996973 840389822 687711677 828904090 734586473 348783442 668076856 230214908 8293003 281573644 813405737 849401689 317188153 730409812 644275992 234615295 916269905 768552869 381648162 106631857 115756026 736700028 388360171 511678538 432261315 846810223 57832519 1409928...

output:

20344885079

result:

ok single line: '20344885079'

Test #33:

score: 0
Accepted
time: 14ms
memory: 5340kb

input:

500
0 41788458 690053862 62162080 879119603 478485135 910106649 652791279 85542104 104388223 513145330 806498051 617966191 34978173 742542750 672330102 411559405 853682768 914271910 666635208 100452973 163456358 553091706 973223823 69124179 466407199 472390506 983437300 496863295 33468098 507845877 ...

output:

26625522149

result:

ok single line: '26625522149'

Test #34:

score: 0
Accepted
time: 11ms
memory: 4552kb

input:

400
0 656554809 996975688 667054661 228552571 766288296 776289781 995818791 979272529 521363650 761864709 887894377 146413308 559816599 596552785 73498006 194801507 758955803 460586428 344651773 870593230 345222498 735325132 183247931 575850409 449566857 294900325 606040822 683667770 482363755 85964...

output:

22305972181

result:

ok single line: '22305972181'

Test #35:

score: 0
Accepted
time: 14ms
memory: 5060kb

input:

450
0 288972144 672805249 186762453 529044882 902281586 383920344 949807860 329983388 117555464 663031149 96650222 815794816 355597548 706795500 340917086 129050308 701080642 70563871 215547858 320576129 272986143 378597293 534466262 41648879 171600969 922415890 648240749 57492273 203261037 76451605...

output:

24123463442

result:

ok single line: '24123463442'