QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#9077 | #1065. 连续子序列 | Qingyu✨ | 100 ✓ | 5ms | 3588kb | C++20 | 2.5kb | 2021-04-07 11:47:01 | 2021-12-19 11:28:08 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c))
{
if (c == '-')
f = -1;
c = getchar();
}
while (isdigit(c))
x = x * 10 - '0' + c, c = getchar();
x *= f;
}
inline void rdS(string &S)
{
S = "";
char c = getchar();
while (c != '0' && c != '1')
c = getchar();
while (c == '0' || c == '1')
S += c, c = getchar();
}
const int mod = 1e9 + 9;
map<ll, int> dp;
ll calcdp(ll k)
{
if (dp.count(k))
return dp[k];
if (k == 0)
return dp[k] = 1;
if (k == 1)
return dp[k] = 2;
if (k == 2)
return dp[k] = 3;
calcdp(k + 1 >> 1), calcdp(k >> 1);
return dp[k] = (dp[k + 1 >> 1] + dp[k >> 1]) % mod;
}
ll calcans(string S, ll k)
{
if (S.length() == 1)
return calcdp(k);
if (k + S.length() <= 3)
{
if (k == 0)
{
if (S == "000" || S == "111")
return 0;
return 1;
}
if (k == 1)
{
if (S == "00" || S == "11")
return 1;
return 2;
}
return calcdp(k);
}
string T = "";
ll res = 0;
int flg = 1;
for (int i = 0; i < S.length() && flg; i += 2)
{
if (i + 1 < S.length() && S[i] == S[i + 1])
flg = 0;
T += S[i];
}
if (flg /*&& k-(S.length()&1)>=0*/)
res = (res + calcans(T, k - (S.length() & 1) + 1 >> 1)) % mod;
flg = 1;
T = "";
T += ('0' + '1' - S[0]);
for (int i = 1; i < S.length() && flg; i += 2)
{
if (i + 1 < S.length() && S[i] == S[i + 1])
flg = 0;
T += S[i];
}
if (flg /*&& k-(S.length()-1&1)>=0*/)
res = (res + calcans(T, k - (S.length() - 1 & 1) + 1 >> 1)) % mod;
return res;
}
string S;
ll k;
int main()
{
ios::sync_with_stdio(false);
int T;// rd(T);
cin >> T;
while (T--)
{
// rdS(S),rd(k);
// printf("%lld\n",calcans(S,k));
cin >> S >> k;
cout << calcans(S, k) << endl;
dp.clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 4ms
memory: 3436kb
input:
100 11001101001100101101001011001101001100101100110100101101001100101101001011001101001011010 59 01001011010011001011001101001100101101001011001101001011010011 65 11010011001011001101001100101101001011001101001100101100110100101101001100101101001011001 53 001101001100101100110100101101001100101100110100110010110100101100110100101 88 1101001100101101001011001101001100101100110100101101001100101100110100 74 1001100101101001011001101001100101100110100101101001100101 88 110010110100101100110100 69 1...
output:
2 2 1 2 2 4 7 5 7 3 2 2 4 1 4 2 4 3 1 3 2 4 2 2 2 11 5 2 1 3 3 1 7 2 2 4 2 2 6 1 4 2 3 7 4 3 2 8 2 2 2 2 2 2 4 2 2 2 3 2 6 2 11 14 4 2 1 7 3 2 2 2 2 3 5 3 3 3 3 4 5 3 2 4 3 2 2 2 2 3 3 7 2 5 3 4 7 4 2 2
result:
ok 100 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
100 0010110011010010110100110 63 0110100101 63 10010110100110010110011010011001011010010110011010011001011001101001011010011001011010 79 0100101100110100110010110011010010110100 99 0010110100110 57 10100110010110011010011001011010010110011010011001011001101001011010011001011001101 82 100110100110010110011010010110 60 11010010110011010011001011001101001011010011001011001101001100101101001011 93 011001011010010110011010010110100110010110011010011001011010010 65 1101001100101 96 0101101001100101101...
output:
5 10 2 4 5 1 3 3 2 14 1 4 2 2 2 1 1 2 3 2 4 4 11 4 4 3 4 4 3 8 2 4 4 4 2 2 3 1 3 2 7 2 13 2 2 2 7 6 4 2 2 5 2 3 3 2 2 3 3 4 2 2 3 14 1 3 3 2 2 2 3 2 2 9 2 2 2 2 1 2 2 1 4 1 2 7 1 3 7 4 2 2 4 2 2 3 2 3 3 2
result:
ok 100 lines
Subtask #2:
score: 20
Accepted
Test #3:
score: 20
Accepted
time: 1ms
memory: 3500kb
input:
100 10011001011010010110011010011001011001101001011010011001011001101 36577 110010110011010010110100110010110100101100110100101101001100101100 27539 100110100110010110011010010110100110010110100101100110100101101001100101100110100110 49845 01001100101101001011001101001100101100110100101101001100101101001011001 48189 010110011010010110100110010110100101100110100110010110011010010110100110010 35354 00110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110 4502...
output:
594 457 861 835 567 769 633 3145 1549 856 1204 914 790 275 710 475 481 1125 1487 3041 894 2759 720 733 488 930 1546 442 665 929 1558 645 1095 898 553 510 2423 1611 1051 464 2271 458 515 508 841 853 633 469 631 491 808 323 275 666 1594 3371 1165 773 1409 1879 749 512 865 2890 244 448 1864 1098 531 3113 955 644 510 641 309 1292 299 839 3839 455 778 4155 228 858 809 855 567 360 318 2473 562 1401 282 795 224 504 361 3325 529 641
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 4ms
memory: 3464kb
input:
100 00101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010 28932 101001011010011001011010010110011010010 36758 10010110011010011001011010010110011010011001011001101001011010011 29501 01101001011010011001011001101001100101101001011001101 42132 011001101001100101 40012 0100110010110011010010110100110010110 44184 11001101001100101101001011001101001011010011001011010010110011010011001011001 27370 100101100110100101101001100101100110100110010110100101100110100110...
output:
236 595 478 1417 2650 1503 456 862 291 661 631 604 537 523 3778 1053 797 737 819 1041 877 3313 623 534 2582 2679 733 914 405 1776 1569 495 521 4803 898 1007 253 992 1313 263 525 473 2322 462 958 765 1394 1307 671 226 791 5034 2015 1222 723 693 579 633 543 221 3013 1926 1141 2902 790 1020 2945 702 1197 862 785 1667 662 854 433 1555 547 706 1975 988 787 589 1214 1761 406 262 1653 811 1989 884 438 468 571 353 2997 505 446 559 444 895
result:
ok 100 lines
Subtask #3:
score: 60
Accepted
Test #5:
score: 60
Accepted
time: 2ms
memory: 3588kb
input:
100 0110100110010110011010010110100110010110011010011001011010010110011010011001011001101001011010011001 538782295465183009 010110100101100110100101101001100101101001011001101001100101100110100101101001100101 523819376769950058 010011001011010010110011010010110100110010 603617868784229971 10010110100110010110011010 695962134477145434 1001011001101001100101100110100101101001100 721764087905211899 0100101100110100101101001 590145043129729394 10110100101100110100101101001100101100110100110010110 79...
output:
625905115 516804318 857202094 559777803 942938174 126650205 823738533 204922935 174479774 549116985 435387601 527386722 737743599 91923596 404828892 575166800 368697681 280157312 109054327 127248871 416007705 562636356 915364900 206616450 325376905 873446297 760012667 485162216 310998106 778868064 203282547 607835518 49929319 344303338 16063941 171649708 773784510 578834986 319474836 840732934 418302036 903536616 792094299 203007102 247051815 786740599 356141785 863982548 278193066 317650705 695...
result:
ok 100 lines
Test #6:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
100 001011010010110011010010110100110010 502089039763996259 001100101101001011001101001011010011001 817423529459653040 001101001011010011001011001101001100101 802034193184911455 00101100110100101101001100101101001011001101001100101100110100101101 685924881067652914 0011010011001011001101001011010011001011010010110011010010110100110010110011010011001 777952062677584369 0011001011001101001100101101001011001101001011 992500068703595238 1101001100101101001011001101001 601139631397306984 001011001101...
output:
683392369 971834271 632824364 835739796 768691605 738399709 934019276 280965877 316701220 171092155 867696843 683538997 417670933 215883139 342508109 204817004 610017381 39383533 906184344 88925420 876914386 573836809 671037419 723502316 238045307 964532138 243163087 331184603 307269393 802299509 651493294 738840598 251024725 977211840 666278051 686478650 56064207 478292974 449197906 559563044 306986823 202849334 518343150 416679207 104019648 110031422 345113827 647359036 331191683 371999744 902...
result:
ok 100 lines
Test #7:
score: 0
Accepted
time: 3ms
memory: 3428kb
input:
100 1010011001011001101001011010011001011010010110 965395788357776806 011001011010 834399723299099107 010011001011001101001011010011001011001101001 572382637490939482 100101100110100101101001100101100110100110010110 886490565150008015 1100101101001011001101001100101100110 944745159494376740 10011001011010010 507218462583448703 1100101101001011001101001011010011001011010010110011010011001011001101001011010011001011001101001100 526696260608529051 011001011001101001100101101001011001101001100101100...
output:
487338459 750890213 811428491 172643122 543894738 315671710 528259905 562212758 785876656 295586524 846780147 842628536 186736976 970329654 39146776 314362623 586354087 873898880 212848829 322291680 478218035 15356657 790365881 501695725 244540089 157791241 987974209 839161472 241094621 246154851 310259739 949580382 686077654 862156284 935057673 84917631 9557933 719081932 234261349 267539968 599850005 607050282 61129837 441037359 102208016 47542266 69647578 627724076 51701446 78323344 546373930 ...
result:
ok 100 lines
Test #8:
score: 0
Accepted
time: 5ms
memory: 3556kb
input:
100 01011010011001011001101001100101101001011001101001011010 705330500096781561 010011001011001101001100101101001011001101001011010 851375912843577877 00110010110011010010110100 945079007711873639 0101100110100 870068764206535059 01011001101001100101101001011001101001100101100110100101101001100101100 917921718011314351 011010010110100110010110011010011001011010 604069149587953168 110100110010110 754737274755592795 01101001100101101001 692604833786773289 100110010110011010010110100110010110011010...
output:
561874756 300049495 715029994 290932755 962840091 223854657 864023041 64542555 378552772 665977956 752203184 139381977 568199805 855667254 110106682 827933943 538798057 612214841 111094242 525494483 586802958 856988411 248056921 262665454 766650847 540867777 39706110 576233456 223471392 20724731 109910931 84343212 474227672 416957380 973907341 95838466 702196239 756177570 482573559 775292075 883715475 31330863 160159519 211120367 53959181 226928641 566632479 93571472 305239541 838524315 55246006...
result:
ok 100 lines
Test #9:
score: 0
Accepted
time: 5ms
memory: 3556kb
input:
100 01001011001101001011010011001011010010110011010011001011001101001011010011001011010 668637248690562107 01011010011001011010010 644980065533280858 0011010011001011001101001011010011001011 817775377932807795 11010010110011010010110100110010110011010011001011010010110011010011001011001101001011 853646958968094807 11010011001011010010110011010010110100110010110011010011001011010010110011010010110100110 667726231083541580 110100101101001100101100110100110010110100101100110100101101001100101101001...
output:
415562583 706235061 324750433 880275564 648908201 755613035 199718010 559537016 397474476 63479041 808398737 500159396 664858922 30649751 528349475 461615431 963376033 946453957 56312586 221447700 318059566 315140597 891491745 480573070 701122680 99275134 386460261 674519539 932070756 237061523 174296452 135167906 96415721 849909062 82115585 954786329 918321012 746300259 506990157 330946852 700896109 417989846 776132560 290981445 979583501 432083647 591135520 736821893 669731112 125571060 286259...
result:
ok 100 lines
Test #10:
score: 0
Accepted
time: 4ms
memory: 3448kb
input:
100 101001100101101001011001101001011010011001011001101001100101101001011001101001100101100110100 908571956134599568 0010110100101100110100110010110011010010110100110010110100101100110100 661956255077759629 01001011001101001011010011001 690471743858774656 001100101101001011001101001100101100110100101101001 837225153729654554 1010011001011010010110011010010110100110010110100 640902789600479191 001011010011001011 521142564746705181 01100110100110010110011010010110100110010110 815941355587449698 10...
output:
286837132 465444466 286071250 642325384 605281986 233919191 727714937 865734515 682576874 328925908 135819466 311425555 533978152 765596020 399793467 428916382 667727892 788319371 502496068 282462448 195060177 499406026 849240347 144931649 563603626 859714406 2901124 923482218 598036305 944008074 623628047 494879193 495314975 922215277 292076223 221918608 454517119 836883594 429256996 200129324 26624674 988669616 178369690 658773545 765651941 966877530 964976835 205774089 134085131 962515192 869...
result:
ok 100 lines