QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687827 | #9463. 基础 ABC 练习题 | kkkgjyismine4 | 0 | 0ms | 0kb | C++20 | 2.1kb | 2024-10-29 21:28:33 | 2024-10-29 21:28:33 |
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!=60){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];
}
}
}
}
for(int i=n*3;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)));
for(int k=l,m=i-j-l;k<=r;++k,--m){
if(j==n&&k==n)ret+=f[i][j][k][1][1];
}
}
}
cout<<ret<<endl;
}
int main() {
int t,ss;cin>>t>>ss;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #22:
score: 0
Time Limit Exceeded
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 2582641664 ...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%