QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641883 | #1999. Spaceship | Elegia | 100 ✓ | 136ms | 7912kb | C++14 | 4.6kb | 2024-10-15 03:07:12 | 2024-10-15 03:07:14 |
Judging History
answer
/*
_/_/_/_/ _/_/_/_/_/ _/_/_/
_/ _/ _/ _/ _/
_/ _/ _/ _/ _/
_/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/_/
_/_/_/_/ _/_/ _/_/_/_/_/
_/_/_/_/ _/ _/ _/ _/
_/ _/ _/ _/ _/_/ _/_/
_/ _/ _/_/ _/ _/_/ _/
_/ _/ _/ _/ _/ _/
_/ _/ _/_/ _/ _/
_/ _/ _/ _/ _/ _/
_/_/_/_/ _/ _/ _/ _/
_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/ _/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/_/_/_/_/ _/_/_/_/_/
_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/ _/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/_/_/_/_/ _/_/_/_/_/
*/
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <limits>
#include <numeric>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v)
is >> x;
return is;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
if (!v.empty()) {
os << v.front();
for (int i = 1; i < v.size(); ++i)
os << ' ' << v[i];
}
return os;
}
const int P = 1000000007;
int norm(int x) { return x >= P ? (x - P) : x; }
void add(int &x, int y) { if ((x += y) >= P) x -= P; }
void sub(int &x, int y) { if ((x -= y) < 0) x += P; }
void exGcd(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return;
}
exGcd(b, a % b, y, x);
y -= a / b * x;
}
int inv(int a) {
int x, y;
exGcd(a, P, x, y);
return norm(x + P);
}
const int N = 65;
int n, k;
char g[N][N];
int f[N][N][N], sum[N][N][N];
int l[N][N][N], r[N][N][N];
int main() {
#ifdef ELEGIA
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> n >> k >> q;
for (int i = 1; i <= n; ++i) {
cin >> (g[i] + 1);
for (int j = 1; j <= n; ++j) g[i][j] -= '0';
}
for (int i = 1; i <= k; ++i) {
for (int u = 1; u <= n; ++u) {
l[i][u][u] = r[i][u][u] = 1;
for (int v = 1; v <= n; ++v)
for (int w = 1; w <= n; ++w)
if (g[w][u]) // v - w - [u]
add(l[i][u][v], sum[i - 1][v][w]);
for (int v = 1; v <= n; ++v)
for (int w = 1; w <= n; ++w)
if (g[u][v]) // [u] - v - w
add(r[i][u][w], sum[i - 1][v][w]);
for (int v = 1; v <= n; ++v)
for (int w = 1; w <= n; ++w)
f[i][v][w] = (f[i][v][w] + l[i][u][v] * (ull) r[i][u][w]) % P;
}
for (int j = 1; j <= n; ++j)
for (int t = 1; t <= n; ++t)
sum[i][j][t] = norm(sum[i - 1][j][t] + f[i][j][t]);
}
while (q--) {
int a, s, b, t;
cin >> a >> s >> b >> t;
static int x[N][N], y[N][N], xs[N][N], ys[N][N];
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
memset(xs, 0, sizeof(xs));
memset(ys, 0, sizeof(ys));
x[a][s] = 1;
for (int i = a; i <= k; ++i) {
for (int u = 1; u <= n; ++u)
for (int v = 1; v <= n; ++v)
if (g[u][v])
add(x[i][v], xs[i - 1][u]);
for (int u = 1; u <= n; ++u)
for (int v = 1; v <= n; ++v)
xs[i][v] = (xs[i][v] + x[i][u] * (ull) r[i][u][v]) % P;
for (int u = 1; u <= n; ++u) add(xs[i][u], xs[i - 1][u]);
}
y[b][t] = 1;
for (int i = b; i <= k; ++i) {
for (int u = 1; u <= n; ++u)
for (int v = 1; v <= n; ++v)
if (g[u][v])
add(y[i][u], ys[i - 1][v]);
for (int u = 1; u <= n; ++u)
for (int v = 1; v <= n; ++v)
ys[i][u] = (ys[i][u] + y[i][v] * (ull) l[i][v][u]) % P;
for (int u = 1; u <= n; ++u) add(ys[i][u], ys[i - 1][u]);
}
int ans = 0;
for (int i = 1; i <= k; ++i)
for (int j = 1; j <= n; ++j) {
ans = (ans + x[i][j] * (ull) y[i][j]) % P;
}
cout << ans << '\n';
}
#ifdef ELEGIA
LOG("Time: %dms\n", int ((clock()
-nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 4.34783
Accepted
time: 0ms
memory: 5852kb
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: 1ms
memory: 5804kb
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: 5932kb
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: 6ms
memory: 5908kb
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: 8ms
memory: 5876kb
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: 9ms
memory: 4072kb
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: 8ms
memory: 5880kb
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: 68ms
memory: 7816kb
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: 63ms
memory: 7500kb
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: 66ms
memory: 7484kb
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: 66ms
memory: 7704kb
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: 0ms
memory: 6120kb
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: 2ms
memory: 6116kb
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: 0ms
memory: 4436kb
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: 2ms
memory: 6180kb
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: 135ms
memory: 7564kb
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: 136ms
memory: 7608kb
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: 128ms
memory: 7788kb
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: 130ms
memory: 7748kb
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: 135ms
memory: 7912kb
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: 132ms
memory: 7852kb
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: 127ms
memory: 7452kb
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: 136ms
memory: 7748kb
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