QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91829 | #5717. 密码锁 | Crysfly | 100 ✓ | 2235ms | 28276kb | C++11 | 2.8kb | 2023-03-29 17:36:48 | 2023-03-29 17:36:51 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,k,a[maxn][5],Mx,mn,V=60000;
vector<vi>v[maxn];
bool make(int s1,int r,int s2){
For(i,1,n){
v[i].clear();
For(j,0,k-1)
if(a[i][j]>=s1 && a[i][(j+r)%k]<=s2){
vi o;
For(x,0,k-1)if(x!=0&&x!=r)o.pb(a[i][(j+x)%k]);
v[i].pb(o);
}
if(!v[i].size())return 0;
}return 1;
}
int t[maxn],len,id[maxn];
int cnt[maxn];
vi buc[maxn];
int mx[maxn<<2],tag[maxn<<2];
void add(int p,int l,int r,int nl,int nr,int v){
if(l>=nl&&r<=nr)return tag[p]+=v,mx[p]+=v,void();
int mid=l+r>>1;
if(nl<=mid)add(p<<1,l,mid,nl,nr,v);
if(nr>mid)add(p<<1|1,mid+1,r,nl,nr,v);
mx[p]=max(mx[p<<1],mx[p<<1|1])+tag[p];
}
void des(vi&o){sort(o.begin(),o.end()),o.erase(unique(o.begin(),o.end()),o.end());}
bool f[9][9];
bool chk(int mid){
For(R,1,k-1){
if(!make(Mx-mid,R,mn+mid))continue;
if(k==2)return 1;
if(k==3){
For(i,1,len)buc[i].clear();
For(i,1,n){
cnt[i]=0;
for(auto it:v[i])buc[id[it[0]]].pb(i);
}
int j=1,sum=0;
For(i,1,len){
for(;t[i]-t[j]>mid;++j) for(int x:buc[j]) --cnt[x],sum-=(!cnt[x]);
for(int x:buc[i]) sum+=(!cnt[x]),++cnt[x];
if(sum==n)return 1;
}
continue;
}
vector<pair<int,pii>>o;
For(_,1,n){
vi vx,vy;
for(auto it:v[_]) vx.pb(it[0]),vx.pb(it[0]+mid+1),vy.pb(it[1]),vy.pb(it[1]+mid+1);
des(vx),des(vy);
int sx=vx.size()-1,sy=vy.size()-1;
memset(f,0,sizeof f);
for(auto it:v[_])
For(i,0,sx-1) if(it[0]<=vx[i] && it[0]+mid+1>=vx[i+1])
For(j,0,sy-1) if(it[1]<=vy[j] && it[1]+mid+1>=vy[j+1]) f[i+1][j+1]=1;
int cnt=0;
For(i,1,sx+1){
for(int l=1,r;l<=sy;l=r+1){
r=l;
while(r<n && f[i][r+1]==f[i][r] && f[i-1][r+1]==f[i-1][r])++r;
if(f[i][l]==f[i-1][l])continue;
++cnt;
if(f[i][l]) o.pb(mkp(vx[i-1],mkp(vy[l-1],vy[r]-1)));
else o.pb(mkp(vx[i-1],mkp(-vy[l-1],vy[r]-1)));
}
}
}
sort(o.begin(),o.end());
bool ok=0;
for(auto qwq:o){
auto t=qwq.se;
if(t.fi<0)add(1,0,V,-t.fi,t.se,-1);
else add(1,0,V,t.fi,t.se,1);
if(mx[1]==n)ok=1;
}
if(ok)return 1;
}
return 0;
}
void work()
{
cin>>n;; Mx=-V,mn=V; len=0;
For(i,0,k-1)For(j,1,n)cin>>a[j][i],Mx=max(Mx,a[j][i]),mn=min(mn,a[j][i]),t[++len]=a[j][i];
sort(t+1,t+len+1),len=unique(t+1,t+len+1)-t-1;
For(i,1,len)id[t[i]]=i;
int res=Mx-mn,l=0,r=res-1;
while(l<=r){
int mid=l+r>>1;
if(chk(mid))res=mid,r=mid-1;
else l=mid+1;
}
cout<<res<<"\n";
}
signed main()
{
int T;cin>>T>>k;
while(T--)work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 7ms
memory: 17836kb
input:
5 1 20 20828 22671 20646 13184 13779 12445 15192 14863 14396 19238 16788 20325 16831 8559 13417 8768 13227 8760 12456 12091 20 17138 10757 10189 4459 19805 4791 8043 15409 14758 15901 9004 13481 20599 17218 14056 5078 8021 16969 22031 15690 20 26410 25246 16063 9589 20080 21752 25766 14007 12750 231...
output:
14112 17572 16821 21321 16199
result:
ok 5 number(s): "14112 17572 16821 21321 16199"
Test #2:
score: 5
Accepted
time: 43ms
memory: 17856kb
input:
3 1 50000 15429 14039 16730 23945 7044 17994 15646 15950 7744 7726 19830 8000 7607 19562 22681 17139 19133 13561 14539 21246 8476 20813 21139 18999 18270 11950 19511 14822 24627 20644 10619 7699 8058 9578 8425 12058 22166 12276 21095 22645 8087 24264 21082 16567 18500 15489 14629 16114 19826 22286 1...
output:
18373 18000 18000
result:
ok 3 number(s): "18373 18000 18000"
Test #3:
score: 5
Accepted
time: 1ms
memory: 17844kb
input:
5 2 20 3646 6903 10939 9491 14584 16498 7415 10353 8781 10454 703 4651 11986 3700 2186 21659 18792 6774 15283 9422 22629 3204 24229 11810 15271 20496 13170 19867 6105 13572 6657 11440 22722 22564 10168 2797 5798 11753 18320 12720 20 18619 25811 14645 26890 3897 11154 16664 20111 15847 16651 8537 116...
output:
17572 18784 14814 14107 15187
result:
ok 5 number(s): "17572 18784 14814 14107 15187"
Test #4:
score: 5
Accepted
time: 13ms
memory: 17768kb
input:
186 2 5 10809 20957 1456 13581 19134 19871 12718 14451 14783 23041 7 24553 4790 18932 21045 14061 6438 17183 9155 15756 16480 17055 13768 11550 15400 4 12340 23115 28018 8781 16634 10828 1457 21446 7 9619 7632 22338 17091 11090 3368 4366 17684 14282 25007 9194 3144 9944 15465 3 3024 25036 17327 2034...
output:
17678 13003 11384 19194 20499 16143 15079 11508 11891 22699 12676 11250 16873 3238 9264 8040 18134 10772 27251 15001 14812 6575 5499 18396 18795 10752 17672 13273 13915 15178 8303 15337 11707 18835 16270 10944 15953 22359 4914 17434 19001 3224 14155 17053 8670 17906 18767 3696 10036 10580 23062 7636...
result:
ok 186 numbers
Test #5:
score: 5
Accepted
time: 14ms
memory: 17952kb
input:
1357 2 6 1679 1896 8067 24584 3225 2239 14688 13434 4956 688 2751 5016 5 18325 12446 17937 6311 21564 24096 6172 17497 25829 12016 3 9440 752 22972 11570 26214 5969 3 13475 23941 17551 9287 14467 15412 2 20079 827 5314 5994 3 24501 13180 9614 25780 17665 18145 4 16980 22134 5840 14181 16144 7553 773...
output:
21359 13383 14644 10466 14085 14887 14396 19769 12727 14894 9957 19961 16696 14903 12494 14811 13441 15241 5475 15280 10050 15477 10792 15489 14676 21437 19598 12192 15812 10749 24133 15641 24351 20130 8512 11012 19409 7014 18531 9567 17379 4718 13822 15877 11260 17467 12318 12804 19625 4182 20704 1...
result:
ok 1357 numbers
Test #6:
score: 5
Accepted
time: 95ms
memory: 23260kb
input:
3 2 50000 7513 17243 9697 14636 12922 14859 12193 5056 13705 14408 13089 11378 14342 14499 15298 9625 22287 6924 7449 7005 13845 14641 18588 7768 17917 8750 15618 18464 13925 8818 17391 13200 2575 11253 4899 12707 7147 18547 8379 17524 11779 19107 23448 10551 9856 5503 8494 1692 14681 13130 17456 15...
output:
18000 18000 21622
result:
ok 3 number(s): "18000 18000 21622"
Test #7:
score: 5
Accepted
time: 6ms
memory: 15796kb
input:
5 3 10 16030 9693 27756 24507 23211 17464 8887 7416 13135 4895 17169 11454 10400 13490 11738 22678 15050 29009 12184 12183 6893 16992 11689 16565 26352 8380 18580 20848 9410 21743 10 1128 13324 10854 697 15189 7294 1871 12509 18641 18737 8263 13121 15061 18066 16059 11121 24606 17909 1413 9992 12404...
output:
16826 16195 14672 17434 14651
result:
ok 5 number(s): "16826 16195 14672 17434 14651"
Test #8:
score: 5
Accepted
time: 3ms
memory: 17892kb
input:
10 3 50 12127 17615 4504 20695 16125 18833 13652 5613 8019 15730 16385 3568 14282 14276 13925 16974 8261 24045 9779 1487 3759 15923 7152 21549 26107 14901 14057 5048 12826 6651 12380 18877 17171 4811 18423 22750 12101 8463 7906 20052 9943 4320 11309 23876 6387 7655 3242 14459 14963 6580 20320 8545 2...
output:
18252 16219 18615 15968 20398 17291 22169 17075 17681 17390
result:
ok 10 numbers
Test #9:
score: 5
Accepted
time: 16ms
memory: 17920kb
input:
492 3 6 8092 24146 5245 25301 8773 26713 20068 26047 4375 21461 28935 4037 28742 5614 21217 11156 23813 14955 4 26596 4665 12954 28516 2539 28719 26192 23894 9531 18883 18267 9946 4 15563 2548 22395 29261 1483 598 24912 12610 17817 9629 17119 7397 5 11066 7676 29263 9309 5342 18273 24030 25203 5102 ...
output:
19776 19188 21797 18197 16488 9621 18985 14281 13947 14275 11892 9245 17832 17173 17726 9662 18620 13692 17887 16482 23818 21403 13634 12965 6193 18261 13831 13028 12865 19479 17691 16458 13698 18656 19260 6233 12146 11289 11588 13898 18827 10520 21260 13972 11976 11540 18082 16415 18846 24749 9902 ...
result:
ok 492 numbers
Test #10:
score: 5
Accepted
time: 95ms
memory: 18568kb
input:
2823 3 7 11008 15379 3474 23505 21289 13545 21951 14190 11309 11018 12827 20349 17613 20448 14242 15097 16392 7823 18077 27988 12213 4 10305 19014 15560 26972 21128 9755 5367 23887 17563 15511 13210 12065 5 7016 12729 24261 5979 12169 21967 10993 25792 11527 11476 21349 2172 20428 22930 23721 6 1562...
output:
14603 13762 18256 16513 15764 21273 11977 12505 8396 21677 12517 21399 12827 15856 14628 12291 14834 18210 19601 13710 10595 10094 17897 16185 18524 13388 10652 12097 8966 11074 9961 9831 15566 19751 18182 15649 12751 15690 12487 15892 16475 15285 5549 11479 13063 8339 9186 13834 14067 12428 23249 1...
result:
ok 2823 numbers
Test #11:
score: 5
Accepted
time: 297ms
memory: 23120kb
input:
4 3 30000 8497 11286 8353 2876 13129 10774 10578 13288 16631 14892 4744 10355 11083 16465 12953 9099 9278 12561 12862 13392 1500 17077 11412 4467 14626 14772 8321 8327 3999 11277 13029 4212 1734 13474 13656 8398 762 10438 14080 15473 3866 7574 10692 16389 4413 9044 18604 1591 10649 14576 10155 10361...
output:
10103 10118 10196 10178
result:
ok 4 number(s): "10103 10118 10196 10178"
Test #12:
score: 5
Accepted
time: 440ms
memory: 28276kb
input:
3 3 50000 19199 27507 19780 17075 20200 20902 22589 12623 21750 21336 4538 24298 18509 16201 16796 6650 19468 19507 25451 27321 18009 23942 24617 24422 26676 8908 4600 11408 20067 23198 23582 16086 21592 19845 18972 17985 11853 25099 28717 27759 10596 23082 27902 19323 16693 8408 26792 20131 22735 2...
output:
10040 15453 19023
result:
ok 3 number(s): "10040 15453 19023"
Test #13:
score: 5
Accepted
time: 3ms
memory: 18752kb
input:
5 4 10 12871 9817 14695 11872 16291 27028 1392 12572 10409 3017 16310 28902 7458 24546 13098 2633 26901 14337 17441 63 26236 2514 24674 23157 9327 13531 25862 26834 24256 21476 22242 24748 23021 17878 26324 12312 3909 28308 3462 20168 10 20846 29205 14900 19250 722 6157 15661 8441 17182 11169 3390 1...
output:
24685 22656 22046 23738 22355
result:
ok 5 number(s): "24685 22656 22046 23738 22355"
Test #14:
score: 5
Accepted
time: 44ms
memory: 16816kb
input:
10 4 50 19704 7323 15828 22182 10893 7859 16948 16603 28637 8205 12361 2532 5845 23202 10647 14169 15901 24468 1029 25019 26328 18995 14057 6145 13869 15274 5361 22018 4967 1745 16752 19883 926 78 6747 7515 8391 21114 28634 18985 27576 5184 3502 25152 21983 2702 11587 9661 9052 23658 5746 9465 16337...
output:
26043 27185 27397 26352 28517 26578 25856 25676 28104 25894
result:
ok 10 numbers
Test #15:
score: 5
Accepted
time: 89ms
memory: 18896kb
input:
296 4 5 14984 9981 9017 21474 22589 15490 4551 17062 14214 18005 5994 11883 5919 13543 16909 18835 23523 17149 11464 14979 6 14169 24435 27207 2521 14770 2155 8254 9241 12877 22826 18706 14972 19413 12325 7660 19399 13082 17109 21888 14786 17154 13755 1801 9630 7 12587 18433 18081 13142 19835 14986 ...
output:
12511 10524 18268 18094 17939 12851 11657 17111 14244 19726 17196 16208 18788 15137 18399 10145 14959 13270 14484 20078 14814 18087 16894 11828 23192 24887 14794 15738 21539 22505 20498 11968 17556 21716 9821 21038 20046 13142 19941 18880 15711 10544 19569 13011 12045 18762 11510 13108 20176 16102 1...
result:
ok 296 numbers
Test #16:
score: 5
Accepted
time: 165ms
memory: 19052kb
input:
556 4 6 24538 1561 15955 25462 13820 18425 23525 16200 7272 8057 14559 13522 4043 13481 11449 26789 19442 22612 19442 17815 15054 14372 24215 15908 7 4992 21533 18540 20730 21070 25918 14971 18953 15648 18255 12969 20983 12375 20955 4379 23010 25490 28045 16038 13733 27907 7885 27116 20057 29239 136...
output:
15340 23053 13559 23172 14989 14339 12399 12797 17439 19464 17954 16936 16876 23513 15667 12337 19783 13724 18516 21357 18068 22247 12341 23511 14801 10506 11572 9374 17598 13758 13755 17614 20779 15389 17645 14177 15511 23190 20611 15695 21937 22119 13534 20474 18298 20579 14677 14012 19496 20429 1...
result:
ok 556 numbers
Test #17:
score: 5
Accepted
time: 599ms
memory: 21408kb
input:
910 4 5 18495 4213 7072 24451 5053 24983 1518 19953 25740 1087 4368 10700 8715 18200 28641 14575 2496 27461 27488 13358 4 9653 12755 22556 17654 21198 18496 17358 19398 27223 11305 27527 21344 22554 19509 8064 23976 7 1138 20361 16799 21891 18013 21953 4783 12601 3538 13276 22157 13538 10272 24627 2...
output:
21955 14468 16634 18296 16350 11548 20506 13501 22262 19344 18475 20066 17636 15124 24275 19747 21989 20782 18640 14872 11375 14879 21998 18443 13717 25115 12706 18136 23493 13745 16521 12208 16001 18263 18400 23617 10163 14338 15277 23845 14012 17613 19900 8042 0 11551 13270 15543 21395 17116 17366...
result:
ok 910 numbers
Test #18:
score: 5
Accepted
time: 823ms
memory: 20080kb
input:
1826 4 5 12038 3573 20463 6119 19486 9769 26360 9873 3880 27288 14634 18318 2181 14462 7044 18465 4615 19511 28217 543 5 29712 7598 12660 5404 13631 8149 15497 14057 12916 16856 23561 10256 5404 6465 13656 6258 12169 17157 15896 14018 6 10545 25243 9487 14739 13377 3270 7836 5934 29067 27149 19583 1...
output:
11898 14215 22984 21851 15408 19410 7192 19889 17373 22863 19336 16456 16888 13820 16097 13914 8616 10866 13444 14903 11845 17773 24730 17164 23083 18271 15779 25674 19116 24944 22504 9813 19429 14764 16853 15871 23291 16732 19851 19080 17257 13462 12114 15378 20429 18445 18873 19736 15068 13227 265...
result:
ok 1826 numbers
Test #19:
score: 5
Accepted
time: 1276ms
memory: 22272kb
input:
1834 4 5 14031 15017 11718 8584 24580 2938 13523 5087 3420 27335 16189 5418 9070 14669 21628 22686 16121 15677 21857 26168 4 13628 4601 13896 2382 5508 5343 25068 22533 17027 14789 2864 19773 26676 3034 11148 26438 5 20602 13848 6353 13350 23468 26366 10523 24372 8484 24138 4007 21029 5227 14962 231...
output:
18751 17932 17785 20577 14948 18357 13497 10772 14615 10585 12000 15998 16288 15554 16718 18448 21625 12774 14554 16940 17792 13385 15268 18042 20204 13673 18532 17792 20182 12990 20140 18575 18426 19062 13277 15160 17362 23041 14704 13052 19214 9358 10732 16774 14760 19422 10394 15437 16916 20923 2...
result:
ok 1834 numbers
Test #20:
score: 5
Accepted
time: 2235ms
memory: 23164kb
input:
3 4 10000 27024 14111 22404 5025 23580 12815 13934 2337 12175 11404 6514 12919 22433 27537 25780 7967 6642 17225 21192 14830 1691 1887 11039 7793 3178 8346 22904 16381 5296 29290 20246 12878 21843 11597 11199 7069 14778 10902 24331 15641 21285 16597 16428 20494 26998 7139 14721 10644 25003 13823 268...
output:
29748 29742 29887
result:
ok 3 number(s): "29748 29742 29887"
Extra Test:
score: 0
Extra Test Passed