QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867446 | #9684. 倾诉 | lgvc# | 2 | 2369ms | 10204kb | C++23 | 5.2kb | 2025-01-23 16:30:53 | 2025-01-23 16:30:53 |
Judging History
answer
#include <bits/stdc++.h>
#define BIT 61
#define SIZ 15
struct bitset {
long long bits[SIZ];
void init(void) {for(int i=0;i<SIZ;i++) bits[i]=0;}
void set(int x,bool y) {bits[x/BIT]^=((((bits[x/BIT]>>(x%BIT))&1)^y)<<(x%BIT));}
void setall(bool y) {for(int i=0;i<SIZ;i++) bits[i]=((((long long)y)<<BIT)-(long long)(y));}
bool q(int x) {return (bits[x/BIT]>>(x%BIT))&1;}
void operator=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]=y.bits[i];}
void operator|=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]|=y.bits[i];}
void operator&=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]&=y.bits[i];}
void operator^=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]^=y.bits[i];}
void operator+=(const bitset& y) {
for(int i=0;i<SIZ;i++) {
bits[i]+=y.bits[i];
if((bits[i]>>BIT)&1) bits[i]^=(1ll<<BIT),bits[i+1]++;
}
}
void operator-=(const bitset& y) {
for(int i=0;i<SIZ;i++) {
bits[i]-=y.bits[i];
if(bits[i]<0) bits[i]+=(1ll<<BIT),bits[i+1]--;
}
}
void operator<<=(int k) {
bitset z;z.init();
int tmp=k/BIT;
for(int i=0;i<SIZ-tmp;i++) z.bits[i+tmp]=bits[i];
k%=BIT;
z.bits[SIZ-1]<<=k;
for(int i=SIZ-2;i>=0;i--) {
long long tmp=z.bits[i];
z.bits[i]&=((1ll<<(BIT-k))-1);
z.bits[i+1]|=((tmp^z.bits[i])>>(BIT-k));
z.bits[i]<<=k;
}
for(int i=0;i<SIZ;i++) bits[i]=z.bits[i];
}
void operator>>=(int k) {
bitset z;z.init();
int tmp=k/BIT;
for(int i=tmp;i<SIZ;i++) z.bits[i-tmp]=bits[i];
k%=BIT;
z.bits[0]>>=k;
for(int i=1;i<SIZ;i++) {
z.bits[i-1]|=((z.bits[i]&((1ll<<k)-1))<<(BIT-k));
z.bits[i]>>=k;
}
for(int i=0;i<SIZ;i++) bits[i]=z.bits[i];
}
bitset operator|(const bitset& y) {
bitset z;
for(int i=0;i<SIZ;i++) z.bits[i]=bits[i]|y.bits[i];
return z;
}
bitset operator&(const bitset& y) {
bitset z;
for(int i=0;i<SIZ;i++) z.bits[i]=bits[i]&y.bits[i];
return z;
}
bitset operator^(const bitset& y) {
bitset z;
for(int i=0;i<SIZ;i++) z.bits[i]=bits[i]^y.bits[i];
return z;
}
bitset operator+(const bitset& y) {
bitset z;z.bits[0]=0;
for(int i=0;i<SIZ;i++) {
z.bits[i]+=bits[i]+y.bits[i];
if((z.bits[i]>>BIT)&1) z.bits[i]^=(1ll<<BIT),z.bits[i+1]=1;else z.bits[i+1]=0;
}
return z;
}
bitset operator-(const bitset& y) {
bitset z;z.bits[0]=0;
for(int i=0;i<SIZ;i++) {
z.bits[i]+=bits[i]-y.bits[i];
if(z.bits[i]<0) z.bits[i]+=(1ll<<BIT),z.bits[i+1]=-1;else z.bits[i+1]=0;
}
return z;
}
bitset operator<<(int k) {
bitset z;z.init();
int tmp=k/BIT;
for(int i=0;i<SIZ-tmp;i++) z.bits[i+tmp]=bits[i];
k%=BIT;
z.bits[SIZ-1]<<=k;
for(int i=SIZ-2;i>=0;i--) {
long long tmp=z.bits[i];
z.bits[i]&=((1ll<<(BIT-k))-1);
z.bits[i+1]|=((tmp^z.bits[i])>>(BIT-k));
z.bits[i]<<=k;
}
return z;
}
bitset operator>>(int k) {
bitset z;z.init();
int tmp=k/BIT;
for(int i=tmp;i<SIZ;i++) z.bits[i-tmp]=bits[i];
k%=BIT;
z.bits[0]>>=k;
for(int i=1;i<SIZ;i++) {
z.bits[i-1]|=((z.bits[i]&((1ll<<k)-1))<<(BIT-k));
z.bits[i]>>=k;
}
return z;
}
int count(void) {
int ans=0;
for(int i=0;i<SIZ;i++) ans+=__builtin_popcountll(bits[i]);
return ans;
}
bool operator<(const bitset& y) {
for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]<y.bits[i];
return 0;
}
bool operator>(const bitset& y) {
for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]>y.bits[i];
return 0;
}
bool operator<=(const bitset& y) {
for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]<y.bits[i];
return 1;
}
bool operator>=(const bitset& y) {
for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]>y.bits[i];
return 1;
}
bool operator==(const bitset& y) {
for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return 0;
return 1;
}
};
bitset max(bitset& x,bitset& y) {
for(int i=SIZ-1;i>=0;i--) {
if(x.bits[i]>y.bits[i]) return x;
if(x.bits[i]<y.bits[i]) return y;
}
return x;
}
bitset min(bitset& x,bitset& y) {
for(int i=SIZ-1;i>=0;i--) {
if(x.bits[i]>y.bits[i]) return y;
if(x.bits[i]<y.bits[i]) return x;
}
return x;
}
int T,N,a[20009],K;
bitset f[755],qq[755][755];
int dp[755][755];
bool chk(bitset x) {
memset(dp[N+1],0x3f,sizeof(dp[N+1]));
dp[N+1][N+1]=0;
for(int i=N;i>=1;i--) {
memset(dp[i],0x3f,sizeof(dp[i]));
for(int j=N;j>=i;j--) {
dp[i][j]=std::min(dp[i][j],dp[i][j+1]);
for(int k=i;k<=j;k++) {
if(qq[i][k]<=(x<<(j-k))) {
// printf("%d %d %d %d %d\n",i,k,j,qq[1][1].count(),x.count());
dp[i][j]=std::min(dp[i][j],dp[k+1][j+1]+(j-i));
}
}
}
}
if(dp[1][1]<=K) return 1;
return 0;
}
signed main(void) {
scanf("%d",&T);
while(T--) {
scanf("%d %d",&N,&K);
for(int i=1;i<=N;i++) {
scanf("%d",&a[i]);
f[i].setall(0);
f[i].bits[0]=a[i];
f[i]<<=N;
}
for(int i=1;i<=N;i++) {
qq[i][i]=f[i];
for(int j=i+1;j<=N;j++) {
qq[i][j]=(qq[i][j-1]>>1);
qq[i][j]+=f[j];
}
}
bitset ff;
for(int i=N+20;i>=0;i--) ff.set(i,1);
for(int i=N+20;i>=0;i--) {
ff.set(i,0);
if(!chk(ff)) {
ff.set(i,1);
}
}
int st=0;
for(int i=N+20;i>=0;i--) {
if(ff.q(i)) {
st=i;
break;
}
}
for(int i=st;i>=0;i--) printf("%d",ff.q(i));
printf("\n");
}
}
详细
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 1ms
memory: 8028kb
input:
5 6 1 11764 28428 28179 18698 6443 20288 6 3 29 17548 61962 31242 8172 4107 6 15 7 2 239427 137145 171239 3 6 4 294 211 407 190 2 2 6 5 197190 265870 12121 144584 21313 14169
output:
110111100001100000000 101110011000100110000 11101001110100001100000 11000110110000 10100110100010001101100
result:
ok 5 lines
Test #2:
score: 2
Accepted
time: 0ms
memory: 7900kb
input:
3 10 9 11333 23 34461 34357 354 4 3 55 3 3 10 13 5 17524 48186 2193 17524 17524 20914 15829 17524 6 10 5 128279 27396 7992 44204 132529 84302 26783 3378 42535 3786
output:
11010110100011011110 101111000011101000000000 11010100100010110010000000
result:
ok 3 lines
Test #3:
score: 2
Accepted
time: 11ms
memory: 7936kb
input:
1 30 23 129534 106530 312047 478493 635175 682687 771242 851161 898940 103771 4 22344 668706 758190 219263 803071 787124 804602 997769 398659 874234 1 845912 226469 600617 203296 540318 171121 5 103637
output:
1011110001001010101000000000000000000000000000000
result:
ok single line: '1011110001001010101000000000000000000000000000000'
Test #4:
score: 2
Accepted
time: 11ms
memory: 10072kb
input:
1 30 20 24369 112417 273642 91342 16920 82890 51488 110843 350768 2127 32310 317716 289575 345557 10461 133151 237824 131339 154529 77796 16773 128740 561207 292189 244465 178375 50425 149932 60698 32020
output:
100000110011011000011001110000000000000000000000
result:
ok single line: '100000110011011000011001110000000000000000000000'
Test #5:
score: 2
Accepted
time: 10ms
memory: 10020kb
input:
1 30 22 5164 3437 1409 1477 1234 290 641 8387 2389 4783 1704 1430 2859 422 368 348 3778 2161 1898 964 357 763 380 3870 6050 1136 3613 1747 975 131
output:
11100100111010100100000000000000000000000
result:
ok single line: '11100100111010100100000000000000000000000'
Test #6:
score: 2
Accepted
time: 12ms
memory: 10076kb
input:
1 30 16 78284 104679 51060 38372 468848 144187 84013 249991 72147 295666 63152 22000 35446 88085 67085 19719 4766 988 384917 450684 101500 548119 105206 420503 54774 10663 13882 48365 104067 33372
output:
11100010001001000011101010000000000000000000000
result:
ok single line: '11100010001001000011101010000000000000000000000'
Test #7:
score: 2
Accepted
time: 12ms
memory: 10080kb
input:
1 30 20 93587 95074 833612 98114 468073 405234 294453 151570 336309 555067 71292 497114 301076 302914 130800 17777 145963 834497 152338 526181 242311 266037 315170 36843 72099 59791 95401 96269 181758 156382
output:
111011010101101111000000101010000000000000000000
result:
ok single line: '111011010101101111000000101010000000000000000000'
Test #8:
score: 2
Accepted
time: 11ms
memory: 8028kb
input:
1 30 20 7 5 5 2 5 2 4 2 1 8 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 244222 8 6 8 1
output:
111011101000110110010001100000001000000000000
result:
ok single line: '111011101000110110010001100000001000000000000'
Test #9:
score: 2
Accepted
time: 12ms
memory: 8024kb
input:
1 30 30 1486 898 1035 2327 2777 3385 4083 330 2925 3348 1324 826 3223 3418 45 184 54 591 44 4301 4453 1558 601 1914 2114 8 1 93 7 6
output:
10011001000001011100000000000000000000
result:
ok single line: '10011001000001011100000000000000000000'
Test #10:
score: 2
Accepted
time: 11ms
memory: 9900kb
input:
1 30 132 999998 999998 999999 999999 1000000 1000000 1000000 1000000 999999 1000000 999999 1000000 999998 999999 999999 999999 999998 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
10110111000110101111000000000000000000
result:
ok single line: '10110111000110101111000000000000000000'
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #11:
score: 10
Accepted
time: 4ms
memory: 7860kb
input:
33 6 1 2201 30891 22926 51021 5381 1953 6 1 17621 35116 7069 5597 24627 4779 6 8 6 19015 19015 19015 19015 2 6 4 19047 11041 11837 2027 1116 2645 6 7 117530 117530 117530 117530 117530 4 6 5 26692 20497 5915 6516 6714 1098 6 7 348470 348470 348470 348470 348470 7 6 3 2 1 2378 4 107252 2 6 2 9325 369...
output:
111100010101011100000 110000000110011000000 10010100100101100000 1110111101011010100 1110010110010001000000 10001011101010100100 101010100010100010000000 1101000101111100000000 1001001101001001000000 10100110001010100000 1111111101011100000 1110110000100000000 1000010001100101000000 1010011111111001...
result:
ok 33 lines
Test #12:
score: 10
Accepted
time: 7ms
memory: 5976kb
input:
20 10 10 7398 2663 2 28570 2 2 2 2 2 3 10 10 5 4 486615 486615 486615 521695 469075 486615 486615 7 10 5 5132 160984 19067 83543 351799 157254 40607 16829 39349 21513 10 3 2234 2158 11383 7501 3047 737 626 4487 5017 4908 10 5 31661 111680 91073 9607 12095 42688 118218 47360 392 51408 10 3 28734 5994...
output:
1110111000011011000 1111111010111011111000000000 110000100111001110000000000 10101101101101010000000 11010001011110101100000000 111000110111001000000000000 11111011001001000000000000 11110011101111100000000 1000111111101100000000000 1110010101000111001000000000 11100111110110011100000 10110011111001...
result:
ok 20 lines
Test #13:
score: 10
Accepted
time: 47ms
memory: 8028kb
input:
8 25 15 2317 3833 9894 20350 54995 518 77 9839 15551 281 5127 13100 16 13930 16 16 3872 44999 28972 30892 63777 36955 9212 13452 6 25 24 99488 111510 114067 99889 114169 167030 178257 168039 292710 214341 275210 350436 319813 436188 410390 450309 445475 482666 516698 666862 623999 693281 692643 7096...
output:
110110011010100000000000000000000000000 10101101010000100100000000000000000000000000 111001101011010001100000010000 1000010011011111000000000000000000000 11111000000101000000000000000000000000000 10110110001100111011110110000000000000000 111010000000000000000000000000 1001101000001101010101000000000...
result:
ok 8 lines
Test #14:
score: 10
Accepted
time: 265ms
memory: 10204kb
input:
4 50 34 95 81 35 25 62 110 1410 59 3104 7106 65431 5351 95886 127301 256 73557 41 38 60 43 55 8 32 3661 6459 5863 1242 1188 9 32402 14 11 11 13 62993 14 121264 128664 122950 6617 40500 44292 7 5 2 4 4 5 4 2 50 29 5982 32011 27127 38729 45979 27737 46199 11445 36544 9629 104678 220775 12741 46011 468...
output:
10110111110110010010110100000000000000000000000000000000000000 110001110111011000110111000100000000000000000000000000000000000000 11100001000000000000000000000000000000000000000000000000000 101010011111110001111111111110101011000000110110000000000000000000
result:
ok 4 lines
Test #15:
score: 0
Time Limit Exceeded
input:
1 200 104 824019 802339 516620 688752 477193 458691 362601 284661 179293 149012 114733 46386 997099 937623 842616 725675 526621 419116 944566 8 947114 835410 880188 817427 933050 781449 749967 709476 674043 659058 694092 595430 606209 578012 589236 565119 563253 538372 527012 506608 471302 379419 40...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #60:
score: 17
Accepted
time: 125ms
memory: 8024kb
input:
1666 6 1 282 719 29 355 388 275 6 1 348 766 91 299 474 96 6 23 5 2 8554 8554 8554 2 6 1 84 195 23 37 120 117 6 3 8 3 51 62 28 5 6 3 3 64 64 4 4 2 6 9 5 552 552 552 552 5 6 3 3611 1144 417 3461 459 755 6 3 777 315 1007 5 2 1061 6 6 1300 2101 4 1877 360 2434 6 1 384 713 168 25 524 390 6 3 203 18 305 1...
output:
110000100100000 111011010000000 1000010110111000000 1111000100000 11111000000 11110000000 100011001000000 100010001101100000 10000100101000000 100110000010000000 1000001100100000 10011001100000 111001011010000000 1100000110100000 1110111111110000 101011111000000 1000011110000 100101000000000 1011110...
result:
ok 1666 lines
Test #61:
score: 17
Accepted
time: 321ms
memory: 5976kb
input:
1000 10 10 1765 725 287 2983 1959 3 855 1094 2960 4 10 4 856 92 85 15 31 233 718 137 64 213 10 8 4575 2773 2373 497 8150 5057 2455 9107 5 5 10 8 216 189 143 218 154 222 153 147 2 5 10 3 77 74 30 27 241 85 57 8 66 86 10 7 3471 3468 5868 2881 478 3775 2 470 1 3 10 5 317 2460 139 3033 107 359 4 1716 3 ...
output:
101110011000000000000 1010110010000000000 1100010110011110000000 11011110000000000 10101111110000000 110110001111000000000 100100100101100000000 1101111101000000000 10111010010110000000 1111110111101100 10100101000100000000 10100110000110000000 1011110110101000000000 10011110100000000000 10000100100...
result:
ok 1000 lines
Test #62:
score: 17
Accepted
time: 2369ms
memory: 7984kb
input:
400 25 16 678 1005 3339 2086 1363 1802 549 124 406 305 325 742 3344 2194 640 2744 383 1494 2369 1209 667 120 423 243 91 25 16 5 6 5 4 4 37 6 2 2 2 2 2 2 2 2 7 13 12 9 10 15 32 32 1 4 25 18 848 963 139 413 186 82 1329 524 629 70 40 324 1255 282 581 193 439 189 81 268 769 733 22 36 332 25 23 61 41 39 ...
output:
11111011010000000000000000000000000 11001000000000000000000000000 1011111100101000000000000000000000 110110010001110110001100000 1100011111111100000000000000000000000 11000001001110000000000000000000000 110000110110000000000000000000000000 100110110000101000000000000000000 11010000111000000000000000...
result:
ok 400 lines
Test #63:
score: 0
Time Limit Exceeded
input:
200 50 38 1635 1767 1420 565 1815 1952 1969 1438 1749 21 415 15 1257 1883 22 26 13 22 19 12 22 9 16 19 20 19 25 11 28 21 519 29 653 315 987 806 450 651 102 77 101 87 40 2 5 3 3 1 5 3 50 39 157 165 46 80 176 17 4 41 47 213 8 18 161 53 10 56 21 5 400 10 173 35 73 263 161 33 88 102 132 55 173 3 11 6 48...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #80:
score: 16
Accepted
time: 252ms
memory: 5928kb
input:
3333 6 1000000000 131727 7 4 170194 6 59263 6 1000000000 417714 286613 7 310122 6 4 6 1000000000 63764 2430 2696 6699 8478 22261 6 1000000000 217 131 6 1487 2927 2 6 1000000000 26225 27991 3842 72525 4521 5231 6 1000000000 34409 26001 23563 19345 30764 24919 6 1000000000 97981 138532 59280 82393 128...
output:
10100110001101001000000 10010111011100001100000 101011011110101000000 10110111001100000 110010000010110110000 111100110010110100000 11111011000100010000000 11001111100101100 1100000101001001010100000 100000000000 100111000110001000000 101110110010100111000000 10000000000000000000000 1100000111101000...
result:
ok 3333 lines
Test #81:
score: 16
Accepted
time: 647ms
memory: 5976kb
input:
2000 10 1000000000 4 225227 95031 258432 108444 260818 190505 154686 1 5 10 1000000000 541067 480522 7 372550 533382 366492 200177 240412 6 1 10 1000000000 10004 14230 86468 2812 9690 7106 21976 45928 9749 30567 10 1000000000 12217 2718 4247 9981 12911 1845 2048 4 1387 16384 10 1000000000 46966 1438...
output:
11110100000110100010000000 101001100100010010010000000 1111111110010010000000000 1000000000000000000000000 11010100011000000000 110010110111010010100000000 11000010111011011011000000000 1001001110000111010000000000 11110110001100100100000000 101110111011100111000000000 100001001101001011110000000 10...
result:
ok 2000 lines
Test #82:
score: 0
Time Limit Exceeded
input:
800 25 1000000000 87944 70771 86657 342502 146802 122800 216223 248367 121688 22026 9518 1128 64025 63379 231058 292954 218186 35314 64373 10501 20550 32081 39386 10095 78181 25 1000000000 54665 3 129508 98607 92526 68177 57466 62726 21642 52766 23748 16110 18286 9033 4 6 3 6 2 5 7 5 7 1 4 25 100000...
output:
100110001011001010000000000000000000000000 11001101110010100000000000000 1101110010100110110000000000000000000000 1011101001000100000000000000000000000000 10100110000000000000000000000000 1001111010011010010000000000000000000000 10010000010110010011000000000000000000000000 10000010010000000000000000...
result:
Subtask #7:
score: 0
Skipped
Dependency #4:
0%