QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291082 | #4222. 题 | MoRanSky | 100 ✓ | 407ms | 409116kb | C++23 | 2.8kb | 2023-12-26 04:47:00 | 2023-12-26 04:47:01 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int N = 20, P = 1e9 + 7;
int n, F[N][N][N][N][N][N], G[N][N][N][N][N][N];
// (1, 3, 2) - (2, 1, 3) - (3, 2, 1)
char s[N * 3];
void inline add(int &x, int y) {
x += y;
if (x >= P) x -= P;
}
void inline cp() {
for (int a = 0; a <= n; a++)
for (int b = 0; b + a <= n; b++)
for (int c = 0; c + b + a <= n; c++)
for (int d = 0; d + c + b + a <= n; d++)
for (int e = 0; e + d + c + b + a <= n; e++)
for (int f = 0; f + e + d + c + b + a <= n; f++) {
G[a][b][c][d][e][f] = F[a][b][c][d][e][f];
F[a][b][c][d][e][f] = 0;
}
}
int main() {
int T; read(T);
while (T--) {
memset(F, 0, sizeof F);
read(n); scanf("%s", s + 1);
F[0][0][0][0][0][0] = 1;
for (int i = 1; i <= 3 * n; i++) {
cp();
for (int a = 0; a <= n; a++) {
for (int b = 0; b + a <= n; b++) {
for (int c = 0; c + b + a <= n; c++) {
for (int d = 0; d + c + b + a <= n; d++) {
for (int e = 0; e + d + c + b + a <= n; e++) {
for (int f = 0; f + e + d + c + b + a <= n; f++) {
if (!G[a][b][c][d][e][f]) continue;
int w = G[a][b][c][d][e][f], t = f + e + d + c + b + a;
if (s[i] == '0' || s[i] == '1') {
if (t < n) add(F[a + 1][b][c][d][e][f], w);
if (c) add(F[a][b][c - 1][d + 1][e][f], 1ll * w * c % P);
if (f) add(F[a][b][c][d][e][f - 1], 1ll * w * f % P);
}
if (s[i] == '0' || s[i] == '2') {
if (t < n) add(F[a][b][c + 1][d][e][f], w);
if (b) add(F[a][b - 1][c][d][e][f], 1ll * w * b % P);
if (e) add(F[a][b][c][d][e - 1][f + 1], 1ll * w * e % P);
}
if (s[i] == '0' || s[i] == '3') {
if (t < n) add(F[a][b][c][d][e + 1][f], w);
if (a) add(F[a - 1][b + 1][c][d][e][f], 1ll * w * a % P);
if (d) add(F[a][b][c][d - 1][e][f], 1ll * w * d % P);
}
}
}
}
}
}
}
}
int o = F[0][0][0][0][0][0];
for (int i = 2; i <= n; i++) o = 1ll * o * i % P;
printf("%d\n", o);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 101ms
memory: 259604kb
input:
5 1 123 1 100 1 000 1 300 1 010
output:
0 1 3 1 1
result:
ok 5 lines
Test #2:
score: 10
Accepted
time: 79ms
memory: 258192kb
input:
5 1 303 2 000320 2 002000 2 002020 2 020020
output:
0 36 60 12 12
result:
ok 5 lines
Test #3:
score: 10
Accepted
time: 80ms
memory: 262704kb
input:
5 2 110133 3 200010000 3 002002200 3 300000000 3 000000130
output:
0 5940 540 15120 7560
result:
ok 5 lines
Test #4:
score: 10
Accepted
time: 84ms
memory: 272416kb
input:
5 5 000000000000000 4 000000000000 3 000000000 2 000000 1 000
output:
864823720 29937600 45360 180 3
result:
ok 5 lines
Test #5:
score: 10
Accepted
time: 89ms
memory: 284496kb
input:
5 6 000121310223223210 7 033221120002010100230 7 000003020000010302010 7 000010002020302300100 7 030100002033300000000
output:
26853120 152413083 939384999 4309685 970165754
result:
ok 5 lines
Test #6:
score: 10
Accepted
time: 92ms
memory: 311008kb
input:
5 9 120332011311030220200103301 10 200003200103011232000202201120 10 000000201330030030101000003000 10 020000002032000000200000100002 10 100200322001000000320000002010
output:
963757075 290911546 487693965 730680478 984422198
result:
ok 5 lines
Test #7:
score: 10
Accepted
time: 114ms
memory: 339104kb
input:
5 13 000000000000000000000000000000000000000 12 000000000000000000000000000000000000 11 000000000000000000000000000000000 10 000000000000000000000000000000 9 000000000000000000000000000
output:
856865849 574346463 607449787 883895867 88660419
result:
ok 5 lines
Test #8:
score: 10
Accepted
time: 206ms
memory: 374036kb
input:
5 15 331110203302222220331213331310312220103030021 16 001301022200100032010330002213000300220033210033 16 020002030002000330003200030010000000000100002300 16 320000001003222000003000003000300010323113200020 16 000203000000000000010100000000000000002000210000
output:
70336694 482512438 740138646 212387388 427674884
result:
ok 5 lines
Test #9:
score: 10
Accepted
time: 331ms
memory: 398764kb
input:
5 17 221001103220113003322101120223031133120301212031002 18 201000020000000010323100000333030002012000213100030001 18 013203020100001021200030003102000130000002330303302120 18 010003030200000200100000002000000000000302000203103300 18 000001000132020000200321023010000000000000000132210300
output:
821788453 589132243 303959134 648206569 571580782
result:
ok 5 lines
Test #10:
score: 10
Accepted
time: 407ms
memory: 409116kb
input:
5 18 331110100201233220121012022130200011112133012123201012 19 221011310310012302220013020123002132313030023020101110230 19 202000300003001300011000011021320001000300320020302022103 19 010030200000000000300300310000001302002000010230000330020 19 000000000000031000000000131200020001000020000001020000...
output:
171958822 242716134 229925968 914555153 59496792
result:
ok 5 lines
Extra Test:
score: 0
Extra Test Passed