QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297981#4633. Coprime Matricesdefyers#AC ✓5ms4584kbC++171.7kb2024-01-05 15:18:572024-01-05 15:18:57

Judging History

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

  • [2024-01-05 15:18:57]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:4584kb
  • [2024-01-05 15:18:57]
  • 提交

answer

#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC targetr("avx2")

using namespace std;

using ll = long long;
using pii = pair<int, int>;

int n, m, X, Y, w;
vector<pair<int, int>> pl;
bool vis[305][305];
int ans[305][305];

void solve(int TC) {
	cin >> n >> m >> X >> Y >> w;
	int start;
	for (int i = 2; i <= m; i += 2) {
		int x = 1, y = i;
		int ct = 0;
		while (true) {
			vis[x][y] = true;
			pl.push_back({x,y});
			if (x == X && y == Y) {
				start = pl.size() - 1;
			}
			if (ct == 1) {
				x++;
			}
			else {
				y--;
			}
			if (x > n || x < 1 || y > m || y < 1) break;
			ct = 1 - ct;
		}
	}
	for (int i = 1; i <= n; i++) {
		int x = i, y = m;
		if (vis[x][y]) continue;
		int ct = 0;
		if (vis[x][y - 1]) ct = 1;
		while (true) {
			vis[x][y] = true;
			pl.push_back({x, y});
			if (x == X && y == Y) {
				start = pl.size() - 1;
			}
			if (ct == 1) {
				x++;
			}
			else {
				y--;
			}
			if (x > n || x < 1 || y > m || y < 1) break;
			ct = 1 - ct;
		}
	}
	int num = w;
	for (int i = start; i < pl.size(); i++) {
		ans[pl[i].first][pl[i].second] = num;
		num++;
		if (num > n * m) num = 1;
	}
	for (int i = 0; i < start; i++) {
		//cout << "pl " << i << " = " << pl[i].first << " " << pl[i].second << endl;
		ans[pl[i].first][pl[i].second] = num;
		num++;
		if (num > n * m) num = 1;
	}
	cout << "Yes\n";
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << ans[i][j] << " \n"[j == m];
		}
	}
	return;
}

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(10);

	int t = 1;
	// cin >> t;
	for (int i = 1; i <= t; i++) {
		solve(i);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

3 3 2 1 3

output:

Yes
2 1 4
3 6 5
8 7 9

result:

ok OK, Accepted.

Test #2:

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

input:

1 1 1 1 1

output:

Yes
1

result:

ok OK, Accepted.

Test #3:

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

input:

8 3 4 2 9

output:

Yes
23 22 1
24 3 2
5 4 7
6 9 8
11 10 13
12 15 14
17 16 19
18 21 20

result:

ok OK, Accepted.

Test #4:

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

input:

7 6 7 2 28

output:

Yes
41 40 2 1 9 8
42 4 3 11 10 19
6 5 13 12 21 20
7 15 14 23 22 30
17 16 25 24 32 31
18 27 26 34 33 37
29 28 36 35 39 38

result:

ok OK, Accepted.

Test #5:

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

input:

6 8 1 2 7

output:

Yes
8 7 11 10 18 17 29 28
9 13 12 20 19 31 30 40
15 14 22 21 33 32 42 41
16 24 23 35 34 44 43 1
26 25 37 36 46 45 3 2
27 39 38 48 47 5 4 6

result:

ok OK, Accepted.

Test #6:

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

input:

8 8 7 3 56

output:

Yes
11 10 14 13 21 20 32 31
12 16 15 23 22 34 33 46
18 17 25 24 36 35 48 47
19 27 26 38 37 50 49 59
29 28 40 39 52 51 61 60
30 42 41 54 53 63 62 4
44 43 56 55 1 64 6 5
45 58 57 3 2 8 7 9

result:

ok OK, Accepted.

Test #7:

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

input:

2 4 2 1 8

output:

Yes
7 6 2 1
8 4 3 5

result:

ok OK, Accepted.

Test #8:

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

input:

6 6 4 2 17

output:

Yes
1 36 4 3 11 10
2 6 5 13 12 21
8 7 15 14 23 22
9 17 16 25 24 30
19 18 27 26 32 31
20 29 28 34 33 35

result:

ok OK, Accepted.

Test #9:

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

input:

8 6 3 1 33

output:

Yes
26 25 29 28 36 35
27 31 30 38 37 46
33 32 40 39 48 47
34 42 41 2 1 10
44 43 4 3 12 11
45 6 5 14 13 19
8 7 16 15 21 20
9 18 17 23 22 24

result:

ok OK, Accepted.

Test #10:

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

input:

2 8 2 4 15

output:

Yes
6 5 9 8 13 12 1 16
7 11 10 15 14 3 2 4

result:

ok OK, Accepted.

Test #11:

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

input:

295 280 79 198 74034

output:

Yes
36204 36203 36207 36206 36214 36213 36225 36224 36240 36239 36259 36258 36282 36281 36309 36308 36340 36339 36375 36374 36414 36413 36457 36456 36504 36503 36555 36554 36610 36609 36669 36668 36732 36731 36799 36798 36870 36869 36945 36944 37024 37023 37107 37106 37194 37193 37285 37284 37380 37...

result:

ok OK, Accepted.

Test #12:

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

input:

300 26 55 17 3020

output:

Yes
1508 1507 1511 1510 1518 1517 1529 1528 1544 1543 1563 1562 1586 1585 1613 1612 1644 1643 1679 1678 1718 1717 1761 1760 1808 1807
1509 1513 1512 1520 1519 1531 1530 1546 1545 1565 1564 1588 1587 1615 1614 1646 1645 1681 1680 1720 1719 1763 1762 1810 1809 1858
1515 1514 1522 1521 1533 1532 1548 1...

result:

ok OK, Accepted.

Test #13:

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

input:

288 282 125 58 43649

output:

Yes
27112 27111 27115 27114 27122 27121 27133 27132 27148 27147 27167 27166 27190 27189 27217 27216 27248 27247 27283 27282 27322 27321 27365 27364 27412 27411 27463 27462 27518 27517 27577 27576 27640 27639 27707 27706 27778 27777 27853 27852 27932 27931 28015 28014 28102 28101 28193 28192 28288 28...

result:

ok OK, Accepted.

Test #14:

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

input:

128 299 59 164 38067

output:

Yes
17920 17919 17923 17922 17930 17929 17941 17940 17956 17955 17975 17974 17998 17997 18025 18024 18056 18055 18091 18090 18130 18129 18173 18172 18220 18219 18271 18270 18326 18325 18385 18384 18448 18447 18515 18514 18586 18585 18661 18660 18740 18739 18823 18822 18910 18909 19001 19000 19096 19...

result:

ok OK, Accepted.

Test #15:

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

input:

300 300 286 253 60209

output:

Yes
62131 62130 62134 62133 62141 62140 62152 62151 62167 62166 62186 62185 62209 62208 62236 62235 62267 62266 62302 62301 62341 62340 62384 62383 62431 62430 62482 62481 62537 62536 62596 62595 62659 62658 62726 62725 62797 62796 62872 62871 62951 62950 63034 63033 63121 63120 63212 63211 63307 63...

result:

ok OK, Accepted.

Test #16:

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

input:

240 77 171 56 15870

output:

Yes
1506 1505 1509 1508 1516 1515 1527 1526 1542 1541 1561 1560 1584 1583 1611 1610 1642 1641 1677 1676 1716 1715 1759 1758 1806 1805 1857 1856 1912 1911 1971 1970 2034 2033 2101 2100 2172 2171 2247 2246 2326 2325 2409 2408 2496 2495 2587 2586 2682 2681 2781 2780 2884 2883 2991 2990 3102 3101 3217 3...

result:

ok OK, Accepted.

Test #17:

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

input:

165 141 69 107 11237

output:

Yes
19816 19815 19819 19818 19826 19825 19837 19836 19852 19851 19871 19870 19894 19893 19921 19920 19952 19951 19987 19986 20026 20025 20069 20068 20116 20115 20167 20166 20222 20221 20281 20280 20344 20343 20411 20410 20482 20481 20557 20556 20636 20635 20719 20718 20806 20805 20897 20896 20992 20...

result:

ok OK, Accepted.

Test #18:

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

input:

300 200 106 195 36560

output:

Yes
56850 56849 56853 56852 56860 56859 56871 56870 56886 56885 56905 56904 56928 56927 56955 56954 56986 56985 57021 57020 57060 57059 57103 57102 57150 57149 57201 57200 57256 57255 57315 57314 57378 57377 57445 57444 57516 57515 57591 57590 57670 57669 57753 57752 57840 57839 57931 57930 58026 58...

result:

ok OK, Accepted.

Test #19:

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

input:

247 46 55 25 776

output:

Yes
9544 9543 9547 9546 9554 9553 9565 9564 9580 9579 9599 9598 9622 9621 9649 9648 9680 9679 9715 9714 9754 9753 9797 9796 9844 9843 9895 9894 9950 9949 10009 10008 10072 10071 10139 10138 10210 10209 10285 10284 10364 10363 10447 10446 10534 10533
9545 9549 9548 9556 9555 9567 9566 9582 9581 9601 ...

result:

ok OK, Accepted.

Test #20:

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

input:

18 300 15 168 2858

output:

Yes
5144 5143 5147 5146 5154 5153 5165 5164 5180 5179 5199 5198 5222 5221 5249 5248 5280 5279 5315 5314 5351 5350 5387 5386 23 22 59 58 95 94 131 130 167 166 203 202 239 238 275 274 311 310 347 346 383 382 419 418 455 454 491 490 527 526 563 562 599 598 635 634 671 670 707 706 743 742 779 778 815 81...

result:

ok OK, Accepted.

Test #21:

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

input:

300 58 71 22 15741

output:

Yes
12102 12101 12105 12104 12112 12111 12123 12122 12138 12137 12157 12156 12180 12179 12207 12206 12238 12237 12273 12272 12312 12311 12355 12354 12402 12401 12453 12452 12508 12507 12567 12566 12630 12629 12697 12696 12768 12767 12843 12842 12922 12921 13005 13004 13092 13091 13183 13182 13278 13...

result:

ok OK, Accepted.

Test #22:

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

input:

290 262 3 217 58080

output:

Yes
34205 34204 34208 34207 34215 34214 34226 34225 34241 34240 34260 34259 34283 34282 34310 34309 34341 34340 34376 34375 34415 34414 34458 34457 34505 34504 34556 34555 34611 34610 34670 34669 34733 34732 34800 34799 34871 34870 34946 34945 35025 35024 35108 35107 35195 35194 35286 35285 35381 35...

result:

ok OK, Accepted.

Test #23:

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

input:

231 272 226 145 45674

output:

Yes
54465 54464 54468 54467 54475 54474 54486 54485 54501 54500 54520 54519 54543 54542 54570 54569 54601 54600 54636 54635 54675 54674 54718 54717 54765 54764 54816 54815 54871 54870 54930 54929 54993 54992 55060 55059 55131 55130 55206 55205 55285 55284 55368 55367 55455 55454 55546 55545 55641 55...

result:

ok OK, Accepted.

Test #24:

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

input:

300 116 15 107 32192

output:

Yes
24925 24924 24928 24927 24935 24934 24946 24945 24961 24960 24980 24979 25003 25002 25030 25029 25061 25060 25096 25095 25135 25134 25178 25177 25225 25224 25276 25275 25331 25330 25390 25389 25453 25452 25520 25519 25591 25590 25666 25665 25745 25744 25828 25827 25915 25914 26006 26005 26101 26...

result:

ok OK, Accepted.

Test #25:

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

input:

126 300 67 285 17771

output:

Yes
20592 20591 20595 20594 20602 20601 20613 20612 20628 20627 20647 20646 20670 20669 20697 20696 20728 20727 20763 20762 20802 20801 20845 20844 20892 20891 20943 20942 20998 20997 21057 21056 21120 21119 21187 21186 21258 21257 21333 21332 21412 21411 21495 21494 21582 21581 21673 21672 21768 21...

result:

ok OK, Accepted.

Test #26:

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

input:

231 117 51 40 8557

output:

Yes
4542 4541 4545 4544 4552 4551 4563 4562 4578 4577 4597 4596 4620 4619 4647 4646 4678 4677 4713 4712 4752 4751 4795 4794 4842 4841 4893 4892 4948 4947 5007 5006 5070 5069 5137 5136 5208 5207 5283 5282 5362 5361 5445 5444 5532 5531 5623 5622 5718 5717 5817 5816 5920 5919 6027 6026 6138 6137 6253 6...

result:

ok OK, Accepted.

Test #27:

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

input:

300 124 203 13 3245

output:

Yes
21314 21313 21317 21316 21324 21323 21335 21334 21350 21349 21369 21368 21392 21391 21419 21418 21450 21449 21485 21484 21524 21523 21567 21566 21614 21613 21665 21664 21720 21719 21779 21778 21842 21841 21909 21908 21980 21979 22055 22054 22134 22133 22217 22216 22304 22303 22395 22394 22490 22...

result:

ok OK, Accepted.

Test #28:

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

input:

62 146 44 52 331

output:

Yes
5360 5359 5363 5362 5370 5369 5381 5380 5396 5395 5415 5414 5438 5437 5465 5464 5496 5495 5531 5530 5570 5569 5613 5612 5660 5659 5711 5710 5766 5765 5825 5824 5888 5887 5955 5954 6026 6025 6101 6100 6180 6179 6263 6262 6350 6349 6441 6440 6536 6535 6635 6634 6738 6737 6845 6844 6956 6955 7071 7...

result:

ok OK, Accepted.

Test #29:

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

input:

40 52 22 17 1571

output:

Yes
864 863 867 866 874 873 885 884 900 899 919 918 942 941 969 968 1000 999 1035 1034 1074 1073 1117 1116 1164 1163 1215 1214 1270 1269 1329 1328 1392 1391 1459 1458 1530 1529 1605 1604 1684 1683 1764 1763 1844 1843 1924 1923 2004 2003 4 3
865 869 868 876 875 887 886 902 901 921 920 944 943 971 970...

result:

ok OK, Accepted.

Test #30:

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

input:

300 300 23 278 19171

output:

Yes
64577 64576 64580 64579 64587 64586 64598 64597 64613 64612 64632 64631 64655 64654 64682 64681 64713 64712 64748 64747 64787 64786 64830 64829 64877 64876 64928 64927 64983 64982 65042 65041 65105 65104 65172 65171 65243 65242 65318 65317 65397 65396 65480 65479 65567 65566 65658 65657 65753 65...

result:

ok OK, Accepted.

Test #31:

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

input:

271 253 159 69 51872

output:

Yes
25905 25904 25908 25907 25915 25914 25926 25925 25941 25940 25960 25959 25983 25982 26010 26009 26041 26040 26076 26075 26115 26114 26158 26157 26205 26204 26256 26255 26311 26310 26370 26369 26433 26432 26500 26499 26571 26570 26646 26645 26725 26724 26808 26807 26895 26894 26986 26985 27081 27...

result:

ok OK, Accepted.

Test #32:

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

input:

124 259 8 165 20677

output:

Yes
7210 7209 7213 7212 7220 7219 7231 7230 7246 7245 7265 7264 7288 7287 7315 7314 7346 7345 7381 7380 7420 7419 7463 7462 7510 7509 7561 7560 7616 7615 7675 7674 7738 7737 7805 7804 7876 7875 7951 7950 8030 8029 8113 8112 8200 8199 8291 8290 8386 8385 8485 8484 8588 8587 8695 8694 8806 8805 8921 8...

result:

ok OK, Accepted.

Test #33:

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

input:

300 179 80 58 9660

output:

Yes
186 185 189 188 196 195 207 206 222 221 241 240 264 263 291 290 322 321 357 356 396 395 439 438 486 485 537 536 592 591 651 650 714 713 781 780 852 851 927 926 1006 1005 1089 1088 1176 1175 1267 1266 1362 1361 1461 1460 1564 1563 1671 1670 1782 1781 1897 1896 2016 2015 2139 2138 2266 2265 2397 2...

result:

ok OK, Accepted.

Test #34:

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

input:

97 95 71 13 1081

output:

Yes
6753 6752 6756 6755 6763 6762 6774 6773 6789 6788 6808 6807 6831 6830 6858 6857 6889 6888 6924 6923 6963 6962 7006 7005 7053 7052 7104 7103 7159 7158 7218 7217 7281 7280 7348 7347 7419 7418 7494 7493 7573 7572 7656 7655 7743 7742 7834 7833 7929 7928 8028 8027 8131 8130 8238 8237 8349 8348 8464 8...

result:

ok OK, Accepted.

Test #35:

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

input:

288 300 233 151 62807

output:

Yes
83625 83624 83628 83627 83635 83634 83646 83645 83661 83660 83680 83679 83703 83702 83730 83729 83761 83760 83796 83795 83835 83834 83878 83877 83925 83924 83976 83975 84031 84030 84090 84089 84153 84152 84220 84219 84291 84290 84366 84365 84445 84444 84528 84527 84615 84614 84706 84705 84801 84...

result:

ok OK, Accepted.

Test #36:

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

input:

300 259 206 73 42316

output:

Yes
3871 3870 3874 3873 3881 3880 3892 3891 3907 3906 3926 3925 3949 3948 3976 3975 4007 4006 4042 4041 4081 4080 4124 4123 4171 4170 4222 4221 4277 4276 4336 4335 4399 4398 4466 4465 4537 4536 4612 4611 4691 4690 4774 4773 4861 4860 4952 4951 5047 5046 5146 5145 5249 5248 5356 5355 5467 5466 5582 5...

result:

ok OK, Accepted.

Test #37:

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

input:

149 295 129 201 30873

output:

Yes
37356 37355 37359 37358 37366 37365 37377 37376 37392 37391 37411 37410 37434 37433 37461 37460 37492 37491 37527 37526 37566 37565 37609 37608 37656 37655 37707 37706 37762 37761 37821 37820 37884 37883 37951 37950 38022 38021 38097 38096 38176 38175 38259 38258 38346 38345 38437 38436 38532 38...

result:

ok OK, Accepted.

Test #38:

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

input:

121 252 57 39 17402

output:

Yes
12825 12824 12828 12827 12835 12834 12846 12845 12861 12860 12880 12879 12903 12902 12930 12929 12961 12960 12996 12995 13035 13034 13078 13077 13125 13124 13176 13175 13231 13230 13290 13289 13353 13352 13420 13419 13491 13490 13566 13565 13645 13644 13728 13727 13815 13814 13906 13905 14001 14...

result:

ok OK, Accepted.

Test #39:

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

input:

300 37 136 22 4789

output:

Yes
10754 10753 10757 10756 10764 10763 10775 10774 10790 10789 10809 10808 10832 10831 10859 10858 10890 10889 10925 10924 10964 10963 11007 11006 11054 11053 5 4 60 59 119 118 182 181 249 248 319
10755 10759 10758 10766 10765 10777 10776 10792 10791 10811 10810 10834 10833 10861 10860 10892 10891 ...

result:

ok OK, Accepted.

Test #40:

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

input:

300 300 298 186 66405

output:

Yes
73081 73080 73084 73083 73091 73090 73102 73101 73117 73116 73136 73135 73159 73158 73186 73185 73217 73216 73252 73251 73291 73290 73334 73333 73381 73380 73432 73431 73487 73486 73546 73545 73609 73608 73676 73675 73747 73746 73822 73821 73901 73900 73984 73983 74071 74070 74162 74161 74257 74...

result:

ok OK, Accepted.