QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563078 | #2023. Routing Schemes | elegia | 100 ✓ | 2ms | 3784kb | C++11 | 4.0kb | 2024-09-14 02:25:12 | 2024-09-14 18:52:54 |
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 = 150;
int fac[N];
char g[N][N];
char s[N];
int in[N], out[N];
int mat[N][N];
int det(int n) {
int ret = 1;
for (int i = 1; i <= n; ++i) {
int p = i;
while (p <= n && !mat[p][i])
++p;
if (p > n)
return 0;
if (p != i) {
for (int j = i; j <= n; ++j)
swap(mat[p][j], mat[i][j]);
ret = norm(P - ret);
}
ret = ret * (ll) mat[i][i] % P;
int nv = inv(mat[i][i]);
for (int j = i; j <= n; ++j)
mat[i][j] = mat[i][j] * (ll) nv % P;
for (int j = p + 1; j <= n; ++j)
for (int k = n; k >= i; --k)
mat[j][k] = norm(P + mat[j][k] - mat[j][i] * (ll) mat[i][k] % P);
}
return ret;
}
int main() {
#ifdef ELEGIA
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
fac[0] = 1;
for (int i = 1; i != N; ++i) fac[i] = fac[i - 1] * (ull) i % P;
int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
cin >> (s + 1);
for (int i = 1; i <= n; ++i) cin >> (g[i] + 1);
memset(in, 0, sizeof(in));
memset(out, 0, sizeof(out));
memset(mat, 0, sizeof(mat));
auto adde = [&](int i, int j) {
++in[j];
++out[i];
++mat[i][i];
sub(mat[i][j], 1);
};
for (int i = 1; i <= n; ++i)
if (s[i] == 'S')
adde(0, i);
else if (s[i] == 'R') adde(i, 0);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (g[i][j] == '1') adde(i, j);
for (int i = 1; i <= n; ++i)
if (in[i] == 0) mat[i][i] = 1;
int ans = det(n);
for (int i = 1; i <= n; ++i) if (in[i]) ans = ans * (ull) fac[in[i] - 1] % P;
cout << ans << '\n';
}
#ifdef ELEGIA
LOG("Time: %dms\n", int ((clock()
-nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 4.16667
Accepted
time: 0ms
memory: 3692kb
input:
2 8 0 SS....RR 00100000 00100000 00011000 00000100 00000100 00000011 00000000 00000000 13 0 SSS.RRRSS.RR. 0001000000000 0001000000000 0001000000000 0000111000000 0000000000000 0000000000000 0000000000000 0000000001000 0000000001000 0000000000110 0000000000000 0000000000000 0000000000000
output:
4 12
result:
ok 2 lines
Test #2:
score: 4.16667
Accepted
time: 0ms
memory: 3672kb
input:
2 5 1 SS.RR 00101 00100 10010 00000 00000 6 2 S....R 001000 000100 010001 000010 001000 000000
output:
3 1
result:
ok 2 lines
Test #3:
score: 4.16667
Accepted
time: 0ms
memory: 3732kb
input:
5 3 2 RS. 010 101 100 4 2 .R.S 0100 0010 1000 0100 4 2 .SR. 0000 0011 0100 0010 5 2 .SSRR 01000 10101 01010 00000 00000 6 2 SS..RR 001010 000010 000010 000010 100101 000000
output:
2 1 2 6 24
result:
ok 5 lines
Test #4:
score: 4.16667
Accepted
time: 0ms
memory: 3736kb
input:
20 6 2 SS..RR 000001 001010 000110 000010 010001 001000 6 1 .SS.RR 000000 000010 000011 000000 000001 001000 6 0 .SR.SR 000000 001000 000000 000000 000001 000000 6 2 SS..RR 011100 000110 000010 100001 100000 000000 6 1 SS.RR. 000110 001000 100000 000000 000000 000000 6 0 .SS.RR 000000 001000 0...
output:
24 5 1 24 2 4 12 6 2 14 8 2 8 10 1 6 5 2 46 12
result:
ok 20 lines
Test #5:
score: 4.16667
Accepted
time: 0ms
memory: 3676kb
input:
20 6 2 .SSR.R 000100 001000 000111 001000 000001 100000 6 1 .S.SRR 010000 000110 000000 100010 000001 000000 6 0 S.RSR. 010000 001000 000000 000010 000000 000000 6 2 ..SSRR 000000 000010 000100 010011 000001 000100 6 1 S.SR.R 010000 000110 000100 010000 000001 000000 6 0 SRS.R. 010000 000000 0...
output:
16 6 1 16 3 1 52 3 1 48 8 1 28 12 2 50 3 2 26 66
result:
ok 20 lines
Test #6:
score: 4.16667
Accepted
time: 1ms
memory: 3756kb
input:
20 100 0 SSSS..S.S.SR.SSSSSS.SSR..SRS.SS.RSSSSRSSSSSRRRRSRRRRS...R.SRSRRS..S..RRSR...R.RRSRRRRRR.RRR....RRRR. 0000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000 0000100000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
598434032 1327104 576 884736 96 237273118 1536 32 4 27648 8 4608 1536 605079681 41472 6 556485058 3972517 439853547 1
result:
ok 20 lines
Test #7:
score: 4.16667
Accepted
time: 1ms
memory: 3772kb
input:
19 100 0 S.SSSSSSSSSSSSRS.SRSSSSSS.SRSRSSSSSSSR..RSRSSRSSSSRS.SRRRSRSRRSR.RRRRRRRRRRRRS.RRRRSRSRRRRRRSRRRRRRR 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
62130475 55296 48 64 4 27648 55296 573308928 477885230 8 95551488 2 2654208 644491483 4 933474442 7962624 112970109 254803968
result:
ok 19 lines
Test #8:
score: 4.16667
Accepted
time: 0ms
memory: 3768kb
input:
19 100 1 SSSSSRSSSSS.RSSSRSSSSSSSSSSSSSRS.RSSSSSSSSSS.SSRSSRSSSRRRRRRSRRRRRRSSRR.RRRRRRRRRRRRRRRRRR..RRRRRRRR 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0010100000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
689691380 448688154 160 3 1952 30710784 10423296 11776 648576 3 83607552 434872188 126074880 411720392 40 188006400 405930966 85733880 96576
result:
ok 19 lines
Test #9:
score: 4.16667
Accepted
time: 1ms
memory: 3688kb
input:
19 100 1 SSSSSSSSSR.SSSSSSSSRSSSSSRSSSRSSSSSSSRSSSSSSRRSSRSSSRRSSSRRRRRRR.RRRRRRRR.S.RRRRSRRRRRRRRRRRRRRRRRRR 0000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000100000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
90137953 54934394 901518419 178034057 565248 893842573 3 34176 847977096 33696 834388724 204037824 265403599 40 207872 2356128 3984 38 209610728
result:
ok 19 lines
Test #10:
score: 4.16667
Accepted
time: 1ms
memory: 3776kb
input:
20 100 1 SSSS.SSS.SRSSSRSSSSSSS.SSSRRSSSSSSSSSRS.SRSS.S.SSSS.R.SRRSSRSRRR.RRRRRRRRRRRRRRRRRRRRSRRRRR.RRRR..RR 0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000...
output:
503432759 594772364 544942080 36000 302334554 1728 130970091 330786317 570862472 1152 1536 980377003 816 36 741497200 3483648 238016597 2808 1280 534354874
result:
ok 20 lines
Test #11:
score: 4.16667
Accepted
time: 1ms
memory: 3764kb
input:
20 100 1 S.SSS.SSSSRSSSSSS.RS..SSS.SSSRR.SSSRSSSSS.SSS.SR.SRRS.R.RRRRRR..RRRRRSS.RRRRRSRRR...RSRRSSRRRRRRRRRR 0000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
118409422 384 848468894 271953138 80 68832 120 638 44 946471695 46752 489537139 3 276480 68 650455698 2 9953280 16 6
result:
ok 20 lines
Test #12:
score: 4.16667
Accepted
time: 0ms
memory: 3752kb
input:
2 100 1 SSSRSS.SSSSSSSSSSSSSSRSSRSSSSSSSRSSSRSSR.SRRS.SSRSS.RSRRR.SS.RSRRRRRRRSR.RSRRSRRRRRRRRRR.RRRRRRRRRRR 0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000001000000000000000000000000000000...
output:
840967271 265512588
result:
ok 2 lines
Test #13:
score: 4.16667
Accepted
time: 1ms
memory: 3752kb
input:
19 100 2 SSSSSSSSRSSSSSSSSSSSSSSSSRSRSSSSSRSRRSRRSSSSRSSRRSSSRRSSSRRRSRRSRRRSRRSRRSRRRRRRRRRRSRRRRRRRRRRRRRRR 0000000100000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000 0001000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
288382526 586884853 620640127 126 840 50688 577482031 217976832 802287906 218 6 86158509 111559680 3072 18 993526011 3696 808254173 25505280
result:
ok 19 lines
Test #14:
score: 4.16667
Accepted
time: 1ms
memory: 3684kb
input:
18 100 2 S.SSSSSS.SRSSSSSSSSSS.SSS.SS.SSSSS.RSSRRR.SRR.SSR.RR.RSSRRSRRSSRRR.RS.RS.RRRRRRRR.RRRR.RR...RRR..RRR 0000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
697195692 618898048 172800 27157804 55406592 128480256 1631616 1121472 873122334 141419520 920 10 271362863 22176 808300753 55172453 1871424 14
result:
ok 18 lines
Test #15:
score: 4.16667
Accepted
time: 1ms
memory: 3756kb
input:
20 100 2 SSSS.S.SS.SS.SSS.SRSS.R.SSSSSS..SSSS.RRSSSRS..SS...RS.RS.RSRRRRRR.SRRRRR.SRRRRRRR..RR...RSRRRRRRRR.. 0100000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000 0011000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
482364841 46 30301483 886937551 533292954 477411877 14616576 161792 438755707 282222897 1329024 1162656 655637728 152098340 564 186654173 2736 85561990 273888 6768
result:
ok 20 lines
Test #16:
score: 4.16667
Accepted
time: 0ms
memory: 3772kb
input:
19 100 2 SSSSSSSSSSSRSSRSSSSSS.SSSSSSSSSSRSSRR.SSSSSRSSSRRSRRS.SS.RRRRRRRRS.RRSSRRRRRRR.RRSRRRRRRRRRRRRRRRRRR 0000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000 0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
799345293 1963584 47921184 31728 503502938 11 43414557 809484678 1180 23520 746898789 4 60692372 1170 480 620165360 825252916 17808249 604800
result:
ok 19 lines
Test #17:
score: 4.16667
Accepted
time: 1ms
memory: 3772kb
input:
20 100 2 .S...SS.SSSSS.S..S..SSSS.S.SS.S.SSRRSRS.RRSR.SR.R.S....RR.R....RR.RR.RRSR.R.S..RRS..RRR.R....R...R.R 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000010000000000000000000000000000000000000000000000000000000...
output:
469006517 29270016 392037224 20 206208 591411456 4106592 9288 342033913 25524 375795687 42 25837056 619991390 139649673 264130863 328 14 4473792 975901937
result:
ok 20 lines
Test #18:
score: 4.16667
Accepted
time: 1ms
memory: 3760kb
input:
19 100 2 .S.S.SS......SS.S..SS.S.S.SS..S...R.SSR.S.SSS.SSS....R.RRRR.....RR.S.R.RRRRRSR.R.RS....R.RR..RRR.R.R 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000100000000000000000000000000000000000000...
output:
682103332 275071534 109983559 76 542216858 578 271872 233280000 251873280 5568 1376 320175888 118034867 170201088 6 4680 17664 823374152 12
result:
ok 19 lines
Test #19:
score: 4.16667
Accepted
time: 1ms
memory: 3696kb
input:
19 100 2 .SSSSS.S..SSSSSSSSSSS.SSSSSS.SSSRSRRSSSR.SSSSSRRRR.SRR.RS.SR...R.RRRR.RRRRR..RRSRRRSSRRRR.RRRRRRRRRR 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000010000000000000000000000000000000000000000000000000000000...
output:
167077449 103022667 991359642 318642285 385920 94 791047322 3408 809988073 134016 384 129408 20160 752574023 775966050 5200 624375289 85 547938585
result:
ok 19 lines
Test #20:
score: 4.16667
Accepted
time: 1ms
memory: 3736kb
input:
19 100 2 SS..SSSS.S.SRSS.SSSR....SS.SS..SS..SRSSRSSRSS.R.RS...S...RSRS.RR.RRRR.RRRSR.RSR.R..SR.R.RRRR.RR..RRR 0000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000010000000000000000000000000000000000000000000000...
output:
624070116 108 697115986 31078372 30912 9114624 643870277 4640 29520 1008 336780288 785664 896 63698746 130914290 942108125 110351390 402689352 906235839
result:
ok 19 lines
Test #21:
score: 4.16667
Accepted
time: 0ms
memory: 3696kb
input:
19 100 2 S...S..S....S.SSS...SSS.S.RSS..R..SR..SSS...R...S...SSS..R.S.SS.S.R.RRR..R..RRRR.S.RRRRR.R..RRRR..RR 0000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
184450660 732005041 480605689 4096 568512 974032746 117460824 278893961 8 1359360 6965760 227367936 529817832 401344 510698770 20483328 17 1291680 861821825
result:
ok 19 lines
Test #22:
score: 4.16667
Accepted
time: 0ms
memory: 3784kb
input:
2 100 2 SRSSSS.SSSSSSSSSRSSSSSSSSRSSSSSRRSSRSSRSRRRS..RSSSSSRSRSRSSRRSSR.RRRSRRRSRRRR.RRRRRRRSRRRRRRRRR.RRRR 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
968420002 389389747
result:
ok 2 lines
Test #23:
score: 4.16667
Accepted
time: 2ms
memory: 3764kb
input:
2 100 2 SSSSSSSSSSSRSSSSSRSSSSSSSS.SSSSS.SSSSSSSRSSRSRSSSRRRRRRRRR..RRRSRRRR.RRRRRRRSSRRRRR.RSR.RRRRRRR.RRRR 0011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000100000000000000000000000000000000000000000000000...
output:
303488821 183480277
result:
ok 2 lines
Test #24:
score: 4.16667
Accepted
time: 2ms
memory: 3700kb
input:
2 100 2 S.SSSS.SSSSRSSSSSSSSRSSSSSSS.S.RSRSSSRRSSRSS.SSR.RRRRSRRSS.SRRSSRS.RRRRRS.RRRRRR.RR.RRR.R.RRRRRRRRR. 0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
709758665 79666468
result:
ok 2 lines