UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200043#2632. AllocationAnonyme1004139ms2204kbC++112.6kb2023-12-26 10:28:462023-12-26 12:03:31

answer

#include<bits/stdc++.h>
using namespace std;

#define QwQ330AwA return 0
#define ll long long

const int mod = 998244353;
const int N = 100005;
const int M = 330;
int f[2][M];
int to[M][2];
int mask[8];
bool vis[22][1 << 21], g[22][1 << 21];
bool tmp[22];
struct Node {
	int s;
	int len;
} pos[M];
int cnt;

bool dfs(int len, int s) {
	if (len == 1) return s;
	if (vis[len][s]) return g[len][s];
	vis[len][s] = 1;
	for (int i = 0; i <= len - 3; i++) {
		int w = (mask[(s >> i) & 7] << i) | (s & ((1 << i) - 1)) | ((s >> (i + 3)) << (i + 1));
		if (dfs(len - 2, w)) return g[len][s] = 1;
	}
	return g[len][s] = 0;
}

bool check(Node u, Node v) {
	int su = u.s, lenu = u.len;
	int sv = v.s, lenv = v.len;
	if (lenu % 2 != lenv % 2) return 0;
	for (int i = 0; i <= max(lenu, lenv) + 10; i++) {
		if (!tmp[i]) {
			tmp[i] = 1;
			for (int s = 0; s < (1 << i); s++) vis[i][s] = 0;
		}
	}
	for (int i = (lenu & 1) ^ 1; i <= 10; i += 2) {
		for (int s = 0; s < (1 << i); s++) {
			if (dfs(lenu + i, su | (s << lenu)) != dfs(lenv + i, sv | (s <<lenv))) return 0;
		}
	}
	return 1;
}

void build() {
	memset(tmp, 0, sizeof(tmp));
	queue <int> q;
	cnt = 0;
	pos[++cnt] = {0, 0};
	q.push(1);
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		int flag = 0;
		Node nw = {pos[u].s, pos[u].len + 1};
		for (int i = 1; i <= cnt; i++) {
			if (check(nw, pos[i])) {
				to[u][0] = i;
				flag = 1;
				break;
			}
		}
		if (!flag) {
			cnt++;
			pos[cnt] = nw;
			to[u][0] = cnt;
			q.push(cnt);
		}
		flag = 0;
		nw = {pos[u].s | (1 << pos[u].len), pos[u].len + 1};
		for (int i = 1; i <= cnt; i++) {
			if (check(nw, pos[i])) {
				to[u][1] = i;
				flag = 1;
				break;
			}
		}
		if (!flag) {
			cnt++;
			pos[cnt] = nw;
			to[u][1] = cnt;
			q.push(cnt);
		}
	}
}

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

void solve() {
	string s;
	cin >> s;
	for (int i = 0; i < 8; i++) mask[i] = s[i] - '0';
	string t;
	cin >> t;
	int n = t.length();
	build();
//	cout << cnt << '\n';
	memset(f[0], 0, sizeof(f[0]));
	f[0][1] = 1;
	for (int i = 0; i < n; i++) {
		int op = i & 1;
		for (int j = 1; j <= cnt; j++) f[op ^ 1][j] = 0;
		for (int j = 1; j <= cnt; j++) {
			if (t[i] != '0') add(f[op ^ 1][to[j][1]], f[op][j]);
			if (t[i] != '1') add(f[op ^ 1][to[j][0]], f[op][j]);
		}
	}
	int op = n & 1;
	int ans = 0;
	for (int i = 1; i <= cnt; i++) {
		if (pos[i].len % 2 == 1 && dfs(pos[i].len, pos[i].s)) add(ans, f[op][i]);
	}
	cout << ans << '\n';
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	QwQ330AwA;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 4
Accepted
time: 153ms
memory: 2068kb

input:

512
11111001 0001110101111101001
00011111 1101111111001100110
00010100 0000000000000001000
11101010 ...

output:

1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
...

result:

ok 512 numbers

Test #2:

score: 4
Accepted
time: 166ms
memory: 2068kb

input:

512
10010010 11010010101000101010010001111
11111011 10010011100000011011101101010
01001000 011011101...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 512 numbers

Test #3:

score: 4
Accepted
time: 156ms
memory: 2072kb

input:

512
00110000 0111000111010101111000001101001010010011101101000
10000111 0000000000000000000000100000...

output:

1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
0
0
1
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1
1
0
1
...

result:

ok 512 numbers

Test #4:

score: 4
Accepted
time: 154ms
memory: 2068kb

input:

512
10110100 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1
1
1
0
1
0
0
1
0
1
0
1
1
1
1
1
1
1
1
0
1
1
1
0
0
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
...

result:

ok 512 numbers

Test #5:

score: 4
Accepted
time: 156ms
memory: 2072kb

input:

512
00101111 011111100001100011010010010010110000011010001000110011111000110001011110001001101111111...

output:

1
0
1
1
1
0
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
...

result:

ok 512 numbers

Test #6:

score: 4
Accepted
time: 158ms
memory: 2068kb

input:

512
01010101 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
0
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
...

result:

ok 512 numbers

Test #7:

score: 4
Accepted
time: 160ms
memory: 2072kb

input:

512
10000101 101111010010000100100100001110001000010010000111011010111011000100100111111111100101010...

output:

1
1
1
1
0
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 512 numbers

Test #8:

score: 4
Accepted
time: 157ms
memory: 2080kb

input:

512
10111000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1
1
1
1
1
0
1
1
0
0
1
1
1
1
1
1
1
0
0
1
1
1
1
1
0
0
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
...

result:

ok 512 numbers

Test #9:

score: 4
Accepted
time: 156ms
memory: 2072kb

input:

512
10111000 000000000?000000000000000000000000000000000000000?0000000000000000000000000000000000000...

output:

4
32
32
4
2
0
64
64
2
512
128
128
1024
256
4
256
256
3
1024
8
1
4
32
128
220
1024
8
1
256
7
240
0
10...

result:

ok 512 numbers

Test #10:

score: 4
Accepted
time: 151ms
memory: 2072kb

input:

512
11010101 101101001101011111011011010100111001101111010101100?11?1000001101001?111001100101001101...

output:

256
32
128
15
7
4
512
0
1
4
0
4
16
509
512
2
8
1
8
1023
4
64
512
64
64
1
1024
1024
0
512
256
8
32
51...

result:

ok 512 numbers

Test #11:

score: 4
Accepted
time: 155ms
memory: 2068kb

input:

512
10101001 00000?0000000000000000000000000?0000000000000000000000000000000000000000000000000000000...

output:

16
2
512
16
256
128
16
128
128
1024
512
32
1024
512
0
64
256
16
16
128
0
256
8
64
0
8
256
0
1024
32
...

result:

ok 512 numbers

Test #12:

score: 4
Accepted
time: 160ms
memory: 2068kb

input:

512
10101011 101110100001110011011111101001000011111010111111110001101111111110101010010011100111011...

output:

2
64
1024
1
64
8
512
8
0
880
64
64
64
0
16
1024
2
64
1
512
32
4
31
512
4
16
2
4
1024
1024
8
32
1
400...

result:

ok 512 numbers

Test #13:

score: 4
Accepted
time: 163ms
memory: 2084kb

input:

512
00010101 111111101000101101100111100001010111000001101010011000000010000001110000010100000011111...

output:

1024
256
128
56
31
256
64
512
0
2
1
8
256
1
128
32
15
16
1024
1024
1
64
8
0
1024
0
0
512
0
128
4
512...

result:

ok 512 numbers

Test #14:

score: 4
Accepted
time: 168ms
memory: 1424kb

input:

512
00010111 11100?010111??0101?1?10?0???0??1111000001?01?0010??110000100?0????10?0101010????0???1?0...

output:

901519461
599324484
218439087
608341720
430646583
943023373
500292333
650970907
436878174
749268343
...

result:

ok 512 numbers

Test #15:

score: 4
Accepted
time: 182ms
memory: 1396kb

input:

512
01010101 10??00?0?100??100?0??1?1???10101?0?0????00001??1?00110011110?1?1001?0?01111?0??000001?0...

output:

194536473
873756348
76042715
668008760
608341720
0
0
167002190
167002190
0
4680626
436878174
3041708...

result:

ok 512 numbers

Test #16:

score: 4
Accepted
time: 252ms
memory: 1420kb

input:

512
00000101 100101??10?11??0?11?1001?000?11??0?101??1???01?10?1?1?10?1??10?0110???011?????00?0?110?...

output:

0
0
0
4680626
0
436878174
500292333
0
135218181
0
0
2340313
167002190
0
218439087
0
0
537143534
8350...

result:

ok 512 numbers

Test #17:

score: 4
Accepted
time: 165ms
memory: 1540kb

input:

512
00010111 0?0?00??00?00?000??000?0?0000?0??00?000?0000000000?00?00?000000?00??0??0?00000000?00000...

output:

905382510
114902782
308337054
466025955
479109895
966153695
861597630
398106623
682155965
114902782
...

result:

ok 512 numbers

Test #18:

score: 4
Accepted
time: 188ms
memory: 1512kb

input:

512
01010101 ?0???1011???10100?10??11?1111??0??101??00?1010?10?1??1?111??1001?0?110111?010??00?10111...

output:

44177446
0
732135154
459611128
0
134499103
366067577
932051910
459611128
0
134499103
459611128
0
537...

result:

ok 512 numbers

Test #19:

score: 4
Accepted
time: 159ms
memory: 2204kb

input:

512
00110111 1?11???11?1?111?1?1??1111111?11?11?11?1??1?1??11?1111??1111??11111???1?1?1?11111111111?...

output:

406227041
0
682155965
114902782
732135154
449601726
459611128
840200159
366067577
229805564
11490278...

result:

ok 512 numbers

Test #20:

score: 4
Accepted
time: 165ms
memory: 2200kb

input:

512
11100100 ???????????????????????????????????????????????????????????????????????????????????????...

output:

454432056
229805564
840200159
865859467
356245718
639120290
366067577
919222256
682155965
919222256
...

result:

ok 512 numbers

Test #21:

score: 4
Accepted
time: 164ms
memory: 2204kb

input:

512
01100101 0000?000000?0?0000?0?0000?0000000?000??00???00??0000000000??0000000000000?0000000?000?0...

output:

812454079
919222256
705867665
732135154
865859467
566371728
919222256
283185864
840200159
366067577
...

result:

ok 512 numbers

Test #22:

score: 4
Accepted
time: 158ms
memory: 2200kb

input:

512
00010111 ??0?0?0????1?0??01????00000???00100?00??00?10?0????110?0100000001?0?1??0?100?1110101?10...

output:

406227041
459611128
732135154
865859467
932051910
70796466
466025955
566371717
114902782
932051910
8...

result:

ok 512 numbers

Test #23:

score: 4
Accepted
time: 164ms
memory: 2204kb

input:

512
01000101 000111??110110??01?0?01?011110111?010001??1?1001?1?00?001?010?10?001??01100?1??1?001111...

output:

0
919222256
229805564
932051910
229805564
70796466
459611128
466025955
77748468
537996412
732135154
...

result:

ok 512 numbers

Test #24:

score: 4
Accepted
time: 164ms
memory: 2204kb

input:

512
10101000 0?10??1011?1??10??1?00?10?111??10101110?00??10000000101?00?10?10?0?0?1111?00?1001?1?110...

output:

176709784
0
932051910
366067577
932051910
70796466
0
35398233
732135154
932051910
919222256
22980556...

result:

ok 512 numbers

Test #25:

score: 4
Accepted
time: 165ms
memory: 2204kb

input:

512
00101110 00?001110?101?0??10110?1111?11?00?111111??0??00?000???01?100001100?1011?00?11010?100?11...

output:

255083269
682155965
141592932
932051910
732135154
0
114902782
537996348
466025882
680393705
84020015...

result:

ok 512 numbers

Extra Test:

score: 0
Extra Test Passed