#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2005;
const int M=3*N;
const int mod=1e9+7;
int mul(int x, int y){ return (ll)x*y%mod;}
void ckmul(int &x, int y){ x=mul(x,y);}
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
void ckadd(int &x, int y){ x=add(x,y);}
int sub(int x, int y){ x-=y;return x<0?x+mod:x;}
void cksub(int &x, int y){ x=sub(x,y);}
int dp[2],dp_ok[2][M],dp_lo[2][M],dp_tmp[2][M],dp_pre[2][M];
char base[4][N];
void Clear(int col)
{
dp[col]=0;
for(int i=0;i<M;i++)
{
dp_ok[col][i]=0;
dp_lo[col][i]=0;
dp_tmp[col][i]=0;
dp_pre[col][i]=0;
}
}
int main()
{
int n;
scanf("%i",&n);
scanf("%s %s %s",base[1]+1,base[2]+1,base[3]+1);
for(int i=2;i<=n;i++) if(base[1][i]=='x' && base[1][i-1]=='x') return 0*printf("0\n");
for(int i=2;i<=n;i++) if(base[3][i]=='x' && base[3][i-1]=='x') return 0*printf("0\n");
int col=0,SZ=0;
dp[col]=1;
for(int i=1;i<=n+1;i++)
{
col^=1;
Clear(col);
if(base[2][i]=='x')
{
if(base[2][i-1]=='x')
{
for(int X=SZ+1;X>=1;X--)
{
if(X>SZ) dp_tmp[col][X]=0;
else dp_tmp[col][X]=add(dp_tmp[col][X+1],dp_lo[col^1][X]);
}
int sum=0;
for(int X=1;X<=SZ;X++) ckadd(sum,dp_ok[col^1][X]);
for(int X=1;X<=SZ+1;X++) ckadd(dp_tmp[col][X],sum);
for(int X=1;X<=SZ+1;X++)
{
dp_pre[col][X]=0;
if(X>1) ckadd(dp_pre[col][X],add(dp_pre[col][X-1],dp_ok[col^1][X-1]));
}
}
else
{
for(int X=SZ+1;X>=1;X--)
{
dp_tmp[col][X]=dp_pre[col][X]=dp[col^1];
}
}
SZ++;
int cs=(base[1][i]=='x')+(base[3][i]=='x');
SZ+=cs;
if(cs==0) for(int X=1;X<=SZ;X++) dp_ok[col][X]=dp_tmp[col][X];
if(cs==1) for(int X=2;X<=SZ;X++) dp_ok[col][X]=mul(dp_tmp[col][X-1],X-1);
if(cs==2) for(int X=3;X<=SZ;X++) dp_ok[col][X]=mul(dp_tmp[col][X-2],mul(X-1,X-2));
//if(cs==0) for(int X=1;X<=SZ;X++) dp_lo[col][X]=dp_pre[col][X];
if(cs==1) for(int X=1;X<=SZ;X++) dp_lo[col][X]=mul(dp_pre[col][X],SZ-X);
if(cs==2) for(int X=1;X<=SZ;X++) dp_lo[col][X]=add(mul(dp_pre[col][X],mul(SZ-X,SZ-X-1)),mul(dp_pre[col][X-1],mul(mul(X-1,SZ-X),2)));
}
else
{
if(base[2][i-1]=='x')
{
for(int X=1;X<=SZ;X++) ckadd(dp[col],add(dp_ok[col^1][X],dp_lo[col^1][X]));
}
else
{
dp[col]=dp[col^1];
}
int cs=(base[1][i]=='x')+(base[3][i]=='x');
SZ+=cs;
if(cs==1) ckmul(dp[col],SZ);
if(cs==2) ckmul(dp[col],mul(SZ,SZ-1));
}
/*printf("col:%i\n\n",i);
if(base[2][i]=='x')
{
printf("dp_tmp:");for(int X=1;X<=SZ;X++) printf("%i ",dp_tmp[col][X]);printf("\n");
printf("dp_pre:");for(int X=1;X<=SZ;X++) printf("%i ",dp_pre[col][X]);printf("\n");
printf("dp_lo:");for(int X=1;X<=SZ;X++) printf("%i ",dp_lo[col][X]);printf("\n");
printf("dp_ok:");for(int X=1;X<=SZ;X++) printf("%i ",dp_ok[col][X]);printf("\n");
}
else
{
printf("dp: %i\n",dp[col]);
}
printf("\n");*/
}
printf("%i\n",dp[col]);
return 0;
}
Compilation message
solitaire.cpp: In function 'int main()':
solitaire.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
solitaire.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s %s %s",base[1]+1,base[2]+1,base[3]+1);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
504 KB |
Output is correct |
2 |
Correct |
36 ms |
632 KB |
Output is correct |
3 |
Correct |
14 ms |
504 KB |
Output is correct |
4 |
Correct |
45 ms |
504 KB |
Output is correct |
5 |
Correct |
42 ms |
504 KB |
Output is correct |
6 |
Correct |
42 ms |
504 KB |
Output is correct |
7 |
Correct |
34 ms |
504 KB |
Output is correct |
8 |
Correct |
44 ms |
556 KB |
Output is correct |
9 |
Correct |
44 ms |
632 KB |
Output is correct |
10 |
Correct |
58 ms |
504 KB |
Output is correct |
11 |
Correct |
39 ms |
504 KB |
Output is correct |
12 |
Correct |
42 ms |
504 KB |
Output is correct |
13 |
Correct |
51 ms |
592 KB |
Output is correct |
14 |
Correct |
50 ms |
504 KB |
Output is correct |
15 |
Correct |
52 ms |
504 KB |
Output is correct |
16 |
Correct |
50 ms |
508 KB |
Output is correct |
17 |
Correct |
51 ms |
504 KB |
Output is correct |
18 |
Correct |
112 ms |
568 KB |
Output is correct |
19 |
Correct |
67 ms |
632 KB |
Output is correct |
20 |
Correct |
50 ms |
504 KB |
Output is correct |
21 |
Correct |
49 ms |
564 KB |
Output is correct |
22 |
Correct |
50 ms |
504 KB |
Output is correct |
23 |
Correct |
55 ms |
476 KB |
Output is correct |
24 |
Correct |
50 ms |
504 KB |
Output is correct |
25 |
Correct |
50 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
552 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
7 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
508 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
524 KB |
Output is correct |
16 |
Correct |
3 ms |
552 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
7 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
508 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
3 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
3 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
504 KB |
Output is correct |
38 |
Correct |
5 ms |
504 KB |
Output is correct |
39 |
Correct |
3 ms |
508 KB |
Output is correct |
40 |
Correct |
13 ms |
604 KB |
Output is correct |
41 |
Correct |
7 ms |
504 KB |
Output is correct |
42 |
Correct |
7 ms |
504 KB |
Output is correct |
43 |
Correct |
7 ms |
504 KB |
Output is correct |
44 |
Correct |
7 ms |
504 KB |
Output is correct |
45 |
Correct |
7 ms |
504 KB |
Output is correct |
46 |
Correct |
7 ms |
504 KB |
Output is correct |
47 |
Correct |
7 ms |
504 KB |
Output is correct |
48 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
17 ms |
504 KB |
Output is correct |
14 |
Correct |
36 ms |
632 KB |
Output is correct |
15 |
Correct |
14 ms |
504 KB |
Output is correct |
16 |
Correct |
45 ms |
504 KB |
Output is correct |
17 |
Correct |
42 ms |
504 KB |
Output is correct |
18 |
Correct |
42 ms |
504 KB |
Output is correct |
19 |
Correct |
34 ms |
504 KB |
Output is correct |
20 |
Correct |
44 ms |
556 KB |
Output is correct |
21 |
Correct |
44 ms |
632 KB |
Output is correct |
22 |
Correct |
58 ms |
504 KB |
Output is correct |
23 |
Correct |
39 ms |
504 KB |
Output is correct |
24 |
Correct |
42 ms |
504 KB |
Output is correct |
25 |
Correct |
51 ms |
592 KB |
Output is correct |
26 |
Correct |
50 ms |
504 KB |
Output is correct |
27 |
Correct |
52 ms |
504 KB |
Output is correct |
28 |
Correct |
50 ms |
508 KB |
Output is correct |
29 |
Correct |
51 ms |
504 KB |
Output is correct |
30 |
Correct |
112 ms |
568 KB |
Output is correct |
31 |
Correct |
67 ms |
632 KB |
Output is correct |
32 |
Correct |
50 ms |
504 KB |
Output is correct |
33 |
Correct |
49 ms |
564 KB |
Output is correct |
34 |
Correct |
50 ms |
504 KB |
Output is correct |
35 |
Correct |
55 ms |
476 KB |
Output is correct |
36 |
Correct |
50 ms |
504 KB |
Output is correct |
37 |
Correct |
50 ms |
504 KB |
Output is correct |
38 |
Correct |
3 ms |
504 KB |
Output is correct |
39 |
Correct |
3 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
524 KB |
Output is correct |
41 |
Correct |
3 ms |
552 KB |
Output is correct |
42 |
Correct |
3 ms |
504 KB |
Output is correct |
43 |
Correct |
3 ms |
504 KB |
Output is correct |
44 |
Correct |
7 ms |
504 KB |
Output is correct |
45 |
Correct |
3 ms |
504 KB |
Output is correct |
46 |
Correct |
3 ms |
504 KB |
Output is correct |
47 |
Correct |
3 ms |
508 KB |
Output is correct |
48 |
Correct |
3 ms |
504 KB |
Output is correct |
49 |
Correct |
3 ms |
504 KB |
Output is correct |
50 |
Correct |
3 ms |
504 KB |
Output is correct |
51 |
Correct |
2 ms |
504 KB |
Output is correct |
52 |
Correct |
3 ms |
504 KB |
Output is correct |
53 |
Correct |
3 ms |
504 KB |
Output is correct |
54 |
Correct |
3 ms |
504 KB |
Output is correct |
55 |
Correct |
3 ms |
504 KB |
Output is correct |
56 |
Correct |
3 ms |
504 KB |
Output is correct |
57 |
Correct |
3 ms |
504 KB |
Output is correct |
58 |
Correct |
3 ms |
504 KB |
Output is correct |
59 |
Correct |
2 ms |
504 KB |
Output is correct |
60 |
Correct |
2 ms |
504 KB |
Output is correct |
61 |
Correct |
3 ms |
504 KB |
Output is correct |
62 |
Correct |
4 ms |
504 KB |
Output is correct |
63 |
Correct |
5 ms |
504 KB |
Output is correct |
64 |
Correct |
3 ms |
508 KB |
Output is correct |
65 |
Correct |
13 ms |
604 KB |
Output is correct |
66 |
Correct |
7 ms |
504 KB |
Output is correct |
67 |
Correct |
7 ms |
504 KB |
Output is correct |
68 |
Correct |
7 ms |
504 KB |
Output is correct |
69 |
Correct |
7 ms |
504 KB |
Output is correct |
70 |
Correct |
7 ms |
504 KB |
Output is correct |
71 |
Correct |
7 ms |
504 KB |
Output is correct |
72 |
Correct |
7 ms |
504 KB |
Output is correct |
73 |
Correct |
7 ms |
504 KB |
Output is correct |
74 |
Correct |
35 ms |
504 KB |
Output is correct |
75 |
Correct |
14 ms |
504 KB |
Output is correct |
76 |
Correct |
22 ms |
660 KB |
Output is correct |
77 |
Correct |
52 ms |
596 KB |
Output is correct |
78 |
Correct |
53 ms |
504 KB |
Output is correct |
79 |
Correct |
38 ms |
504 KB |
Output is correct |
80 |
Correct |
50 ms |
504 KB |
Output is correct |
81 |
Correct |
45 ms |
508 KB |
Output is correct |
82 |
Correct |
53 ms |
504 KB |
Output is correct |
83 |
Correct |
38 ms |
504 KB |
Output is correct |
84 |
Correct |
35 ms |
504 KB |
Output is correct |
85 |
Correct |
45 ms |
504 KB |
Output is correct |
86 |
Correct |
82 ms |
632 KB |
Output is correct |
87 |
Correct |
81 ms |
564 KB |
Output is correct |
88 |
Correct |
80 ms |
504 KB |
Output is correct |
89 |
Correct |
81 ms |
508 KB |
Output is correct |
90 |
Correct |
83 ms |
504 KB |
Output is correct |
91 |
Correct |
81 ms |
552 KB |
Output is correct |
92 |
Correct |
79 ms |
564 KB |
Output is correct |
93 |
Correct |
82 ms |
632 KB |
Output is correct |
94 |
Correct |
90 ms |
504 KB |
Output is correct |
95 |
Correct |
92 ms |
508 KB |
Output is correct |
96 |
Correct |
86 ms |
504 KB |
Output is correct |
97 |
Correct |
79 ms |
504 KB |
Output is correct |