QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360067 | #4633. Coprime Matrices | Kevin5307 | AC ✓ | 4ms | 5256kb | C++20 | 2.0kb | 2024-03-21 11:06:47 | 2024-03-21 11:06:48 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int ind[303][303],ans[303][303];
int rep[303];
bool used[100100];
int psum[200100];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m,x,y,w;
cin>>n>>m>>x>>y>>w;
for(int i=2;i<n;i+=2)
{
int tot=0;
for(int j=1;j<=m;j++)
if(j%2)
{
ind[i][j]=++tot;
ind[i+1][j]=++tot;
}
else
{
ind[i+1][j]=++tot;
ind[i][j]=++tot;
}
}
if(!ind[x][y])
{
ans[x][y]=w;
used[w]=1;
psum[w]=1;
}
else
{
rep[x/2*2]=(w-ind[x][y]+n*m)%(n*m)+1;
for(int i=0;i<m+m;i++)
used[(rep[x/2*2]+i-1)%(n*m)+1]=psum[(rep[x/2*2]+i-1)%(n*m)+1]=1;
}
for(int i=1;i<=n*m;i++)
psum[i+n*m]=psum[i];
for(int i=1;i<=n*m+n*m;i++)
psum[i]+=psum[i-1];
int p;
if(!ind[x][y])
p=1;
else
p=(rep[x/2*2]+m+m-1)%(n*m)+1;
for(int i=2;i<n;i+=2)
if(!rep[i])
{
while(psum[p+m+m-1]!=psum[p-1])
p++;
rep[i]=p;
p+=m+m;
}
for(int i=2;i<n;i+=2)
for(int j=1;j<=m;j++)
for(int k=0;k<2;k++)
{
ans[i+k][j]=(rep[i]+ind[i+k][j]-2+n*m)%(n*m)+1;
used[ans[i+k][j]]=1;
}
p=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(!ind[i][j]&&!ans[i][j])
{
while(used[p]) p++;
used[p]=1;
ans[i][j]=p;
}
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 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3760kb
input:
3 3 2 1 3
output:
Yes 1 2 9 3 6 7 4 5 8
result:
ok OK, Accepted.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
1 1 1 1 1
output:
Yes 1
result:
ok OK, Accepted.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
8 3 4 2 9
output:
Yes 1 2 3 12 15 16 13 14 17 6 9 10 7 8 11 18 21 22 19 20 23 4 5 24
result:
ok OK, Accepted.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
7 6 7 2 28
output:
Yes 20 21 22 23 24 25 38 41 42 3 4 7 39 40 1 2 5 6 8 11 12 15 16 19 9 10 13 14 17 18 26 29 30 33 34 37 27 28 31 32 35 36
result:
ok OK, Accepted.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
6 8 1 2 7
output:
Yes 1 7 2 3 4 5 6 40 8 11 12 15 16 19 20 23 9 10 13 14 17 18 21 22 24 27 28 31 32 35 36 39 25 26 29 30 33 34 37 38 41 42 43 44 45 46 47 48
result:
ok OK, Accepted.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
8 8 7 3 56
output:
Yes 35 36 37 38 39 40 41 42 3 6 7 10 11 14 15 18 4 5 8 9 12 13 16 17 19 22 23 26 27 30 31 34 20 21 24 25 28 29 32 33 51 54 55 58 59 62 63 2 52 53 56 57 60 61 64 1 43 44 45 46 47 48 49 50
result:
ok OK, Accepted.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 4 2 1 8
output:
Yes 1 2 3 4 8 5 6 7
result:
ok OK, Accepted.
Test #8:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
6 6 4 2 17
output:
Yes 2 3 4 5 6 7 26 29 30 33 34 1 27 28 31 32 35 36 14 17 18 21 22 25 15 16 19 20 23 24 8 9 10 11 12 13
result:
ok OK, Accepted.
Test #9:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
8 6 3 1 33
output:
Yes 20 21 22 23 24 25 32 35 36 39 40 43 33 34 37 38 41 42 44 47 48 3 4 7 45 46 1 2 5 6 8 11 12 15 16 19 9 10 13 14 17 18 26 27 28 29 30 31
result:
ok OK, Accepted.
Test #10:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
2 8 2 4 15
output:
Yes 1 2 3 4 5 6 7 8 9 10 11 15 12 13 14 16
result:
ok OK, Accepted.
Test #11:
score: 0
Accepted
time: 4ms
memory: 5108kb
input:
295 280 79 198 74034
output:
Yes 73360 73361 73362 73363 73364 73365 73366 73367 73368 73369 73370 73371 73372 73373 73374 73375 73376 73377 73378 73379 73380 73381 73382 73383 73384 73385 73386 73387 73388 73389 73390 73391 73392 73393 73394 73395 73396 73397 73398 73399 73400 73401 73402 73403 73404 73405 73406 73407 73408 73...
result:
ok OK, Accepted.
Test #12:
score: 0
Accepted
time: 1ms
memory: 4404kb
input:
300 26 55 17 3020
output:
Yes 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 3039 3042 3043 3046 3047 3050 3051 3054 3055 3058 3059 3062 3063 3066 3067 3070 3071 3074 3075 3078 3079 3082 3083 3086 3087 3090 3040 3041 3044 3045 3048 3049 3052 3...
result:
ok OK, Accepted.
Test #13:
score: 0
Accepted
time: 4ms
memory: 5144kb
input:
288 282 125 58 43649
output:
Yes 42971 42972 42973 42974 42975 42976 42977 42978 42979 42980 42981 42982 42983 42984 42985 42986 42987 42988 42989 42990 42991 42992 42993 42994 42995 42996 42997 42998 42999 43000 43001 43002 43003 43004 43005 43006 43007 43008 43009 43010 43011 43012 43013 43014 43015 43016 43017 43018 43019 43...
result:
ok OK, Accepted.
Test #14:
score: 0
Accepted
time: 2ms
memory: 4324kb
input:
128 299 59 164 38067
output:
Yes 37143 37144 37145 37146 37147 37148 37149 37150 37151 37152 37153 37154 37155 37156 37157 37158 37159 37160 37161 37162 37163 37164 37165 37166 37167 37168 37169 37170 37171 37172 37173 37174 37175 37176 37177 37178 37179 37180 37181 37182 37183 37184 37185 37186 37187 37188 37189 37190 37191 37...
result:
ok OK, Accepted.
Test #15:
score: 0
Accepted
time: 2ms
memory: 5256kb
input:
300 300 286 253 60209
output:
Yes 59105 59106 59107 59108 59109 59110 59111 59112 59113 59114 59115 59116 59117 59118 59119 59120 59121 59122 59123 59124 59125 59126 59127 59128 59129 59130 59131 59132 59133 59134 59135 59136 59137 59138 59139 59140 59141 59142 59143 59144 59145 59146 59147 59148 59149 59150 59151 59152 59153 59...
result:
ok OK, Accepted.
Test #16:
score: 0
Accepted
time: 1ms
memory: 4408kb
input:
240 77 171 56 15870
output:
Yes 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 15630 15631 15632 15633 15634 15635 15636 15637 15638 15639 15640 15641 15642 15643 15644 15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15...
result:
ok OK, Accepted.
Test #17:
score: 0
Accepted
time: 1ms
memory: 4220kb
input:
165 141 69 107 11237
output:
Yes 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10...
result:
ok OK, Accepted.
Test #18:
score: 0
Accepted
time: 3ms
memory: 4992kb
input:
300 200 106 195 36560
output:
Yes 35772 35773 35774 35775 35776 35777 35778 35779 35780 35781 35782 35783 35784 35785 35786 35787 35788 35789 35790 35791 35792 35793 35794 35795 35796 35797 35798 35799 35800 35801 35802 35803 35804 35805 35806 35807 35808 35809 35810 35811 35812 35813 35814 35815 35816 35817 35818 35819 35820 35...
result:
ok OK, Accepted.
Test #19:
score: 0
Accepted
time: 1ms
memory: 4392kb
input:
247 46 55 25 776
output:
Yes 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 819 822 823 826 827 830 831 834 835 838 839 842 843 846 847 850 851 854 855 858 859 862 863 866 867 870 871 874 ...
result:
ok OK, Accepted.
Test #20:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
18 300 15 168 2858
output:
Yes 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1...
result:
ok OK, Accepted.
Test #21:
score: 0
Accepted
time: 0ms
memory: 4620kb
input:
300 58 71 22 15741
output:
Yes 15583 15584 15585 15586 15587 15588 15589 15590 15591 15592 15593 15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 15630 15631 15...
result:
ok OK, Accepted.
Test #22:
score: 0
Accepted
time: 0ms
memory: 5044kb
input:
290 262 3 217 58080
output:
Yes 57123 57124 57125 57126 57127 57128 57129 57130 57131 57132 57133 57134 57135 57136 57137 57138 57139 57140 57141 57142 57143 57144 57145 57146 57147 57148 57149 57150 57151 57152 57153 57154 57155 57156 57157 57158 57159 57160 57161 57162 57163 57164 57165 57166 57167 57168 57169 57170 57171 57...
result:
ok OK, Accepted.
Test #23:
score: 0
Accepted
time: 0ms
memory: 4716kb
input:
231 272 226 145 45674
output:
Yes 45114 45115 45116 45117 45118 45119 45120 45121 45122 45123 45124 45125 45126 45127 45128 45129 45130 45131 45132 45133 45134 45135 45136 45137 45138 45139 45140 45141 45142 45143 45144 45145 45146 45147 45148 45149 45150 45151 45152 45153 45154 45155 45156 45157 45158 45159 45160 45161 45162 45...
result:
ok OK, Accepted.
Test #24:
score: 0
Accepted
time: 0ms
memory: 4644kb
input:
300 116 15 107 32192
output:
Yes 31747 31748 31749 31750 31751 31752 31753 31754 31755 31756 31757 31758 31759 31760 31761 31762 31763 31764 31765 31766 31767 31768 31769 31770 31771 31772 31773 31774 31775 31776 31777 31778 31779 31780 31781 31782 31783 31784 31785 31786 31787 31788 31789 31790 31791 31792 31793 31794 31795 31...
result:
ok OK, Accepted.
Test #25:
score: 0
Accepted
time: 2ms
memory: 4256kb
input:
126 300 67 285 17771
output:
Yes 16602 16603 16604 16605 16606 16607 16608 16609 16610 16611 16612 16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630 16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16...
result:
ok OK, Accepted.
Test #26:
score: 0
Accepted
time: 2ms
memory: 4532kb
input:
231 117 51 40 8557
output:
Yes 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8...
result:
ok OK, Accepted.
Test #27:
score: 0
Accepted
time: 0ms
memory: 4668kb
input:
300 124 203 13 3245
output:
Yes 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3...
result:
ok OK, Accepted.
Test #28:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
62 146 44 52 331
output:
Yes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
result:
ok OK, Accepted.
Test #29:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
40 52 22 17 1571
output:
Yes 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1643 1646 1647 1650 1651 1654 1655 1...
result:
ok OK, Accepted.
Test #30:
score: 0
Accepted
time: 4ms
memory: 5188kb
input:
300 300 23 278 19171
output:
Yes 18017 18018 18019 18020 18021 18022 18023 18024 18025 18026 18027 18028 18029 18030 18031 18032 18033 18034 18035 18036 18037 18038 18039 18040 18041 18042 18043 18044 18045 18046 18047 18048 18049 18050 18051 18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 18062 18063 18064 18065 18...
result:
ok OK, Accepted.
Test #31:
score: 0
Accepted
time: 3ms
memory: 5000kb
input:
271 253 159 69 51872
output:
Yes 51482 51483 51484 51485 51486 51487 51488 51489 51490 51491 51492 51493 51494 51495 51496 51497 51498 51499 51500 51501 51502 51503 51504 51505 51506 51507 51508 51509 51510 51511 51512 51513 51514 51515 51516 51517 51518 51519 51520 51521 51522 51523 51524 51525 51526 51527 51528 51529 51530 51...
result:
ok OK, Accepted.
Test #32:
score: 0
Accepted
time: 2ms
memory: 4280kb
input:
124 259 8 165 20677
output:
Yes 19831 19832 19833 19834 19835 19836 19837 19838 19839 19840 19841 19842 19843 19844 19845 19846 19847 19848 19849 19850 19851 19852 19853 19854 19855 19856 19857 19858 19859 19860 19861 19862 19863 19864 19865 19866 19867 19868 19869 19870 19871 19872 19873 19874 19875 19876 19877 19878 19879 19...
result:
ok OK, Accepted.
Test #33:
score: 0
Accepted
time: 0ms
memory: 4812kb
input:
300 179 80 58 9660
output:
Yes 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9...
result:
ok OK, Accepted.
Test #34:
score: 0
Accepted
time: 1ms
memory: 3996kb
input:
97 95 71 13 1081
output:
Yes 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 ...
result:
ok OK, Accepted.
Test #35:
score: 0
Accepted
time: 4ms
memory: 5144kb
input:
288 300 233 151 62807
output:
Yes 61906 61907 61908 61909 61910 61911 61912 61913 61914 61915 61916 61917 61918 61919 61920 61921 61922 61923 61924 61925 61926 61927 61928 61929 61930 61931 61932 61933 61934 61935 61936 61937 61938 61939 61940 61941 61942 61943 61944 61945 61946 61947 61948 61949 61950 61951 61952 61953 61954 61...
result:
ok OK, Accepted.
Test #36:
score: 0
Accepted
time: 0ms
memory: 5072kb
input:
300 259 206 73 42316
output:
Yes 41654 41655 41656 41657 41658 41659 41660 41661 41662 41663 41664 41665 41666 41667 41668 41669 41670 41671 41672 41673 41674 41675 41676 41677 41678 41679 41680 41681 41682 41683 41684 41685 41686 41687 41688 41689 41690 41691 41692 41693 41694 41695 41696 41697 41698 41699 41700 41701 41702 41...
result:
ok OK, Accepted.
Test #37:
score: 0
Accepted
time: 2ms
memory: 4432kb
input:
149 295 129 201 30873
output:
Yes 30177 30178 30179 30180 30181 30182 30183 30184 30185 30186 30187 30188 30189 30190 30191 30192 30193 30194 30195 30196 30197 30198 30199 30200 30201 30202 30203 30204 30205 30206 30207 30208 30209 30210 30211 30212 30213 30214 30215 30216 30217 30218 30219 30220 30221 30222 30223 30224 30225 30...
result:
ok OK, Accepted.
Test #38:
score: 0
Accepted
time: 2ms
memory: 4188kb
input:
121 252 57 39 17402
output:
Yes 17073 17074 17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 17088 17089 17090 17091 17092 17093 17094 17095 17096 17097 17098 17099 17100 17101 17102 17103 17104 17105 17106 17107 17108 17109 17110 17111 17112 17113 17114 17115 17116 17117 17118 17119 17120 17121 17...
result:
ok OK, Accepted.
Test #39:
score: 0
Accepted
time: 0ms
memory: 4516kb
input:
300 37 136 22 4789
output:
Yes 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4820 4823 4824 4827 4828 4831 4832 4835 4836 4839 4840 4843 4844 4847 4848 4851 4852 4855 4856 4859 4860 4863 4...
result:
ok OK, Accepted.
Test #40:
score: 0
Accepted
time: 4ms
memory: 5128kb
input:
300 300 298 186 66405
output:
Yes 65434 65435 65436 65437 65438 65439 65440 65441 65442 65443 65444 65445 65446 65447 65448 65449 65450 65451 65452 65453 65454 65455 65456 65457 65458 65459 65460 65461 65462 65463 65464 65465 65466 65467 65468 65469 65470 65471 65472 65473 65474 65475 65476 65477 65478 65479 65480 65481 65482 65...
result:
ok OK, Accepted.