QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67543 | #1999. Spaceship | alpha1022 | 100 ✓ | 181ms | 3840kb | C++23 | 3.9kb | 2022-12-10 17:08:30 | 2022-12-10 17:09:19 |
Judging History
answer
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 60;
const int mod = 1e9 + 7;
int n,K,q;
struct Matrix
{
int a[N + 5][N + 5];
inline Matrix(int op = 0)
{
if(!op)
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
a[i][j] = 0;
else
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
a[i][j] = i == j;
}
inline int *operator[](int x)
{
return a[x];
}
inline const int *operator[](int x) const
{
return a[x];
}
inline Matrix operator*(int x) const
{
Matrix ret;
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
ret[i][j] = (long long)x * a[i][j] % mod;
return ret;
}
inline Matrix operator+(const Matrix &o) const
{
Matrix ret;
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
ret[i][j] = (a[i][j] + o[i][j]) % mod;
return ret;
}
inline Matrix operator*(const Matrix &o) const
{
Matrix ret;
for(int k = 1;k <= n;++k)
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
ret[i][j] = (ret[i][j] + (long long)a[i][k] * o[k][j]) % mod;
return ret;
}
} G,f[N + 5],f_temp[N + 5];
struct Vector
{
int a[N + 5];
inline Vector(int x = 0)
{
for(int i = 1;i <= n;++i)
a[i] = i == x;
}
inline int &operator[](int x)
{
return a[x];
}
inline const int &operator[](int x) const
{
return a[x];
}
inline Vector operator+(const Vector &o) const
{
Vector ret;
for(int i = 1;i <= n;++i)
ret[i] = (a[i] + o[i]) % mod;
return ret;
}
} f_10[N + 5],f_10_temp[N + 5];
inline Vector operator*(const Vector &a,const Matrix &b)
{
Vector ret;
for(int k = 1;k <= n;++k)
for(int i = 1;i <= n;++i)
ret[i] = (ret[i] + (long long)a[k] * b[k][i]) % mod;
return ret;
}
struct VectorT
{
int a[N + 5];
inline VectorT(int x = 0)
{
for(int i = 1;i <= n;++i)
a[i] = i == x;
}
inline int &operator[](int x)
{
return a[x];
}
inline const int &operator[](int x) const
{
return a[x];
}
inline VectorT operator+(const VectorT &o) const
{
VectorT ret;
for(int i = 1;i <= n;++i)
ret[i] = (a[i] + o[i]) % mod;
return ret;
}
} f_01[N + 5],f_01_temp[N + 5];
inline VectorT operator*(const Matrix &a,const VectorT &b)
{
VectorT ret;
for(int k = 1;k <= n;++k)
for(int i = 1;i <= n;++i)
ret[i] = (ret[i] + (long long)a[i][k] * b[k]) % mod;
return ret;
}
int f_11[N + 5],f_11_temp[N + 5];
inline int operator*(const Vector &a,const VectorT &b)
{
int ret = 0;
for(int k = 1;k <= n;++k)
ret = (ret + (long long)a[k] * b[k]) % mod;
return ret;
}
int main()
{
scanf("%d%d%d",&n,&K,&q);
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
scanf("%1d",G[i] + j);
f_temp[0] = G;
for(int k = 1;k <= K;++k)
{
for(int i = 1;i <= k;++i)
f[k] = f[k] + f_temp[i - 1];
f_temp[k] = (f[k] + 1) * (f[k] + 1) * G;
}
for(int b_s,s,b_t,t;q;--q)
{
scanf("%d%d%d%d",&b_s,&s,&b_t,&t);
Vector v_s(s),v_g_s = v_s * G;
VectorT v_t(t),v_g_t = G * v_t;
for(int k = 1;k <= K;++k)
{
f_10[k] = 0;
for(int i = 1;i <= k;++i)
f_10[k] = f_10[k] + f_10_temp[i - 1];
if(b_s <= k)
f_10[k] = f_10[k] + v_g_s * (f[b_s - 1] + 1);
f_10_temp[k] = (f_10[k] * G) * (f[k] + 1);
}
for(int k = 1;k <= K;++k)
{
f_01[k] = 0;
for(int i = 1;i <= k;++i)
f_01[k] = f_01[k] + f_01_temp[i - 1];
if(b_t <= k)
f_01[k] = f_01[k] + (f[b_t - 1] + 1) * v_g_t;
f_01_temp[k] = (f[k] + 1) * (G * f_01[k]);
}
for(int k = 1;k <= K;++k)
{
f_11[k] = 0;
for(int i = 1;i <= k;++i)
f_11[k] = (f_11[k] + f_11_temp[i - 1]) % mod;
if(b_s <= k)
f_11[k] = (f_11[k] + v_s * f_01[b_s - 1]) % mod;
if(b_t <= k)
f_11[k] = (f_11[k] + f_10[b_t - 1] * v_t) % mod;
if(b_s == b_t && b_s <= k)
f_11[k] = (f_11[k] + v_s * v_t) % mod;
f_11_temp[k] = f_10[k] * f_01[k];
}
printf("%d\n",f_11[K]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.34783
Accepted
time: 0ms
memory: 1752kb
input:
6 3 8 010000 001000 000100 000010 000000 000001 1 1 1 1 3 3 1 1 1 1 3 3 1 1 1 5 2 1 1 5 1 1 2 5 3 1 3 5 2 6 2 6
output:
1 0 1 3 2 2 0 5
result:
ok 8 lines
Test #2:
score: 4.34783
Accepted
time: 0ms
memory: 1836kb
input:
6 4 6 001100 001110 101101 010111 110111 000111 3 2 4 3 3 1 4 4 3 4 4 1 3 3 4 3 3 6 4 3 3 1 4 2
output:
26 49 29 27 18 22
result:
ok 6 lines
Test #3:
score: 4.34783
Accepted
time: 1ms
memory: 1992kb
input:
6 10 5 110101 011001 001111 101111 111010 000001 2 5 2 5 6 1 5 2 3 4 8 3 9 3 3 5 5 1 3 4
output:
713313311 716721076 782223918 335511486 539247783
result:
ok 5 lines
Test #4:
score: 4.34783
Accepted
time: 11ms
memory: 1924kb
input:
60 4 60 101101000101110111001110100111111111110100110011010100110110 100110001111011001010110011111111111011111111011001011010101 101010011110101101010111111111111111111111111110011111111100 011111111011111101001110001111111101001101111110011011111100 001101011101110010101101111111111111001110111011...
output:
228818915 198807528 739150434 613754310 48494 57813 247277017 66785949 533911910 658665057 772132471 482303781 50956 52565 468527929 52925 307346566 287404304 680162765 67378045 764487128 51026 414733445 52565 640535115 510761842 515702458 217788997 27436267 37687 55777 312587125 366800893 412945547...
result:
ok 60 lines
Test #5:
score: 4.34783
Accepted
time: 15ms
memory: 1880kb
input:
60 5 60 110011010101010101100010110101101010100011011111011011011110 100001011010111100111111110011011011011000011111111100110101 100111111101110101111111110111001100011001010111111001110100 111011110101111011011110111011110110111111101011101111001011 001010001111110111011000011110101001011110011111...
output:
599624995 45526585 511492739 445266523 471070025 870078898 790145937 512272867 994850319 848709918 300944165 655311559 280190020 362336951 160057880 60438412 789467000 464653312 211956891 261448319 499944183 621657886 191771609 979467150 784438665 431872843 291057454 46418402 592298349 437938193 758...
result:
ok 60 lines
Test #6:
score: 4.34783
Accepted
time: 15ms
memory: 1996kb
input:
60 5 60 000110100111011111110011111110011011110101110111011011101111 110110111111000110101110010011011111011111111011111111110101 111111010110111100110110000111001101011011101110101001110110 000100010110100101110011111111111110011011010101001011011111 110001111011011011111000111011000111100111011101...
output:
361570155 878706765 633634392 604767724 96497275 668578420 576283294 806208255 814916170 590594483 139294880 618924900 878706765 169919488 258696167 33404616 776625060 974525847 541176492 618366485 802094145 472547715 740115260 192146163 720061694 844420319 672811895 900970869 117323699 176809697 79...
result:
ok 60 lines
Test #7:
score: 4.34783
Accepted
time: 10ms
memory: 1992kb
input:
60 5 60 111011011100011110010111110101001001111011101110001011010001 111010011110111101001111011000111111111110111011000010100101 110110000001110111101100001001111111101100010001000100100101 110110001011111101111111011001011111010110111110111111000101 111010000100011110101111111011101111110111101001...
output:
903762175 620466655 742247772 475706978 98326678 764555675 228287236 326479687 252867412 247200100 297651745 898381695 480984894 496975149 702263844 614947858 888139714 515449503 533453995 645476093 298210024 476837183 990748610 326479687 894031168 515449503 659439388 293335974 139383383 297651745 1...
result:
ok 60 lines
Test #8:
score: 4.34783
Accepted
time: 131ms
memory: 3816kb
input:
60 59 60 111111001110011110010101111100101111011001100111110101011001 111110001011011111110101111000111110111110111011011011110111 111111110110111001011000111101011011111101110001100101001111 110111001111011011011001110110110011111111111111101011011111 01011011010000101001011111101001101111101110001...
output:
889097789 47838751 862208036 817545179 823972313 776422758 531934602 980310349 990314191 246909436 916729686 420711428 283758988 673517382 131971013 592065254 231910225 853637462 943623931 858751005 682780602 257252779 422220505 28358535 683004948 709045773 577929618 819090264 269083130 139189220 81...
result:
ok 60 lines
Test #9:
score: 4.34783
Accepted
time: 128ms
memory: 3744kb
input:
60 58 60 011011100111110111100111111111000111110111111100001110011101 100101101110101011011000101100001011111111101011100100011111 111110111001011011001111111111111010101111101010000011101111 011101010101101100011111111011001011011101111110010010111111 00111101000111010100101110111111101110111001110...
output:
536893136 77755822 704219333 132300389 312202386 976315275 435584534 636537142 771953265 295369137 205715958 197733966 974812356 729205407 166357405 883531790 41360763 983246967 885267629 600141328 31236295 334428405 127411098 27972521 336161355 716194181 626330687 885046964 129722852 682895579 4932...
result:
ok 60 lines
Test #10:
score: 4.34783
Accepted
time: 118ms
memory: 3608kb
input:
60 56 60 000111110110101110111001101000110110110010011101111001111001 010111110111110101011101111111110011010111101111011111001111 101011111011101110101011111100010011010111101101101011101100 101110110100111011110110111111111111110101111111011111110111 00011110001011100110111011101000100111010101010...
output:
768536213 124663212 335536513 9110456 904182673 952262475 831382696 225685797 516113573 688308301 308174105 26942683 719419822 535665185 301255547 674135617 587564459 966634983 980309487 842497672 353693723 750282725 267963114 497874423 562850263 963506235 569097989 410402711 317934104 959620032 642...
result:
ok 60 lines
Test #11:
score: 4.34783
Accepted
time: 131ms
memory: 3840kb
input:
60 60 60 111111111011110101111011110001011111001011111010111111111011 101101001110110101111110110101111010011111000001110111100110 010110001010111101111000001111100100011100011111111101011100 010101111100101110000000111001111011111101100110101111111101 11101111111111101010100110111110111111111001111...
output:
705729571 482306065 834387064 916925094 765359395 242043081 557939924 551188446 446577089 525183156 179286212 88899407 485073392 413801754 703539712 455683368 555335243 201630394 757031532 197904505 909278462 979693168 672510437 471471002 854057178 458752231 568542639 839683999 134242526 514389118 7...
result:
ok 60 lines
Test #12:
score: 4.34783
Accepted
time: 5ms
memory: 2392kb
input:
20 20 20 10111110111001011001 11001111100111011111 11000101100011100101 11101010111000001111 11101011111101111011 01111110111011011001 11111111110101100110 11011001101010111110 11101011011111111110 01010111110010011001 10001101111110011011 10001010100101101101 10011010011010111101 001101110000111110...
output:
913483583 67417963 801798892 559377478 397608020 75224225 42959642 582938529 486918338 14604947 425114704 595276201 43286170 288543906 902090680 314812855 117311471 593413979 398075401 490408335
result:
ok 20 lines
Test #13:
score: 4.34783
Accepted
time: 1ms
memory: 2212kb
input:
20 16 20 01011011111111101011 01111110111101101111 11101111101011110110 11111101011110001110 11011000111010111001 00011111110011101111 11111010010001111100 11001110110101101110 10100010111000110010 10100010010001001111 00011010011100100100 01110110011011011111 00000101011010100101 010000111101100010...
output:
640450293 886313896 689831991 494788119 570429944 222941461 146352620 362404624 1096616 121348005 432018387 454815245 666458903 61987807 396357234 105928332 515814917 467072163 930259540 715530412
result:
ok 20 lines
Test #14:
score: 4.34783
Accepted
time: 4ms
memory: 2344kb
input:
20 20 20 11101111111111110101 11111011010101011101 11101111101111110111 11011111111110111100 10010010111101111011 11010011111101101010 01011101101001001010 11010111110011111010 10101111010100110110 11110010111111111011 11111111110010111011 10011101110111010011 11111110011010111111 101000110001011110...
output:
385390419 454311707 699513282 332500375 973346913 202133205 949948294 952006502 11953672 344557108 300186523 972824039 960322308 426309157 870549091 949918805 2548834 705646652 458990257 690122077
result:
ok 20 lines
Test #15:
score: 4.34783
Accepted
time: 4ms
memory: 2388kb
input:
20 20 20 11111111101101101000 11111111111011110111 11111001011110011011 11101111011001011010 11001110111011110110 00100011011111110111 00111000111110110000 01110101010111011100 10111110111101110001 00011011011011101111 11110010111111111010 11010110110110010111 01101010100111011011 101111010110111110...
output:
956525923 885099666 653370559 609353986 768358511 784189269 441227644 348011264 915269384 412433449 704663660 476832915 386432757 420649503 652708650 611704168 398550395 950091228 369306610 717832324
result:
ok 20 lines
Test #16:
score: 4.34783
Accepted
time: 173ms
memory: 3816kb
input:
60 59 60 110110111010111101010010111101101011110011100111111110111111 110111110111011101100110110010111101011010101111001010111111 001011110000001101110110001101110000110011111101111111100011 110011001011110011111011100011000110000011011100011010101100 01101011110110011110111111101101101111010111110...
output:
119599851 253913577 192068128 987241667 924960313 436457742 724101316 549666696 342328117 825892071 193936249 136972566 722067170 145153605 369047574 357405181 442609305 903226205 815305478 121408453 811391654 417637386 513206169 530032797 267177991 279173611 421026697 528408526 87707564 638674058 4...
result:
ok 60 lines
Test #17:
score: 4.34783
Accepted
time: 170ms
memory: 3812kb
input:
60 59 60 101000101111111111101111011001101110110111011110110110000111 111011110110000000111011110100111110110011100011001111101101 110010010011110101001001111111111011001011111100110010001111 110111111100110001010110100001110011111011011100111111000010 11101110011110110001001001100110011011011110110...
output:
834268515 791596185 376711358 800171923 118641927 984251929 755154254 577964499 638038790 247139796 613474913 238382422 582031585 660501496 701886668 50922969 227091787 698008834 800479977 827767788 634193204 859715438 672059174 965234571 133581582 191948462 591232075 550966910 179129989 387097773 4...
result:
ok 60 lines
Test #18:
score: 4.34783
Accepted
time: 181ms
memory: 3804kb
input:
60 60 60 111111111111101011011111100011100111111100101110111111011111 010111011101101111011111111101001110101100111011101010111011 111011000110101111111111111110001000011111111100011111011101 010011011101110010011000011100101010010111110111010101110101 11011100011111111111101101011110111010111111111...
output:
259028760 490900362 1475599 40218854 211061496 173866277 532408525 876942468 509608423 328407584 151741425 801434871 623918660 591986341 991361051 832240383 521687025 419830876 360695386 861129876 316170930 782916111 569838182 21981289 627393089 572542735 843137642 94861269 998736688 451955215 91851...
result:
ok 60 lines
Test #19:
score: 4.34783
Accepted
time: 179ms
memory: 3748kb
input:
60 60 60 101101111111111011101110001110111111011000111100011110011110 111111011011010111101011110111111010111011110000111000111000 101011101110011111111100001101111111001101001001011011001011 111001111110101000010100111110000111101100110101110111110111 11110100010101101011100000101110111101110011110...
output:
337199906 357369221 100399581 988710174 361612150 296168332 635450403 212252272 31942710 462436 725611091 826171804 20492828 420451233 205754 546986134 357403601 309834852 758966574 722517386 497368222 792578801 768973442 401063903 404364199 36433402 272780466 377128545 72449886 363802560 548930438 ...
result:
ok 60 lines
Test #20:
score: 4.34783
Accepted
time: 177ms
memory: 3824kb
input:
60 60 60 100001010011111010011000101101000011001101000110111001100111 101101010100101011110101100110001111100001111111101101000001 111011110111101111111110000011111010111010111101100010111010 101111111101111110011111010011011101110101111110111010111100 10000111111110111101011111110111011110011110110...
output:
54891655 292979577 313100228 829867659 308710655 899101442 853325052 612822107 795029427 249728493 276429687 264391074 141837729 621365716 278230449 155446827 405613077 729542340 968307680 678278950 665479592 419541794 739372011 180952215 903040288 926976837 915150836 282826541 875601250 401417 4854...
result:
ok 60 lines
Test #21:
score: 4.34783
Accepted
time: 175ms
memory: 3828kb
input:
60 60 60 111110000010000110111011100010111101111110010110001001110101 011110011101101001111100011100110110011010011110110100111101 110110110111010010101110110011001100111101111000000011100111 101111111011011110100111111001101001101011011111111110100111 01011010010111111010111110111111001011110001111...
output:
630035150 682026759 927448582 344175720 991917202 846723358 155627817 417466638 819194716 662083409 165032361 328378651 311098462 193167835 342416826 621137325 912696242 609886239 626403642 320465271 497344612 837896624 114588146 604245638 834034487 514883892 192510605 213723624 793489356 475474682 ...
result:
ok 60 lines
Test #22:
score: 4.34783
Accepted
time: 158ms
memory: 3728kb
input:
60 57 60 101110111110100011111011011110011001010111111101101100111011 111111101111111001100011111110110111011111111111110011111101 110101110011010110100111110101010100111110011111101001010010 000110110111100111010011110101111101111011011111001101100100 11110111011101101110011111001110111011111110111...
output:
525368864 125035055 487209096 717624418 978754211 110924884 682757405 148936859 384179531 378994459 177412412 407959229 705362641 865660932 639800528 470551355 282135713 749044837 775053703 998279264 823669429 549528956 974605313 614800147 296248403 814979663 743562292 505892908 484574039 523208340 ...
result:
ok 60 lines
Test #23:
score: 4.34783
Accepted
time: 179ms
memory: 3828kb
input:
60 60 60 111011011001111110111100111111110110011111111111011010110111 111111111011111111010111111111010111100000110001111111110101 100010111101011001001101111111100000001101101101011010001101 011110010011110111110100110010100111100100101111111011011101 11111100110111110101101101111111111111101011110...
output:
356596877 441566612 179333165 311294369 267656603 703411289 219226473 728052015 288908648 455385192 228836868 374644248 494514849 503767083 263233318 18854480 493737608 347629389 446732223 250050219 170404093 70017782 212342906 990768281 95703122 273603547 685643604 353814169 225807386 897490754 530...
result:
ok 60 lines