#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
using namespace std;
typedef long long Int;
typedef pair<Int, Int> P;
#define MOD 1000000007
Int dp[2006][6006][2];
Int c[4001][4001];
Int cnt[4001];
char board[3][2000];
vector<P> block;
void init(){
for(Int i = 0;i < 4001;i++){
for(Int j = 0;j <= i;j++){
if(i == 0 || j == 0)c[i][j] = 1;
else c[i][j] = c[i-1][j] + c[i-1][j-1];
c[i][j] %= MOD;
}
}
}
void go(vector<Int> &vec){
Int n = vec.size();
if(n == 0)return;
for(Int i = 0;i <= n;i++){
for(Int j = 0;j <= 3 * (i+1);j++){
dp[i][j][0] = dp[i][j][1] = 0;
}
}
vector<Int>sum = vec;
for(Int i = 1;i < n;i++)sum[i] += sum[i-1];
for(Int i = 0;i < n;i++){
if(i == 0){
if(vec[i] == 1){
dp[0][1][1] = 1;
}
if(vec[i] == 2){
dp[0][1][0] = 1;
dp[0][2][1] = 1;
}
if(vec[i] == 3){
dp[0][1][0] = 2;
dp[0][2][0] = 2;
dp[0][3][1] = 2;
}
continue;
}
for(Int j = 1;j <= 3 * (i+1);j++){
dp[i-1][j][1] += dp[i-1][j-1][1];
dp[i-1][j][0] += dp[i-1][j-1][0];
}
if(vec[i] == 1){
for(Int j = 1;j <= sum[i];j++){
dp[i][j][1] += dp[i-1][sum[i-1]][1];
dp[i][j][1] += dp[i-1][sum[i-1]][0] - dp[i-1][j-1][0];
dp[i][j][1] %= MOD;
}
}
if(vec[i] == 2){
for(Int j = 1;j <= sum[i];j++){
// dp[i][j][0] += dp[i-1][j-1][0] * (sum[i] - j);
dp[i][j][0] += dp[i-1][j-1][1] * (sum[i] - j);
dp[i][j][0] %= MOD;
dp[i][j][1] += (dp[i-1][sum[i-1]][0] - dp[i-1][j-2][0]) * (j-1);
dp[i][j][1] += dp[i-1][sum[i-1]][1] * (j-1);
dp[i][j][1] %= MOD;
}
}
if(vec[i] == 3){
for(Int j = 1;j <= sum[i];j++){
// dp[i][j][0] += dp[i-1][j-1][0] * (sum[i] - j) % MOD * (sum[i] - j - 1);
dp[i][j][0] += dp[i-1][j-1][1] * (sum[i] - j) % MOD * (sum[i] - j - 1);
dp[i][j][0] %= MOD;
// if(j >= 2)dp[i][j][0] += dp[i-1][j-2][0] * (j-1) % MOD * (sum[i] - j) * 2;
if(j >= 2)dp[i][j][0] += dp[i-1][j-2][1] * (j-1) % MOD * (sum[i] - j) * 2;
dp[i][j][0] %= MOD;
dp[i][j][1] += (dp[i-1][sum[i-1]][0] - dp[i-1][j-1][0]) * (j-1) % MOD * (j-2);
dp[i][j][1] += dp[i-1][sum[i-1]][1] * (j-1) % MOD * (j-2);
dp[i][j][1] %= MOD;
}
}
}
Int res = 0;
for(Int i = 1;i <= sum[n-1];i++){
res += dp[n-1][i][0];
res += dp[n-1][i][1];
res %= MOD;
}
block.push_back(P(res, sum[n-1]));
}
int main(){
init();
Int black = 0;
Int n;
cin >> n;
for(Int i = 0;i < 3;i++){
for(Int j = 0;j < n;j++){
cin >> board[i][j];
if(board[i][j] == 'x')cnt[j]++, black++;
if(board[i][j] != 'o' && board[i][j] != 'x' ){
// cerr << "oxoxo" << endl;
// exit(10);
}
}
}
if(board[0][0] == 'x' || board[2][0] == 'x' || board[0][n-1] == 'x' || board[2][n-1] == 'x'){
cout << 0 << endl;
return 0;
}
for(Int i = 0;i < n;i++){
if(i == 0)continue;
if(board[0][i-1] == 'x' && board[0][i] == 'x'){
cout << 0 << endl;
return 0;
}
if(board[2][i-1] == 'x' && board[2][i] == 'x'){
cout << 0 << endl;
return 0;
}
}
vector<Int> tmp;
for(Int i = 0;i < n;i++){
if(board[1][i] == 'o'){
go(tmp);
tmp.clear();
if(board[0][i] == 'x')block.push_back(P(1, 1));
if(board[2][i] == 'x')block.push_back(P(1, 1));
}
else{
tmp.push_back(cnt[i]);
}
}
go(tmp);
Int res = 1;
for(Int i = 0;i < block.size();i++){
Int a = block[i].first;
Int b = block[i].second;
res *= a;res %= MOD;
res *= c[black][b];res %= MOD;
black -= b;
}
if(black != 0)cout << "PYA" << endl;
res %= MOD;
if(res < 0)res += MOD;
cout << res << endl;
return 0;
}
Compilation message
solitaire.cpp: In function 'int main()':
solitaire.cpp:162:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(Int i = 0;i < block.size();i++){
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
78072 KB |
Output is correct |
2 |
Correct |
69 ms |
78148 KB |
Output is correct |
3 |
Correct |
74 ms |
78148 KB |
Output is correct |
4 |
Correct |
87 ms |
78268 KB |
Output is correct |
5 |
Correct |
74 ms |
78316 KB |
Output is correct |
6 |
Correct |
83 ms |
78316 KB |
Output is correct |
7 |
Correct |
103 ms |
78316 KB |
Output is correct |
8 |
Correct |
88 ms |
78316 KB |
Output is correct |
9 |
Correct |
73 ms |
78316 KB |
Output is correct |
10 |
Correct |
78 ms |
78316 KB |
Output is correct |
11 |
Correct |
70 ms |
78316 KB |
Output is correct |
12 |
Correct |
78 ms |
78316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
78404 KB |
Output is correct |
2 |
Correct |
96 ms |
78412 KB |
Output is correct |
3 |
Correct |
77 ms |
78412 KB |
Output is correct |
4 |
Correct |
81 ms |
78412 KB |
Output is correct |
5 |
Correct |
76 ms |
78440 KB |
Output is correct |
6 |
Correct |
73 ms |
78540 KB |
Output is correct |
7 |
Correct |
79 ms |
78540 KB |
Output is correct |
8 |
Correct |
82 ms |
78540 KB |
Output is correct |
9 |
Correct |
79 ms |
78540 KB |
Output is correct |
10 |
Correct |
72 ms |
78540 KB |
Output is correct |
11 |
Correct |
68 ms |
78540 KB |
Output is correct |
12 |
Correct |
71 ms |
78540 KB |
Output is correct |
13 |
Correct |
79 ms |
82144 KB |
Output is correct |
14 |
Correct |
87 ms |
83936 KB |
Output is correct |
15 |
Correct |
86 ms |
91356 KB |
Output is correct |
16 |
Correct |
92 ms |
91356 KB |
Output is correct |
17 |
Correct |
88 ms |
91356 KB |
Output is correct |
18 |
Correct |
81 ms |
91356 KB |
Output is correct |
19 |
Correct |
83 ms |
91356 KB |
Output is correct |
20 |
Correct |
86 ms |
91356 KB |
Output is correct |
21 |
Correct |
81 ms |
91356 KB |
Output is correct |
22 |
Correct |
82 ms |
92848 KB |
Output is correct |
23 |
Correct |
96 ms |
92848 KB |
Output is correct |
24 |
Correct |
88 ms |
92848 KB |
Output is correct |
25 |
Correct |
79 ms |
92848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
92848 KB |
Output is correct |
2 |
Correct |
71 ms |
92848 KB |
Output is correct |
3 |
Correct |
66 ms |
92848 KB |
Output is correct |
4 |
Correct |
70 ms |
92848 KB |
Output is correct |
5 |
Correct |
66 ms |
92848 KB |
Output is correct |
6 |
Correct |
68 ms |
92848 KB |
Output is correct |
7 |
Correct |
67 ms |
92848 KB |
Output is correct |
8 |
Correct |
93 ms |
92848 KB |
Output is correct |
9 |
Correct |
90 ms |
92848 KB |
Output is correct |
10 |
Correct |
79 ms |
92848 KB |
Output is correct |
11 |
Correct |
83 ms |
92848 KB |
Output is correct |
12 |
Correct |
76 ms |
92848 KB |
Output is correct |
13 |
Correct |
73 ms |
92848 KB |
Output is correct |
14 |
Correct |
69 ms |
92848 KB |
Output is correct |
15 |
Correct |
70 ms |
92848 KB |
Output is correct |
16 |
Correct |
65 ms |
92848 KB |
Output is correct |
17 |
Correct |
68 ms |
92848 KB |
Output is correct |
18 |
Correct |
68 ms |
92848 KB |
Output is correct |
19 |
Correct |
68 ms |
92848 KB |
Output is correct |
20 |
Correct |
72 ms |
92848 KB |
Output is correct |
21 |
Correct |
75 ms |
92848 KB |
Output is correct |
22 |
Correct |
72 ms |
92848 KB |
Output is correct |
23 |
Correct |
75 ms |
92848 KB |
Output is correct |
24 |
Correct |
78 ms |
92848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
78072 KB |
Output is correct |
2 |
Correct |
69 ms |
78148 KB |
Output is correct |
3 |
Correct |
74 ms |
78148 KB |
Output is correct |
4 |
Correct |
87 ms |
78268 KB |
Output is correct |
5 |
Correct |
74 ms |
78316 KB |
Output is correct |
6 |
Correct |
83 ms |
78316 KB |
Output is correct |
7 |
Correct |
103 ms |
78316 KB |
Output is correct |
8 |
Correct |
88 ms |
78316 KB |
Output is correct |
9 |
Correct |
73 ms |
78316 KB |
Output is correct |
10 |
Correct |
78 ms |
78316 KB |
Output is correct |
11 |
Correct |
70 ms |
78316 KB |
Output is correct |
12 |
Correct |
78 ms |
78316 KB |
Output is correct |
13 |
Correct |
65 ms |
92848 KB |
Output is correct |
14 |
Correct |
71 ms |
92848 KB |
Output is correct |
15 |
Correct |
66 ms |
92848 KB |
Output is correct |
16 |
Correct |
70 ms |
92848 KB |
Output is correct |
17 |
Correct |
66 ms |
92848 KB |
Output is correct |
18 |
Correct |
68 ms |
92848 KB |
Output is correct |
19 |
Correct |
67 ms |
92848 KB |
Output is correct |
20 |
Correct |
93 ms |
92848 KB |
Output is correct |
21 |
Correct |
90 ms |
92848 KB |
Output is correct |
22 |
Correct |
79 ms |
92848 KB |
Output is correct |
23 |
Correct |
83 ms |
92848 KB |
Output is correct |
24 |
Correct |
76 ms |
92848 KB |
Output is correct |
25 |
Correct |
73 ms |
92848 KB |
Output is correct |
26 |
Correct |
69 ms |
92848 KB |
Output is correct |
27 |
Correct |
70 ms |
92848 KB |
Output is correct |
28 |
Correct |
65 ms |
92848 KB |
Output is correct |
29 |
Correct |
68 ms |
92848 KB |
Output is correct |
30 |
Correct |
68 ms |
92848 KB |
Output is correct |
31 |
Correct |
68 ms |
92848 KB |
Output is correct |
32 |
Correct |
72 ms |
92848 KB |
Output is correct |
33 |
Correct |
75 ms |
92848 KB |
Output is correct |
34 |
Correct |
72 ms |
92848 KB |
Output is correct |
35 |
Correct |
75 ms |
92848 KB |
Output is correct |
36 |
Correct |
78 ms |
92848 KB |
Output is correct |
37 |
Correct |
73 ms |
92848 KB |
Output is correct |
38 |
Correct |
69 ms |
92848 KB |
Output is correct |
39 |
Correct |
67 ms |
92848 KB |
Output is correct |
40 |
Correct |
70 ms |
92848 KB |
Output is correct |
41 |
Correct |
66 ms |
92848 KB |
Output is correct |
42 |
Correct |
65 ms |
92848 KB |
Output is correct |
43 |
Correct |
74 ms |
92848 KB |
Output is correct |
44 |
Correct |
68 ms |
92848 KB |
Output is correct |
45 |
Correct |
68 ms |
92848 KB |
Output is correct |
46 |
Correct |
69 ms |
92848 KB |
Output is correct |
47 |
Correct |
69 ms |
92848 KB |
Output is correct |
48 |
Correct |
67 ms |
92848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
78072 KB |
Output is correct |
2 |
Correct |
69 ms |
78148 KB |
Output is correct |
3 |
Correct |
74 ms |
78148 KB |
Output is correct |
4 |
Correct |
87 ms |
78268 KB |
Output is correct |
5 |
Correct |
74 ms |
78316 KB |
Output is correct |
6 |
Correct |
83 ms |
78316 KB |
Output is correct |
7 |
Correct |
103 ms |
78316 KB |
Output is correct |
8 |
Correct |
88 ms |
78316 KB |
Output is correct |
9 |
Correct |
73 ms |
78316 KB |
Output is correct |
10 |
Correct |
78 ms |
78316 KB |
Output is correct |
11 |
Correct |
70 ms |
78316 KB |
Output is correct |
12 |
Correct |
78 ms |
78316 KB |
Output is correct |
13 |
Correct |
72 ms |
78404 KB |
Output is correct |
14 |
Correct |
96 ms |
78412 KB |
Output is correct |
15 |
Correct |
77 ms |
78412 KB |
Output is correct |
16 |
Correct |
81 ms |
78412 KB |
Output is correct |
17 |
Correct |
76 ms |
78440 KB |
Output is correct |
18 |
Correct |
73 ms |
78540 KB |
Output is correct |
19 |
Correct |
79 ms |
78540 KB |
Output is correct |
20 |
Correct |
82 ms |
78540 KB |
Output is correct |
21 |
Correct |
79 ms |
78540 KB |
Output is correct |
22 |
Correct |
72 ms |
78540 KB |
Output is correct |
23 |
Correct |
68 ms |
78540 KB |
Output is correct |
24 |
Correct |
71 ms |
78540 KB |
Output is correct |
25 |
Correct |
79 ms |
82144 KB |
Output is correct |
26 |
Correct |
87 ms |
83936 KB |
Output is correct |
27 |
Correct |
86 ms |
91356 KB |
Output is correct |
28 |
Correct |
92 ms |
91356 KB |
Output is correct |
29 |
Correct |
88 ms |
91356 KB |
Output is correct |
30 |
Correct |
81 ms |
91356 KB |
Output is correct |
31 |
Correct |
83 ms |
91356 KB |
Output is correct |
32 |
Correct |
86 ms |
91356 KB |
Output is correct |
33 |
Correct |
81 ms |
91356 KB |
Output is correct |
34 |
Correct |
82 ms |
92848 KB |
Output is correct |
35 |
Correct |
96 ms |
92848 KB |
Output is correct |
36 |
Correct |
88 ms |
92848 KB |
Output is correct |
37 |
Correct |
79 ms |
92848 KB |
Output is correct |
38 |
Correct |
65 ms |
92848 KB |
Output is correct |
39 |
Correct |
71 ms |
92848 KB |
Output is correct |
40 |
Correct |
66 ms |
92848 KB |
Output is correct |
41 |
Correct |
70 ms |
92848 KB |
Output is correct |
42 |
Correct |
66 ms |
92848 KB |
Output is correct |
43 |
Correct |
68 ms |
92848 KB |
Output is correct |
44 |
Correct |
67 ms |
92848 KB |
Output is correct |
45 |
Correct |
93 ms |
92848 KB |
Output is correct |
46 |
Correct |
90 ms |
92848 KB |
Output is correct |
47 |
Correct |
79 ms |
92848 KB |
Output is correct |
48 |
Correct |
83 ms |
92848 KB |
Output is correct |
49 |
Correct |
76 ms |
92848 KB |
Output is correct |
50 |
Correct |
73 ms |
92848 KB |
Output is correct |
51 |
Correct |
69 ms |
92848 KB |
Output is correct |
52 |
Correct |
70 ms |
92848 KB |
Output is correct |
53 |
Correct |
65 ms |
92848 KB |
Output is correct |
54 |
Correct |
68 ms |
92848 KB |
Output is correct |
55 |
Correct |
68 ms |
92848 KB |
Output is correct |
56 |
Correct |
68 ms |
92848 KB |
Output is correct |
57 |
Correct |
72 ms |
92848 KB |
Output is correct |
58 |
Correct |
75 ms |
92848 KB |
Output is correct |
59 |
Correct |
72 ms |
92848 KB |
Output is correct |
60 |
Correct |
75 ms |
92848 KB |
Output is correct |
61 |
Correct |
78 ms |
92848 KB |
Output is correct |
62 |
Correct |
73 ms |
92848 KB |
Output is correct |
63 |
Correct |
69 ms |
92848 KB |
Output is correct |
64 |
Correct |
67 ms |
92848 KB |
Output is correct |
65 |
Correct |
70 ms |
92848 KB |
Output is correct |
66 |
Correct |
66 ms |
92848 KB |
Output is correct |
67 |
Correct |
65 ms |
92848 KB |
Output is correct |
68 |
Correct |
74 ms |
92848 KB |
Output is correct |
69 |
Correct |
68 ms |
92848 KB |
Output is correct |
70 |
Correct |
68 ms |
92848 KB |
Output is correct |
71 |
Correct |
69 ms |
92848 KB |
Output is correct |
72 |
Correct |
69 ms |
92848 KB |
Output is correct |
73 |
Correct |
67 ms |
92848 KB |
Output is correct |
74 |
Correct |
68 ms |
92848 KB |
Output is correct |
75 |
Correct |
68 ms |
92848 KB |
Output is correct |
76 |
Correct |
68 ms |
92848 KB |
Output is correct |
77 |
Correct |
74 ms |
92848 KB |
Output is correct |
78 |
Correct |
80 ms |
92848 KB |
Output is correct |
79 |
Correct |
67 ms |
92848 KB |
Output is correct |
80 |
Correct |
68 ms |
92848 KB |
Output is correct |
81 |
Correct |
73 ms |
92848 KB |
Output is correct |
82 |
Correct |
69 ms |
92848 KB |
Output is correct |
83 |
Correct |
69 ms |
92848 KB |
Output is correct |
84 |
Correct |
74 ms |
92848 KB |
Output is correct |
85 |
Correct |
72 ms |
92848 KB |
Output is correct |
86 |
Correct |
189 ms |
180624 KB |
Output is correct |
87 |
Correct |
184 ms |
180624 KB |
Output is correct |
88 |
Correct |
181 ms |
180624 KB |
Output is correct |
89 |
Correct |
189 ms |
180624 KB |
Output is correct |
90 |
Correct |
212 ms |
180624 KB |
Output is correct |
91 |
Correct |
189 ms |
180624 KB |
Output is correct |
92 |
Correct |
182 ms |
180624 KB |
Output is correct |
93 |
Correct |
175 ms |
180680 KB |
Output is correct |
94 |
Correct |
178 ms |
180680 KB |
Output is correct |
95 |
Correct |
175 ms |
180680 KB |
Output is correct |
96 |
Correct |
211 ms |
180680 KB |
Output is correct |
97 |
Correct |
175 ms |
180680 KB |
Output is correct |