QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687872#9463. 基础 ABC 练习题kkkgjyismine467.5 221ms10472kbC++201.9kb2024-10-29 21:40:042024-10-29 21:40:05

Judging History

你现在查看的是最新测评结果

  • [2024-10-29 21:40:05]
  • 评测
  • 测评结果:67.5
  • 用时:221ms
  • 内存:10472kb
  • [2024-10-29 21:40:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 65
#define u32 unsigned int
int n;
u32 f[N*3][N][N][2][2];
char t[N],s1[N],s2[N];
void solve(){
	scanf("%d%s%s%s",&n,s1,s2,t+1);
	if(n>30){puts("-1");return;}
	u32 ret=0;
	for(int x=0;x<=n;++x)
		for(int y=0;x+y<=n;++y){
			int z=n+1;
			for(int i=x;i<=n;++i)
				for(int j=y;i+j<=n;++j)
					if(s1[i]=='1'&&s2[j]=='1')z=min(z,i+j);
			if(z>n)continue;z=n-z;
			for(int i=0;i<=n*3;++i)
				for(int j=0,l,r;j<=min(n,i);++j){
					l=max(0,(i-j-z+1)/2),r=min(min(n,i),min(x+i-2*j,min(y+j,i-j)));
					for(int k=l;k<=r;++k)f[i][j][k][0][0]=f[i][j][k][0][1]=f[i][j][k][1][0]=f[i][j][k][1][1]=0;
				}
			int o=(!x),o1=(!y);
			f[0][0][0][o][o1]=1;
			for(int i=0;i<n*3;++i)
				for(int j=0,l,r;j<=min(n,i);++j){
					l=max(max(0,i-j-n),(i-j-z+1)/2),r=min(min(n,i),min(x+i-2*j,min(y+j,i-j)));
					if(t[i+1]=='?'){
						for(int k=l,m=i-j-k,o1,o2;k<=r;++k,--m){
							for(int a=0;a<2;++a)
								for(int b=0;b<2;++b){
									f[i+1][j+1][k][a|(j+1-m==x)][b]+=f[i][j][k][a][b];
									f[i+1][j][k+1][a][b|(k-j+1==y)]+=f[i][j][k][a][b];
									f[i+1][j][k][a][b]+=f[i][j][k][a][b];
								}
						}
					}else if(t[i+1]=='A'){
						for(int k=l,m=i-j-k,o1,o2;k<=r;++k,--m){
							for(int a=0;a<2;++a)
								for(int b=0;b<2;++b){
									f[i+1][j+1][k][a|(j+1-m==x)][b]+=f[i][j][k][a][b];
								}
						}
					}else if(t[i+1]=='B'){
						for(int k=l,m=i-j-k,o1,o2;k<=r;++k,--m){
							for(int a=0;a<2;++a)
								for(int b=0;b<2;++b){
									f[i+1][j][k+1][a][b|(k-j+1==y)]+=f[i][j][k][a][b];
								}
						}
					}else{
						for(int k=l,m=i-j-k,o1,o2;k<=r;++k,--m){
							for(int a=0;a<2;++a)
								for(int b=0;b<2;++b){
									f[i+1][j][k][a][b]+=f[i][j][k][a][b];
								}
						}
					}
				}
			ret+=f[n*3][n][n][1][1];
	}
	cout<<ret<<endl;
}
int main() {
	int t,ss;cin>>t>>ss;
	while(t--)solve();
    return 0;
}

详细

Subtask #1:

score: 13.5
Acceptable Answer

Test #1:

score: 13.5
Acceptable Answer
time: 112ms
memory: 10316kb

input:

60 1
1
11
11
ABC
2
111
111
CABABC
3
1111
1111
CAABBCBAC
4
11111
11111
BACBBACBACAC
5
111111
111111
CABCCBBAABCCBAA
6
1111111
1111111
ABABABCACBCBCCACBA
7
11111111
11111111
BCAABACBBCBBABCCAACAC
8
111111111
111111111
CCBCBBBCAABCBCAAAAACBCBA
9
1111111111
1111111111
CCCCACABCBABAABCCAABABBCBBA
10
1111...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #2:

score: 13.5
Acceptable Answer
time: 110ms
memory: 10264kb

input:

60 1
1
11
11
CBA
2
111
111
BACACB
3
1111
1111
BCBCACABA
4
11111
11111
CCBACABBBCAA
5
111111
111111
BCACBBABBCCAACA
6
1111111
1111111
BBCBACCAACBCBCAABA
7
11111111
11111111
ACBCCBBAABAABCACCACBB
8
111111111
111111111
BAACACBACCCBAACCBABABBCB
9
1111111111
1111111111
BABCBCAAAAABBCCCACBCBBABACC
10
1111...

output:

0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #3:

score: 13.5
Acceptable Answer
time: 114ms
memory: 9960kb

input:

60 1
1
11
11
BCA
2
111
111
BCABCA
3
1111
1111
CBACCAABB
4
11111
11111
BACBCBBCCAAA
5
111111
111111
BCCCBABACCBABAA
6
1111111
1111111
ACAACBABABBCACBCCB
7
11111111
11111111
BBBCABCCCAABCACBACAAB
8
111111111
111111111
ACCACAABACBAABBCBCBBACBC
9
1111111111
1111111111
BCCBACBBACCCBCCAABAACABAABB
10
1111...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #4:

score: 13.5
Acceptable Answer
time: 109ms
memory: 9804kb

input:

60 1
1
11
11
BCA
2
111
111
ACABCB
3
1111
1111
BABCABCCA
4
11111
11111
CCABACABBACB
5
111111
111111
ABBBCBBCACCAACA
6
1111111
1111111
CACBABCABCCBABAACB
7
11111111
11111111
BACBCABACBBCCCBAAACAB
8
111111111
111111111
CABABBCAACABCBACBABACBCC
9
1111111111
1111111111
BCBAACBABABCBACBABABCCACACC
10
1111...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #5:

score: 13.5
Acceptable Answer
time: 109ms
memory: 10196kb

input:

60 1
1
11
11
ABC
2
111
111
BBCACA
3
1111
1111
ACBBCBAAC
4
11111
11111
ABACACCCABBB
5
111111
111111
ACCCCCAAABABBBB
6
1111111
1111111
ABAABBBBCCCCCCAABA
7
11111111
11111111
ACBBBACCCCCCAABABBBAA
8
111111111
111111111
CAAABAAACCCCBBCBBBCACBAB
9
1111111111
1111111111
ABAAACBBCCCCCCCBAAABAACBBBB
10
1111...

output:

1
1
0
0
0
1
1
0
1
1
1
1
1
0
1
1
1
0
0
0
0
1
1
1
0
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #6:

score: 13.5
Acceptable Answer
time: 109ms
memory: 10016kb

input:

60 1
1
11
11
BCA
2
111
111
ACCBAB
3
1111
1111
BACCACBBA
4
11111
11111
AAABBCBCBACC
5
111111
111111
AABBBBCCBCCAACA
6
1111111
1111111
AAACCBCCCAABACBBBB
7
11111111
11111111
AAACACCACBBAABBCBCCBB
8
111111111
111111111
AAACAAABBBBBBBCBACCCACCC
9
1111111111
1111111111
BBCCACCCACCACCBAABBAAAABBBB
10
1111...

output:

1
0
0
1
1
0
1
1
1
1
1
0
0
0
1
1
1
0
0
1
0
1
1
1
1
1
1
0
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #7:

score: 13.5
Acceptable Answer
time: 108ms
memory: 10132kb

input:

60 1
1
11
11
BCA
2
111
111
ACCABB
3
1111
1111
CAABBBCAC
4
11111
11111
BBCCBCCABAAA
5
111111
111111
BAABBBCCCCCAABA
6
1111111
1111111
AACACCCCBABBBCAABB
7
11111111
11111111
AACBBCBBBCCCCCAAABBAA
8
111111111
111111111
AAAABBCBBBBCBBCCCCCCAAAA
9
1111111111
1111111111
ABBBBBBBBCCBCAACCACAACCAAAC
10
1111...

output:

1
0
1
1
1
0
1
1
1
1
0
1
1
0
1
1
0
0
1
0
1
1
0
1
1
0
0
0
0
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #8:

score: 13.5
Acceptable Answer
time: 108ms
memory: 10376kb

input:

60 1
1
11
11
ABC
2
111
111
AABCBC
3
1111
1111
ABAACBBCC
4
11111
11111
AABCCBBBCACA
5
111111
111111
AAACCABBBACBCCB
6
1111111
1111111
AABBBBBBCCACAACACC
7
11111111
11111111
AAAABBBBBBCCACCCCCBAA
8
111111111
111111111
ACCBABBABBBBBCCCACCCAAAA
9
1111111111
1111111111
BAAAABCCCCCCCBBAABAACABCBBB
10
1111...

output:

1
1
1
0
1
1
1
1
0
1
0
1
1
1
0
1
1
1
0
0
0
0
1
0
1
0
0
1
1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #9:

score: 13.5
Acceptable Answer
time: 105ms
memory: 9820kb

input:

60 1
1
11
11
CAB
2
111
111
CCAABB
3
1111
1111
ACCCABBAB
4
11111
11111
AAABBBBCCACC
5
111111
111111
BCACCCCBAAAABBB
6
1111111
1111111
CAAACABABACCCBCBBB
7
11111111
11111111
ACAAACBCCCCBCAABBABBB
8
111111111
111111111
ACCAACACCCCCABABAABBBBBB
9
1111111111
1111111111
AACAAAAAACBCCBCBACBBBBBBCCC
10
1111...

output:

1
1
0
1
1
0
0
0
0
1
1
0
0
1
1
0
1
1
1
1
0
0
1
0
1
1
0
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #10:

score: 13.5
Acceptable Answer
time: 108ms
memory: 10368kb

input:

60 1
1
11
11
BCA
2
111
111
ACACBB
3
1111
1111
AABCCCABB
4
11111
11111
CBCCCABABABA
5
111111
111111
ACACCCAABBCBABB
6
1111111
1111111
BACAAAACCBABCBCBCB
7
11111111
11111111
AAAAABBBBCCBBCCCCACAB
8
111111111
111111111
AACCCCCCABAAACAABCBBBBBB
9
1111111111
1111111111
AABAAAABCCCCABCCCABBCCABBBB
10
1111...

output:

1
0
0
1
1
0
1
1
0
1
0
0
0
0
1
0
1
0
1
1
0
1
1
0
1
1
0
1
1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #11:

score: 13.5
Acceptable Answer
time: 109ms
memory: 10416kb

input:

60 1
1
11
11
BCA
2
111
111
CBBCAA
3
1111
1111
AABABCCCB
4
11111
11111
BABCBBCAAACC
5
111111
111111
AAACBBBBBCAACCC
6
1111111
1111111
BBBBBCCCCCCAABAAAA
7
11111111
11111111
BAAAABAACCCABBCCBBBCC
8
111111111
111111111
ABABBBBBCBCCCACCCCAAABAA
9
1111111111
1111111111
AAAABBAABCABACCCACCCBBCBCBB
10
1111...

output:

1
0
0
0
0
1
0
1
0
0
1
0
1
0
1
1
1
0
1
0
0
0
1
1
1
1
0
1
1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Subtask #2:

score: 13.5
Acceptable Answer

Dependency #1:

67.5%
Acceptable Answer

Test #12:

score: 13.5
Acceptable Answer
time: 93ms
memory: 10080kb

input:

60 2
1
01
11
ABC
2
101
001
ACBABC
3
0011
1000
AAACBBCBC
4
11100
00100
BACABCABACBC
5
001101
110010
ACBABCCABBCCAAB
6
0101010
1000011
CABBAAACACBBCCABCB
7
10010111
10100111
CABAAACBBAACBCACBBBCC
8
100101000
100000110
BACBCACBBAABCCCABCBAACBA
9
1100010100
0111110011
CAABCBBABCACBCACABCABAACBBC
10
0001...

output:

1
0
0
1
1
0
1
0
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #13:

score: 13.5
Acceptable Answer
time: 96ms
memory: 10472kb

input:

60 2
1
01
01
CAB
2
011
101
ABCCBA
3
1111
0000
CBBAACCBA
4
00011
10011
BCCBCCABABAA
5
011111
111011
ACBBABCBCCAACBA
6
1011101
1101000
CBABBCACBAABABCACC
7
00001111
11010100
BCACAABCBBBCCABABCACA
8
110110100
010010100
ABAABCABCABAACCCCBBBBCCA
9
0000111111
1011100011
BAAABBCCABBBBCABACBACACCACC
10
0011...

output:

0
0
0
0
1
1
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #14:

score: 13.5
Acceptable Answer
time: 94ms
memory: 10316kb

input:

60 2
1
01
00
ABC
2
111
000
CAABBC
3
0101
0011
CAACBCBAB
4
11011
01001
CABBCAACBBCA
5
000010
010100
BCCCACAAACBBBBA
6
0011011
0011000
BCACCBAAAAABCBCBBC
7
11000001
11111111
AACBCABACCBBCABCCBAAB
8
111010100
111101010
CBABCACBABAACBABCCCBCAAB
9
1001111111
1011000111
CAABCACCABBBABBCACCABBCAACB
10
0011...

output:

0
0
0
1
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #15:

score: 13.5
Acceptable Answer
time: 92ms
memory: 9916kb

input:

60 2
1
00
10
BCA
2
110
000
BCAABC
3
0111
1001
CACAABBBC
4
10101
00000
ACCBCAABBACB
5
010001
100001
BBCBBAACCBACACA
6
0100101
0100010
CCAAAABCCAABBCBBBC
7
10010000
10010011
BCBCACBCBAAAABCABBCCA
8
001101111
110010111
CABACABCACBBABCBCABACABC
9
1000111100
1011101001
ACBCABABBCCBABCCAAACBBBACAC
10
1111...

output:

0
0
1
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #16:

score: 13.5
Acceptable Answer
time: 25ms
memory: 9948kb

input:

60 2
1
10
11
CAB
2
110
100
AABBCC
3
0100
0110
CAABCBABC
4
01010
01000
BCBCABACBCAA
5
001110
100000
AAABBCCCABCBABC
6
1000000
1101100
ACCBACBCAABCAABBCB
7
11011110
01000000
AAAAABABBBCBBBACCCCCC
8
101000000
010000000
ACBABBCCCCCCCABAAABAABBB
9
1000000000
1000000000
CCCCCCCCCAABAAABABBBABBAABB
10
0111...

output:

1
0
1
0
1
0
1
1
1
1
1
1
1
1
0
0
1
0
1
1
1
1
1
0
1
1
1
0
0
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #17:

score: 13.5
Acceptable Answer
time: 16ms
memory: 10396kb

input:

60 2
1
01
10
ABC
2
100
100
BCABCA
3
1000
1100
CABACCBAB
4
11001
10000
AABCBACABBCC
5
110000
101110
BACBCAABCABCBCA
6
1110000
1111100
AABBBBCABCCCCABAAC
7
10110000
11100000
AAACCABBCAABCBBABBCCC
8
001111100
011000000
ABAACAAAACABCBCBBBBBCCCC
9
0110000000
1111000000
AACBBACBBBCBCABACACBCAABCCA
10
1111...

output:

1
0
0
1
1
1
1
1
1
0
0
1
1
1
1
1
1
1
0
1
0
0
0
1
1
1
1
1
0
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #18:

score: 13.5
Acceptable Answer
time: 11ms
memory: 9876kb

input:

60 2
1
10
11
ABC
2
100
100
CABCAB
3
1000
1000
CCABCABAB
4
11100
10000
ACACBABCABCB
5
111101
100000
AABCABCBACABBCC
6
1000000
0100000
BCACCCCCABAAABBBBA
7
10101110
11000000
AAABBCBBCACCCABBAACBC
8
111110000
001100000
ACBBCBBCABACCACBBABAACCA
9
1110000000
1111110000
CAAACBCCBBAAABCCBACABACCBBB
10
1100...

output:

0
1
1
1
1
1
1
1
1
0
0
1
1
0
1
0
0
1
0
1
0
0
0
1
1
0
1
1
0
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #19:

score: 13.5
Acceptable Answer
time: 18ms
memory: 10020kb

input:

60 2
1
11
10
ABC
2
100
110
BCABCA
3
1000
1111
BBCBACCAA
4
10000
10011
BCABCABCABCA
5
011111
100000
AABCBCABACABCBC
6
1110000
1000000
CAAACCCBBBCAACABBB
7
10000000
01000000
ABBCACCCABBACABACBBAC
8
110100011
100000000
AABBCABCCAABBCABCABCABCC
9
1111011100
1100000000
AAACABBBBBCACABCCBABCACBCCA
10
0111...

output:

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
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #20:

score: 13.5
Acceptable Answer
time: 16ms
memory: 9868kb

input:

60 2
1
10
10
CAB
2
110
100
ABCACB
3
1000
1000
CABCABCAB
4
10111
10000
CABCABCABCAB
5
100000
110000
BCCAABCBCABACAB
6
1000000
1111000
CCCABACAABBCABCABB
7
10000000
11000110
BBCBBBCCACCCBABAAACAA
8
110000000
100000000
AACBCABCABBACCABCBCAABBC
9
1000000000
1100000000
BBCCACACCCBBACBCCABABAAAABB
10
1111...

output:

1
1
1
1
1
1
1
0
0
1
1
0
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #21:

score: 13.5
Acceptable Answer
time: 13ms
memory: 10012kb

input:

60 2
1
10
10
CAB
2
110
100
CABCAB
3
0111
1000
CABCABCAB
4
11010
11000
AAABBBCBACCC
5
110000
100000
ACBACABCBABCABC
6
1111000
1111000
AAABBBBBCACCCAABCC
7
11011100
01000000
AAAAACCBCBCBBBCACACBB
8
111000000
111010000
AAABBBBBCCCCCCCABACABABA
9
1011100010
1000000000
AAABAABAABBABBCCCCBCCCCBACB
10
1111...

output:

1
1
1
1
1
1
0
0
1
0
1
0
1
1
1
1
0
1
1
1
0
0
1
1
1
1
0
0
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Subtask #3:

score: 6.75
Acceptable Answer

Test #22:

score: 6.75
Acceptable Answer
time: 221ms
memory: 9940kb

input:

60 3
1
11
11
???
2
111
111
??????
3
1111
1111
?????????
4
11111
11111
????????????
5
111111
111111
???????????????
6
1111111
1111111
??????????????????
7
11111111
11111111
?????????????????????
8
111111111
111111111
????????????????????????
9
1111111111
1111111111
???????????????????????????
10
1111...

output:

3
48
1077
25950
631596
15361200
373543344
513491674
3715046604
2905885740
1568880512
2580218992
1190440544
717460800
3773052672
4125163354
1253250684
451796724
588301280
3790101036
1976168152
2307984512
3414639104
4155978864
3748854816
300437408
2740636160
342373696
3437770880
3706226944
-1
-1
-1
-1...

result:

points 0.675 the max n you choose to answer is 30

Subtask #4:

score: 13.5
Acceptable Answer

Dependency #1:

67.5%
Acceptable Answer

Dependency #3:

67.5%
Acceptable Answer

Test #23:

score: 13.5
Acceptable Answer
time: 131ms
memory: 10448kb

input:

60 4
1
11
11
AC?
2
111
111
?ACAAA
3
1111
1111
AA?A?CCCC
4
11111
11111
??BBB?CBBACA
5
111111
111111
?CC?CCCAA?BCB??
6
1111111
1111111
?B?BBCCABBCBA?A?BC
7
11111111
11111111
AAA?B??C?CBABACCCA?AA
8
111111111
111111111
CBBB?AAC?B?A???BABAC?ACB
9
1111111111
1111111111
A?A?BAA?BCBC??ABBBBAAA?ACBB
10
1111...

output:

0
0
0
0
0
0
0
105
1
3146
4154
3960
1260
4200
45045
0
0
0
2042040
168168
34320
2454021525
45045
180180
4157010
2042040
1058148
818007190
67863915
34918884
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #24:

score: 13.5
Acceptable Answer
time: 139ms
memory: 9892kb

input:

60 4
1
11
11
CCA
2
111
111
BBAABC
3
1111
1111
?BACB?B?B
4
11111
11111
B??ACBBCBBA?
5
111111
111111
ABBBBC?CABCABA?
6
1111111
1111111
?ACAB?CAA?AB?C?AAC
7
11111111
11111111
?BAAA?BCAAA??AB?BABAC
8
111111111
111111111
BCBCC?ACACA?AAAC??BACACA
9
1111111111
1111111111
ACCCBCBAA?BABBA??BBBBACAA?A
10
1111...

output:

0
0
0
0
0
0
0
0
1
0
252
0
0
84
280
462
0
25740
2860
25740
120120
27713400
12
1750320
3527160
5697720
1963217256
2496144
4620
2912596129
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #25:

score: 13.5
Acceptable Answer
time: 141ms
memory: 10048kb

input:

60 4
1
11
11
A?B
2
111
111
BABBBB
3
1111
1111
?ABBABBCC
4
11111
11111
CBABBBCBABAB
5
111111
111111
AABCBA?CBBCCBBA
6
1111111
1111111
AB????CCBCC?BCBBB?
7
11111111
11111111
C?BBBC?BABCC?CC?A?BAC
8
111111111
111111111
CCAAACA?C?A??AAAABC?CAC?
9
1111111111
1111111111
BAABBBCA?A?BA?CA??CAAABBBAB
10
1111...

output:

0
0
0
0
0
0
5
0
0
0
0
0
0
6930
4620
0
630
10010
225225
48048
11639628
0
99768240
30940
1681680
646646
1594684472
0
0
14725136
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #26:

score: 13.5
Acceptable Answer
time: 204ms
memory: 10028kb

input:

60 4
1
11
11
???
2
111
111
???C??
3
1111
1111
?????????
4
11111
11111
?C???????AAA
5
111111
111111
???????????????
6
1111111
1111111
?????B???C?A?B?BC?
7
11111111
11111111
??????B??????A????C??
8
111111111
111111111
???????????C?CB?????????
9
1111111111
1111111111
??????B??CC?????B??C???????
10
1111...

output:

3
16
1077
84
631596
26874
15414869
333279339
839890088
3550801540
1954615936
2580218992
1105869471
1946118935
2265284022
1798565763
4108603992
1329111895
3649472249
2738880533
705653508
3288119724
147580510
1839072580
2747297333
3329188101
337568615
3559680316
3134386707
652354824
-1
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30

Test #27:

score: 13.5
Acceptable Answer
time: 208ms
memory: 10204kb

input:

60 4
1
11
11
???
2
111
111
??????
3
1111
1111
?????????
4
11111
11111
???AC?????A?
5
111111
111111
????????C??A???
6
1111111
1111111
?A???????????????C
7
11111111
11111111
BC?C??????B??A?B?A???
8
111111111
111111111
???????C?????A??????????
9
1111111111
1111111111
???????????????????????????
10
1111...

output:

3
48
1077
960
78094
1859143
232243
1062623411
3715046604
1407632725
1088064080
2580218992
1190440544
3361753841
1524705337
1888732532
1253250684
451796724
588301280
1832432327
2699631551
381107486
1851939489
2151321620
2541428250
3154326769
1071698061
2841820732
4117676189
1634832599
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30

Test #28:

score: 13.5
Acceptable Answer
time: 205ms
memory: 10004kb

input:

60 4
1
11
11
???
2
111
111
?B????
3
1111
1111
???????B?
4
11111
11111
????????????
5
111111
111111
?C??????????AA?
6
1111111
1111111
?????????????????A
7
11111111
11111111
?AA??????AB?CBC??????
8
111111111
111111111
????????????????????????
9
1111111111
1111111111
??A??????B?????A?????B????A
10
1111...

output:

3
16
359
25950
19248
5120400
240545
513491674
840173947
2433356206
4066542451
504071581
808882656
788643711
3128474815
936066479
1200822080
2347534139
4280254088
3399577184
3704522298
2200983936
456696389
2066128455
982249359
123285372
4133081366
1867086747
3521876468
42391872
-1
-1
-1
-1
-1
-1
-1
-...

result:

points 0.675 the max n you choose to answer is 30

Test #29:

score: 13.5
Acceptable Answer
time: 216ms
memory: 10176kb

input:

60 4
1
11
11
B?A
2
111
111
BACA??
3
1111
1111
???B?AB??
4
11111
11111
?BC?????A?B?
5
111111
111111
??BA??A?B??????
6
1111111
1111111
??????????????????
7
11111111
11111111
B?C?A????C???C???????
8
111111111
111111111
???B????????????????????
9
1111111111
1111111111
A?????????????????????????A
10
1111...

output:

1
1
44
490
8094
15361200
1592603
3034475422
1135004400
968628580
1954615936
2911513531
1190440544
1924761707
1257684224
4013545461
3590607515
1654813867
2486663249
2830610096
2898816748
2200983936
3806332750
617815798
1928809575
1664657716
2740636160
3761942860
1866494472
3057392120
-1
-1
-1
-1
-1
-...

result:

points 0.675 the max n you choose to answer is 30

Test #30:

score: 13.5
Acceptable Answer
time: 217ms
memory: 9948kb

input:

60 4
1
11
11
A?B
2
111
111
A?CBCA
3
1111
1111
?????????
4
11111
11111
C??C?????A??
5
111111
111111
???????A???????
6
1111111
1111111
?????????AC???C???
7
11111111
11111111
?????????????????A???
8
111111111
111111111
????????????????????????
9
1111111111
1111111111
??????????????A????????????
10
1111...

output:

0
1
1077
871
210532
557016
124514448
513491674
1238348868
968628580
1954615936
3723384528
3674406465
717460800
3773052672
4238365982
417750228
150598908
2565779365
1994476545
1976168152
747838472
1774869564
3373344736
3185542324
1531801568
2345201152
3802896928
2577579392
2778783946
-1
-1
-1
-1
-1
-...

result:

points 0.675 the max n you choose to answer is 30

Test #31:

score: 13.5
Acceptable Answer
time: 216ms
memory: 9976kb

input:

60 4
1
11
11
?AA
2
111
111
A??BB?
3
1111
1111
??????B?C
4
11111
11111
????C???????
5
111111
111111
?B????B????????
6
1111111
1111111
?????????????A????
7
11111111
11111111
?B??A?????????A????BA
8
111111111
111111111
????????????????????????
9
1111111111
1111111111
??A????B?????AB???B????????
10
1111...

output:

0
1
150
8650
61839
5120400
1379018
513491674
845030501
2244461381
2213812085
2617107898
2625804471
239153600
737611661
4125163354
1253250684
3417412934
1627756192
3790101036
3217942818
2159912434
2457995320
4155978864
2189382300
3952532646
1640291183
4270475301
296767402
1764586054
-1
-1
-1
-1
-1
-1...

result:

points 0.675 the max n you choose to answer is 30

Test #32:

score: 13.5
Acceptable Answer
time: 216ms
memory: 10112kb

input:

60 4
1
11
11
A?C
2
111
111
?B?B??
3
1111
1111
?A????C??
4
11111
11111
???A????B???
5
111111
111111
??????C?A??B?B?
6
1111111
1111111
????C??????B?C??B?
7
11111111
11111111
???????????B????A????
8
111111111
111111111
??CAC????C??????????????
9
1111111111
1111111111
?????????C???????????????C?
10
1111...

output:

1
4
132
3130
9637
195273
42981141
96486085
1478624726
1355837790
1568880512
2580218992
2997214215
977416340
1257684224
2742224852
2395030581
4130553076
1123321375
1632740557
2937095037
2200983936
1404812305
1385326288
613731216
3888976646
3739696930
527893117
3437770880
2445134823
-1
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30

Subtask #5:

score: 20.25
Acceptable Answer

Dependency #1:

67.5%
Acceptable Answer

Dependency #2:

67.5%
Acceptable Answer

Dependency #3:

67.5%
Acceptable Answer

Dependency #4:

67.5%
Acceptable Answer

Test #33:

score: 20.25
Acceptable Answer
time: 123ms
memory: 10160kb

input:

60 5
1
10
11
BBB
2
110
111
?BAAAC
3
0011
1010
A?AC?A?C?
4
00000
10100
CACBBC?AABBC
5
000011
010001
?CAACC?BBCBCBBB
6
0100111
0011111
C??BAC??ACCCAC?BB?
7
00010001
10011110
??BCABCB???CAAAABBCC?
8
100100000
111010111
?BCACCBACCCCACABAA?CACA?
9
1100111101
0010011010
?BCBCBCCAC?ACBBCBAB?ABBC?B?
10
1111...

output:

0
0
3
0
0
4
80
0
0
168
126
1054
21
4280
1680
2017688
51480
1229676
42324366
77597520
4082137
630630
50388
2310
11395440
1070845776
10010
99768240
12113640
60060
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #34:

score: 20.25
Acceptable Answer
time: 114ms
memory: 9832kb

input:

60 5
1
10
01
BC?
2
010
101
AA?CCB
3
1100
1011
CCACCAB?C
4
01011
00011
CBCCCCABCCCC
5
010110
111011
B?CB?AB?C?C?BCC
6
0100111
0011110
???C?AA?BBAB?CBABC
7
11100011
11000000
BCB?ACBBA?????BBBCA??
8
011000000
100101110
AB?ACCCBBBCCBBA?CAAA?AAB
9
0110101010
1001110110
BB?BBC?BAABA?AC?ABC???CCC??
10
0111...

output:

1
0
0
0
4
15
0
1
682
0
1104
20002
17987
330
126
0
0
0
4900896
840
2004775
1969110
0
7054320
45045
0
43758
1225224
0
1376219819
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #35:

score: 20.25
Acceptable Answer
time: 113ms
memory: 10024kb

input:

60 5
1
01
00
C?C
2
100
111
ACA?AC
3
0000
1001
CCABA?BAA
4
11011
01100
BBB??AA??BB?
5
100001
001111
CCBCAAC????ACB?
6
0010010
0010110
?BCB??CAAABAABBAC?
7
10001011
01011101
BBCACCCACBBC?CCCCB?CB
8
111100000
000000111
?AAC?B?A?BC?AA?A??A?CBA?
9
0000000101
0011011101
BB?BCABAC?ACA??ABCC?ACB????
10
1101...

output:

0
0
0
0
4
0
0
24
154
0
105
205
280
0
756
90
199343
45
27708788
25740
660
1750320
1820
512142614
680680
55350986
1153218090
2473199344
171609900
45224544
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

points 0.675 the max n you choose to answer is 30

Test #36:

score: 20.25
Acceptable Answer
time: 198ms
memory: 10024kb

input:

60 5
1
11
11
??A
2
111
111
A????C
3
0111
1111
??B????C?
4
11111
11101
????????????
5
101111
111001
?B?B??????AC?C?
6
1111111
1111011
C???????B??CB?????
7
10111111
11111110
??????????????????BA?
8
111110100
011111011
????????????????????????
9
1100011111
1101011011
??AC????B??CB???C?C?????CC?
10
1111...

output:

1
9
110
24478
1721
192041
41768688
323175872
4066454
154483534
1235206324
2903718323
2376290205
644471122
2412311104
2878206768
3605855974
1643838292
3711310740
3577163363
830729449
386993162
3927427225
2440231386
2426709105
361352437
1086257332
2736508518
3730328863
3363293047
-1
-1
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30

Test #37:

score: 20.25
Acceptable Answer
time: 198ms
memory: 10268kb

input:

60 5
1
11
11
?B?
2
110
110
??????
3
1111
1111
???????C?
4
11101
10111
????A????A??
5
110111
010111
?????A??????C?B
6
0111111
1011110
??BB?????????B????
7
11111100
01110111
????????A??A?B????C??
8
011101101
111100011
?B???????B?A?C???B??????
9
1111101111
1111101111
??BC?????C?A?????C???????BB
10
1010...

output:

1
40
359
1982
15552
352240
5194472
33487556
111726966
762434484
3502259319
2532111729
3721735927
4180021982
3824766150
2520285950
3026072122
1529388235
3853740221
2183863317
123930912
2390454516
1183647731
2306876587
82344866
70964649
4252651635
1522139983
2054852887
713251496
-1
-1
-1
-1
-1
-1
-1
-...

result:

points 0.675 the max n you choose to answer is 30

Test #38:

score: 20.25
Acceptable Answer
time: 200ms
memory: 10328kb

input:

60 5
1
11
11
C??
2
111
101
??????
3
1111
1101
???C???C?
4
11110
11111
???????C????
5
011111
111101
????B????????B?
6
1011111
1111111
B????C?????AA????C
7
11110111
01111111
??????C??????????????
8
110111100
110011101
?????C????????????A?????
9
1110101111
1101111011
?????B????C???C???????CA???
10
1011...

output:

1
26
85
8582
59089
68454
120308106
871930555
924083470
1662373325
4072937496
1676169075
183718261
3714329667
2374283332
961169386
2672642708
2489989535
1884615582
1584666864
691162122
3272035913
3050837775
1384636239
1023418251
445700103
132198241
1595479921
2935104449
1878239935
-1
-1
-1
-1
-1
-1
-...

result:

points 0.675 the max n you choose to answer is 30

Test #39:

score: 20.25
Acceptable Answer
time: 217ms
memory: 10392kb

input:

60 5
1
10
00
BAA
2
111
111
CBC??A
3
0000
0000
A??BA??BA
4
00100
11111
????????????
5
111111
000010
??A?????????AA?
6
0000110
0100010
B??????????C???C??
7
01011000
11111111
?????A???????????????
8
101000101
100111101
?B?????????????????A????
9
1011010011
1111111111
????????C??C?B????AC???????
10
1101...

output:

0
1
0
12293
2316
114201
114993309
776570536
925648744
3460897187
3179962775
3966667857
3718383099
2650422780
3129038732
3688066266
2391603483
1291684139
3873523640
1941440611
2369619364
1298575945
2658854944
1905149370
2243008240
2980888032
1734148828
1107539052
1671438596
2087725638
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30

Test #40:

score: 20.25
Acceptable Answer
time: 215ms
memory: 10156kb

input:

60 5
1
00
00
CBA
2
111
111
BCB?CC
3
0110
1011
?A?B?B??C
4
10111
00000
????A????BB?
5
100000
111110
????????B??????
6
1011111
0100101
C????C??????ACA???
7
11111111
11111101
????????????????C????
8
101000101
110001010
??????????A???C??C?A????
9
1000101111
1111101111
????B?C??CC?????????????C??
10
1011...

output:

0
0
9
0
35708
29509
124321131
61390530
501726275
4119806520
3043572596
1081182969
201921424
3678701340
588840127
715198416
3291339457
1281591236
1218356005
747666902
1970761136
3820930277
2248776253
4247388229
2058251641
3530468190
3093072823
1221981536
2763768737
1115961863
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30

Test #41:

score: 20.25
Acceptable Answer
time: 212ms
memory: 8504kb

input:

60 5
1
10
01
AAB
2
100
110
??????
3
1111
1111
?A?AB???C
4
01100
11110
BA?A?A??C???
5
110000
111101
?????????C?C?A?
6
0001010
0100011
A??B????????B???A?
7
00101010
11111111
????????????????????B
8
101111011
011111111
?B???????????C?????C?A??
9
1101110111
0111111111
?????C?????AB??????????A???
10
1011...

output:

0
17
24
50
12035
55913
108731604
127494885
3041353970
170946844
2801070225
3282880475
1300876923
56168266
1797931033
2079868786
1605889899
4041822115
1088828397
3140270211
4141522545
4040417281
2053481369
2336033105
4049678175
1835223169
3220617535
3598289904
458388178
2316458271
-1
-1
-1
-1
-1
-1
-...

result:

points 0.675 the max n you choose to answer is 30

Test #42:

score: 20.25
Acceptable Answer
time: 215ms
memory: 10084kb

input:

60 5
1
10
10
CCC
2
110
000
CA?CA?
3
0101
1100
BBBB??B??
4
10000
00000
C??????AA???
5
010100
000001
????C??B??C????
6
0011111
0110101
????????????A?A???
7
10111100
11111011
?????????????????????
8
010111001
110010010
???????????????B???A????
9
1111100111
1101111110
???????????????????????????
10
1111...

output:

0
0
0
0
0
865964
356776838
808715462
3953195031
783798214
2463550387
924796095
2581985025
825802039
2339418618
1067844969
266540766
355397961
3649268341
4061746821
3712860488
2391788746
4042516624
2990731052
2826794749
2870601682
3739233472
279299999
1758641440
1529789543
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

points 0.675 the max n you choose to answer is 30