QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359071 | #8303. Junior Mathematician | kevinyang | AC ✓ | 2006ms | 74144kb | C++17 | 2.0kb | 2024-03-20 11:54:25 | 2024-03-20 11:54:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9+7;
int dp[5001][60][60];
vector<int>pw(5005);
int fix(int x, int m){
x%=m; x+=m; x%=m;
return x;
}
int find(int a, int b, int len, int m){
int ans = 0;
for(int i = 0; i<m; i++){
for(int j = 0; j<m; j++){
int na = a+i-b*j;
na = fix(na,m);
if(na==0)ans+=dp[len][i][j];
ans%=mod;
}
}
return ans;
}
int solve(string s, int m){
int n = s.size();
if(n==1)return 0;
int ans = 0;
dp[0][0][0] = 1;
pw[0] = 1;
for(int i = 1; i<=n+2; i++){
pw[i] = pw[i-1]*10%m;
}
for(int i = 1; i<=n; i++){
for(int a = 0; a<m; a++){ // a encodes x - f(x)
for(int b = 0; b<m; b++){
for(int d = 0; d<10; d++){
int na = a + pw[i-1]*d - b*d; na = fix(na,m);
int nb = (b+d)%m;
dp[i][na][nb]+=dp[i-1][a][b];
dp[i][na][nb]%=mod;
}
}
}
}
for(int i = 1; i+1<n; i++){
for(int d = 1; d<10; d++){
int a = pw[i]*d%m;
int b = d;
ans+=find(a,b,i,m);
ans%=mod;
}
}
int a = 0; int b = 0;
for(int i = 0; i<n; i++){
for(int j = 0; j<=s[i]-'0'; j++){
if(j==s[i]-'0' && i<n-1)continue;
if(i==0&&j==0)continue;
//cout << i << ' ' << j << '\n';
int na = fix(a + pw[n-i-1]*j - b*j, m);
int nb = (b+j)%m;
//cout << na << ' ' << nb << '\n' << '\n';
ans+=find(na,nb,n-i-1,m);
//cout << ans << '\n';
ans%=mod;
}
int d = s[i]-'0';
a = fix(a + pw[n-i-1]*d - b*d, m);
b = (b+d)%m;
}
for(int i = 0; i<=n; i++){
for(int j = 0; j<m; j++){
for(int k = 0; k<m; k++){
dp[i][j][k] = 0;
}
}
}
return ans;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while(t--){
string l,r;
cin >> l >> r;
int m;
cin >> m;
for(int i = (int)l.size()-1; i>=0; i--){
if(l[i] == '0'){
l[i] = '9';
continue;
}
l[i]--;
break;
}
if(l[0] == '0'){
l.erase(l.begin());
}
int v = solve(r,m);
v-=solve(l,m);
v%=mod; v+=mod; v%=mod;
cout << v << '\n';
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 10 50 17 33 33 3
output:
2 1
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 37ms
memory: 3868kb
input:
1252 3893 6798 7 5883 8853 7 2999 4351 2 565 1767 7 1759 4751 10 79 8631 2 2128 8721 7 7890 8423 6 4708 7458 9 4501 6027 4 932 2708 2 3518 5859 7 4355 8296 3 2642 4470 10 7408 8939 8 4892 6777 7 4962 7976 6 2722 3171 7 6616 7527 6 7070 7612 5 429 2087 7 8786 8823 3 8831 8994 2 6346 8524 4 6026 8648 ...
output:
505 447 767 143 357 5413 994 150 321 539 1083 388 1267 225 229 348 588 57 150 87 198 21 126 636 281 210 146 1538 635 143 476 700 966 173 275 29 239 48 1018 377 1349 503 646 43 980 685 563 1187 1 85 1 1025 38 16 1372 68 851 679 43 625 955 431 154 185 644 48 677 429 1182 80 518 258 34 281 36 721 148 2...
result:
ok 1252 lines
Test #3:
score: 0
Accepted
time: 994ms
memory: 3720kb
input:
1253 3862 4458 39 5034 7673 2 510 7150 27 3514 4389 7 6435 6996 58 7300 8758 12 8676 8774 44 8544 8573 49 2445 8608 49 7812 8378 42 4214 4543 50 4995 5544 22 677 6824 55 7444 8746 9 7224 8456 25 3857 5279 26 1343 6042 22 6173 6548 57 2386 6274 58 489 1984 24 1351 2880 47 8499 8624 25 307 8952 46 641...
output:
10 1580 243 143 13 166 4 1 144 17 13 26 107 149 49 82 286 4 83 75 25 5 234 15 200 333 5 31 115 46 17 227 2 129 48 70 142 35 27 244 220 62 251 370 10 375 58 73 211 107 17 79 362 30 1559 397 37 3 24 5 60 85 11 181 19 39 245 176 7 585 138 97 23 21 21 185 69 168 535 61 26 14 39 60 37 50 240 12 44 307 26...
result:
ok 1253 lines
Test #4:
score: 0
Accepted
time: 1087ms
memory: 3696kb
input:
714 5435966 8310614 52 5704997 7881777 18 2219416 7123670 45 8753521 8908557 36 6324833 6708892 16 7826873 8940017 40 4564053 4856296 3 7244416 7308752 50 1082842 3048434 39 1798212 4400110 53 1816169 7932160 12 1357724 3034166 19 7895400 8555848 51 8776920 8789604 46 4322545 5374832 11 6456132 6467...
output:
48977 101411 106247 4030 20946 26428 93477 858 49983 49245 433492 88224 12879 218 95549 823 16450 152429 210336 36228 27704 25600 9019 234595 32348 153999 310550 39190 26443 79160 16566 89981 39522 115033 151913 13156 85511 206261 7650 103807 133667 6639 143061 37525 274112 436224 51814 38402 20615 ...
result:
ok 714 lines
Test #5:
score: 0
Accepted
time: 1130ms
memory: 3736kb
input:
500 47086127 8062735606 18 360878357 562767928 24 49480976 8576022783 13 3476757922 7841781308 36 2555413805 7145295185 18 180566103 8759489364 54 2458610039 3222800330 24 5333648352 6013137590 36 2790561710 8370697212 29 1598694193 3669508654 16 27316449 6307649412 22 739739068 8138716900 19 166733...
output:
461506504 8493277 655830486 125913564 262891609 164175315 32385778 19692674 192417430 133552569 293785322 389425594 487919772 17225005 136379 734106267 73512105 22427516 320865203 272792111 127408900 2921953 11288343 6894189 1171204 857703413 29856027 5021161 6285361 16526239 53011372 122737980 4944...
result:
ok 500 lines
Test #6:
score: 0
Accepted
time: 1230ms
memory: 3816kb
input:
312 1466909309993075 8751933522748891 15 1470437399519306 2056692847618591 31 3462736756734265 3693974732267180 30 2550983922966066 2664700547522419 2 323739377300110 8202701694787388 33 4594231434730263 5457883714482730 48 2342146294298329 2905327391488781 37 576788792669307 7681525011048650 35 214...
output:
304711751 467701491 289116028 831796430 166013031 976516920 81393001 951604794 663155343 12624770 543662565 817025025 907403922 303373776 857468194 802491639 496656087 929134296 202483730 829356695 874995237 840765565 180569984 372753145 458365308 762517477 139702179 357013100 472907393 942235423 55...
result:
ok 312 lines
Test #7:
score: 0
Accepted
time: 1244ms
memory: 3916kb
input:
263 1751756799557614347 2608908010018337253 12 2077506913506405723 2904563726127086387 18 2406248833666099723 3939343666399883893 13 5025873658872423900 5822426817828120268 51 4229271164169909972 4303109259923609466 46 7116626771479640286 7212987115966737012 60 503223518556186695 1973325047576453584...
output:
791235447 178363881 36798026 359581422 56681252 576121209 357107858 927607355 939094762 493883669 593902637 923542274 322126366 522023696 803866720 962490331 677380247 431634331 85697956 996520497 22596944 925288248 748722742 688249621 365871679 414662504 328060332 642808469 151396002 760973240 3086...
result:
ok 263 lines
Test #8:
score: 0
Accepted
time: 113ms
memory: 3808kb
input:
263 328071702552863244 843473407004106590 17 140588221145737224 8119462274765102663 15 7517303140694396850 7601796857178539056 7 6758109157798455543 6880833853610144336 13 111502177553827605 8334471754720816207 4 2103684020252551357 8810675837016588899 4 3941954740850914337 3972920335788395349 7 400...
output:
107319357 488200376 788989796 944936538 25639580 216069069 523290119 773995041 495070125 990777248 204597962 959522884 54204061 485403889 230454072 452413479 47538814 357530945 395864291 140709983 617228930 749613728 133703434 640363996 868940190 51473501 649254312 654406783 639278287 298724448 2400...
result:
ok 263 lines
Test #9:
score: 0
Accepted
time: 251ms
memory: 4048kb
input:
503 33288365082 9227925245195 16 59 802197 26 6956 7375307934047 7 29350276 157525382285705 8 87917723944 2622978617027 29 9588 764826234267569 17 84 7599622 19 377 39561583041 18 652346471168694 688121437333987 24 9666655 404774462995478 2 16643 2613168692 10 910 57602 28 323034 689000707287 10 453...
output:
634214531 26817 609653693 183912932 415716776 780578739 399983 273500099 498943227 71678850 267276803 2070 137041657 431891062 373820027 32802567 588615099 443017075 496773727 766853197 25154 494757948 4990595 419 27065052 119483842 822543680 827289 97446592 250502467 1007321 21592485 726793 1732865...
result:
ok 503 lines
Test #10:
score: 0
Accepted
time: 955ms
memory: 3940kb
input:
329 412493263678147 660601393707287 28 9723705080777012 19965761235108259510 38 5454 53866130984245 17 18907141353 9709555252366 34 142024114713 9581340733011389 39 66 7512406293686550417 17 537807643448 62409396627207198507 40 72 552764133206412159 11 21861253339 199717447737545826 28 36651874230 9...
output:
695071799 194258371 595465950 176215947 152248536 622533157 950803487 88190259 816965053 109269174 601302145 741903056 664897245 44681370 282931921 871041086 360879395 549817741 382388913 507884463 643110872 383222793 626368166 255489595 672552541 598284827 144731553 114718124 27274235 113797847 727...
result:
ok 329 lines
Test #11:
score: 0
Accepted
time: 849ms
memory: 4944kb
input:
69 77161831458410772871039809525841542579809898128209163890583315260333136437 7301997025742841615819495645852503066517743746763541025525870768264996909812744190609552664449 30 70734246820445489405694057836634945559878763145819072216802056755958061999531 1270710553508887230166399355899627220531809338...
output:
221403047 93485050 496777672 619168920 968387212 453885434 751747056 83104537 472252591 955950739 280535808 133797866 807949248 927542587 658729246 178667492 174054548 495796128 201947759 115136819 140757396 880065434 613435375 862058374 322246843 293215494 953186103 171576882 533712872 160622124 37...
result:
ok 69 lines
Test #12:
score: 0
Accepted
time: 338ms
memory: 8620kb
input:
17 9471151626496415734718428823075234688507619337255680356350385163270972835704902220481923263174365037406691840830814216 5949394657826153504860981279023067912976461909746558450229326827857816964519427423276619930735353025700929967515167702956696 19 39295126073796699033652586104107912103917679342776...
output:
752882690 700532701 310376229 422115953 568302193 915612968 572482784 233398598 50487870 827481559 60462125 357919212 901960382 623335235 714951138 226806051 428328025
result:
ok 17 lines
Test #13:
score: 0
Accepted
time: 72ms
memory: 11112kb
input:
7 845704762757988157636180239849226688769119506118635304063471171410433893209066584857885106853136395190848783461470382587693305536758193487767879905235120 143459186904784648291738831172680923820108497610869433100832727119148831592249772157345756253435278373049111116275515975630104524357784579619171...
output:
882569526 840333776 687836474 907004095 260240069 937365004 830556269
result:
ok 7 lines
Test #14:
score: 0
Accepted
time: 31ms
memory: 28316kb
input:
2 3539388254371431670620257479446458197086240684315698196756114198594954406965121993031170743859565544985645314370649010814731232678629841611405017952678935313235238592912221255585504398630496719743162966137442590982645930455334134440879067760530007713444032946249144842890977570940269988148362658377...
output:
342758890 312334409
result:
ok 2 lines
Test #15:
score: 0
Accepted
time: 37ms
memory: 24684kb
input:
2 6287879202761133259087501096764479112574362228136890065873316424815822607375966105421071739553594044727464671496645869239252294424678663284707673099297557799544282289355720777062240860264659406586612361864172925421927129280245675950234676492962657274837914254423642637283707917753015976556461798146...
output:
747540616 620345044
result:
ok 2 lines
Test #16:
score: 0
Accepted
time: 3ms
memory: 25132kb
input:
1 9391250929876454672209103553581737568270255945003717382345381154981831841236622988251563840789934104057259194973627062085663243171755099727834199983073453564122064384832913735050167544998115201834027467976606762360874729722263913956425553616596436548920663149123683794339225977708783050476428622179...
output:
939892867
result:
ok single line: '939892867'
Test #17:
score: 0
Accepted
time: 743ms
memory: 4988kb
input:
65 540 6638282413084931326456455224476385008365783812975053569531599625141893708083514 42 14 35083743346594998325869037451299605999887746173125052751990439294979 37 10914094351 25855361085321537810417039454198787505944006334366558391477601566609493368576393585779829 43 32 519612713800993875216061448...
output:
264148590 195710997 529764371 141827289 746054751 460077906 63155721 777517330 196257657 961016335 285626144 635717217 487902227 508844707 331290009 239492066 735789731 262472958 281967885 857550310 195621717 402743501 172036152 489537664 26311182 655494741 240493602 431019592 738382481 785627491 18...
result:
ok 65 lines
Test #18:
score: 0
Accepted
time: 27ms
memory: 6512kb
input:
21 1338901443674977 359840655917619976339749574640124559966722567633558398854994929958440518334756262274295142891353848353065289989 3 7583666204966271857626 33045423967914663860873848698364762279022001897687349350004161416729950058407583867575187581376691323377519356865377486746202420259032 7 924159...
output:
752121427 541109787 463839506 392584341 201109202 658692361 39622075 194180170 879934192 683416401 847398982 715315617 318022102 971352574 439525250 96535249 212297963 786310554 771992191 475494380 16448
result:
ok 21 lines
Test #19:
score: 0
Accepted
time: 440ms
memory: 13612kb
input:
11 857620516181638150831085923135051280185154792049535502196921859985124681798413982991069714963278000671806010302402756880610664361585178363664282663984471035049713393719863577557837235955666353435831515421105337446769549621417519370554072476217627688285046035279957845293457986489165957962642097921...
output:
68651477 148182959 693128212 663784500 401577161 45917816 189833987 101524824 329352218 703022523 961128907
result:
ok 11 lines
Test #20:
score: 0
Accepted
time: 467ms
memory: 19108kb
input:
8 2191050698441853024399743244319864041156247319211367002629155828033556940361834710396183056601635183845213379938036783912251323103704926590906459784836286968769723494372627957023552998239335320308587486027626871210441959551009650789910583892806246007535697087515084602064168415587959414302838210836...
output:
879865004 917866260 793307832 570896413 487547153 871406352 320134459 331559565
result:
ok 8 lines
Test #21:
score: 0
Accepted
time: 1377ms
memory: 23172kb
input:
5 7792134817695641383522852903020748392508187048260309345168021301270872973430024795268608624787860246995761054238292563950691004866977273290602772557248903047745030125550942644375446992518507166245737788670698063862811102140775368540020380167164647793832438064052757563456646424312895788897362520288...
output:
461538290 504610922 968528781 314067902 883926332
result:
ok 5 lines
Test #22:
score: 0
Accepted
time: 157ms
memory: 12484kb
input:
7 53505677726599783858438456156590449460566695494838599891421905905751359920699802254091055318054248518 1557046622628019985495857807972279858167294083615707314928608832219880907921582535632650109939924869678682035029355727208070980470958469810491970461483290802605888155172399689584853985781971688515...
output:
52474032 36770405 491810582 376928001 370322948 56193144 455390334
result:
ok 7 lines
Test #23:
score: 0
Accepted
time: 261ms
memory: 26236kb
input:
3 7844367357535553881111219875688287190707722726156284859216145945276064573921024605028818320638768409347412521910854931915596808321887834960775830441367546660358316224892236085534682135710811504692832414502116895307872499150852221970815334573848917216380446025892826333665273306749460578044101925578...
output:
502163412 337396208 394443212
result:
ok 3 lines
Test #24:
score: 0
Accepted
time: 14ms
memory: 25160kb
input:
2 7104105092571130858703852172415788499337167354874474285815425768966424607349718965939709957028175306556091042619969021698984111752041230745897837252542304284566344005954126241348571032129960271961717283443946277040698667490289237205127893556877699524593299337400246076200530388769089033986105422068...
output:
89862517 309319498
result:
ok 2 lines
Test #25:
score: 0
Accepted
time: 298ms
memory: 51324kb
input:
1 210252449536500821019386110461213535914703887049221577750431437299007838325211598524895358823173391850765648887371090676178167346288231448794430465891777215221405469970867467162699485690118821804584428775032 768597781133123299326146350728378350147195726783364991397176453679527038342280486447270542...
output:
905293073
result:
ok single line: '905293073'
Test #26:
score: 0
Accepted
time: 1082ms
memory: 73904kb
input:
1 3910911187767247262598772861458209226450121993753405102295459935651928020909134047667418958796161455215212202438604287110564155426075656587420749409771375062115818276688924188927520083618148713202492326416793755651717142516170048574657219526927179387083174734901007413640693713479951990304481946690...
output:
284080026
result:
ok single line: '284080026'
Test #27:
score: 0
Accepted
time: 988ms
memory: 73592kb
input:
1 4908956499295430726515451191658385402126330993498849151653210082453030054091112025424683389532311683358206529889366884603056380065503155700838642185155522730818447393677232834680182777115080967598783598557398 85246675658221165194764161040682251106430427641477716225480253989957009397559718138550721...
output:
69022621
result:
ok single line: '69022621'
Test #28:
score: 0
Accepted
time: 432ms
memory: 57080kb
input:
1 2697088702025461970975313001996189843292971775835900672649080072596656947247489067109068568267423097006590964933656994270659382384118318976893281699474612330668016210997983727909664675580862200446479621680306962703492879922993529092114529445158801130111797556345540830616297503601598451010093093869...
output:
604094937
result:
ok single line: '604094937'
Test #29:
score: 0
Accepted
time: 264ms
memory: 42672kb
input:
1 1953249291909527735365705077374603496113117498111119218278401434030489577656908887454360012892233619433080139179451949696046077406313656393869689050925893183266670188721983798111476431939883870804902408474871424695044769590332496034193465953889991877449745678920434850902120367495051189482766292093...
output:
824934852
result:
ok single line: '824934852'
Test #30:
score: 0
Accepted
time: 1527ms
memory: 70432kb
input:
1 9059705082675778734109887638496334170007571745925944027548674398899506478829425257788533097463143714897678476467857389211312450117470693119227322701434738178475161429977170076983528622133952637887713250473730046436713277947433073808320245512161879020237558469558044194754152267203663041337097401110...
output:
63184232
result:
ok single line: '63184232'
Test #31:
score: 0
Accepted
time: 31ms
memory: 30848kb
input:
1 4304844602715037123159986989883355250426392024163939940393795379798629333723543598556475048007167085281320140938618439185094199053827095890331979810098493198614989521220121197028997115133034779117062632109507729652649126375177486548325773867028535454590656141094821251739888177449621812833558824471...
output:
958183384
result:
ok single line: '958183384'
Test #32:
score: 0
Accepted
time: 195ms
memory: 45452kb
input:
1 719726778029369151253231138730921205137396403084291910908149902069173006976257925952302176108581785931062916331830463341535994911052151142961392772733327324557298505822603857999 925020756856468521342656768829677512587181384649701571202791303294245800215243689844192139684104940789639599488184804102...
output:
208597692
result:
ok single line: '208597692'
Test #33:
score: 0
Accepted
time: 61ms
memory: 32040kb
input:
1 7434859931664592123182945233168995351363381422017698134578903453535967656116900649987450223105254071477682703377107327788016010554154537767147348919699825847880831982384042235650007672200878255987225922995212809814665174455870567020300054602608846941614755196127182378515480525732106285263401142634...
output:
542971524
result:
ok single line: '542971524'
Test #34:
score: 0
Accepted
time: 18ms
memory: 27028kb
input:
1 4571049841193550495193197578914285672601574151004558620625541052330979872348306530346794686397676955617797257650317193193460928777849270537757058032562226031317196371428256156071983608267849610790579418921555311943559892070701795031023086326922224194218732485778971155485545222681367035537267481861...
output:
788376059
result:
ok single line: '788376059'
Test #35:
score: 0
Accepted
time: 2006ms
memory: 74140kb
input:
1 10 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
9662647
result:
ok single line: '9662647'
Test #36:
score: 0
Accepted
time: 1137ms
memory: 73920kb
input:
1 10 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
269464404
result:
ok single line: '269464404'
Test #37:
score: 0
Accepted
time: 1596ms
memory: 74144kb
input:
1 10 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
186731706
result:
ok single line: '186731706'
Test #38:
score: 0
Accepted
time: 459ms
memory: 60476kb
input:
1 10 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
282228675
result:
ok single line: '282228675'
Extra Test:
score: 0
Extra Test Passed