# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
189721 |
2020-01-14T05:12:17 Z |
dndhk |
None (JOI16_solitaire) |
C++14 |
|
49 ms |
904 KB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 6000;
const ll MOD = 1000000007;
ll multi(ll x, ll y){
if(y==0) return 1;
if(y==1) return x%MOD;
ll m = multi(x, y/2);
if(y%2){
return (m*m%MOD)*x%MOD;
}return m*m%MOD;
}
int N;
string str[3];
ll per[MAX_N+1], inv[MAX_N+1];
ll ans = 1, sz = 0;
ll dp[2][MAX_N+1], ndp[2][MAX_N+1];
ll s0[MAX_N+1], s1[MAX_N+1];
int cnt[MAX_N+1];
void input(){
cin>>N;
per[0] = per[1] = inv[0] = inv[1] = 1;
for(int i=2; i<=3*N; i++){
per[i] = (per[i-1] * (ll)i) % MOD;
inv[i] = multi(per[i], MOD-2);
}
for(int i=0; i<3; i++){
cin>>str[i];
}
}
int main(){
input();
if(str[0][0]=='x' || str[2][0]=='x' || str[0][N-1]=='x' || str[2][N-1]=='x'){
printf("0");
return 0;
}
for(int i=0; i<N-1; i++){
if(str[0][i]=='x' && str[0][i+1]=='x'){
printf("0");
return 0;
}
if(str[2][i]=='x' && str[2][i+1]=='x'){
printf("0");
return 0;
}
}
for(int i=0; i<N; i++){
if(str[0][i]=='x') cnt[i]++;
if(str[2][i]=='x') cnt[i]++;
}
for(int i=0; i<N; i++){
if(str[1][i]=='x'){
int s = i, e = i;
while(e<N-1 && str[1][e+1]=='x') e++;
for(int j=0; j<=3*N; j++){
s0[j] = s1[j] = dp[0][j] = dp[1][j] = ndp[0][j] = ndp[1][j] = 0;
}
int l = 0;
for(int j=s; j<=e; j++){
if(j==s){
if(cnt[j]==0){
ndp[0][1] = ndp[1][1] = 1;
}else if(cnt[j]==1){
if(j==0){
ndp[0][2] = ndp[1][2] = 1;
}else{
ndp[0][1] = ndp[0][2] = ndp[1][2] = 1;
}
}else{
if(j==0){
ndp[0][3] = ndp[1][3] = 2;
}else{
ndp[0][1] = ndp[0][2] = ndp[0][3] = 2;
ndp[1][3] = 2;
}
}
}else{
if(cnt[j]==0){
for(int k=1; k<=l+1; k++){
ndp[0][k] = (s0[k]+s1[k-1])%MOD;
ndp[1][k] = ndp[0][k];
}
}else if(cnt[j]==1){
for(int k=1; k<=l+2; k++){
ndp[0][k] = (s0[k-1]*(ll)(k-1)%MOD)+((k>=3?s1[k-2]:0LL)*(ll)(l+1)%MOD) + (dp[1][k-1]*(ll)(l-k+2)%MOD);
ndp[0][k] = ndp[0][k]%MOD;
ndp[1][k] = (s0[k-1]+(k>=3?s1[k-2]:0LL))*(ll)(k-1) % MOD;
}
}else{
for(int k=1; k<=l+3; k++){
if(k>=3) ndp[1][k] = (((s0[k-2]+s1[k-3])*(ll)(k-1)%MOD)*(ll)(k-2))%MOD;
if(k>=3){
//cout<<"*"<<k<<endl;
ndp[0][k] = ((s0[k-2]*(ll)(k-1)%MOD)*(ll)(k-2))%MOD;
//cout<<ndp[0][k]<<endl;
ndp[0][k] = (ndp[0][k] + ((s1[k-3]*(ll)(l+2)%MOD)*(ll)(l+1)%MOD))%MOD;
//cout<<ndp[0][k]<<endl;
ndp[0][k] = (ndp[0][k] + (ll)dp[1][k-2] * (((ll)(l+2)*(ll)(l+1) - (ll)(k-2)*(ll)(k-1))%MOD) %MOD)%MOD;
//cout<<ndp[0][k]<<endl;
}
ndp[0][k] = (ndp[0][k] + (dp[1][k-1] * (ll)(l-k+2)%MOD)*(ll)(l-k+3)%MOD)%MOD;
}
}
}
l+=cnt[j]+1;
//cout<<"*"<<j<<endl;
for(int k=1; k<=l; k++){
dp[0][k] = ndp[0][k];
dp[1][k] = ndp[1][k];
//cout<<dp[0][k]<<" "<<dp[1][k]<<endl;
ndp[0][k] = ndp[1][k] = 0;
}
s1[1] = dp[1][1];
s0[l] = dp[0][l];
for(int k=2; k<=l; k++){
s1[k] = s1[k-1]+dp[1][k];
}
for(int k=l-1; k>=1; k--){
s0[k] = s0[k+1]+dp[0][k];
}
}
ll sum = 0;
for(int k=1; k<=l; k++){
if(e==N-1){
sum = (sum + dp[1][k]) % MOD;
}else{
sum = (sum + dp[0][k]) % MOD;
}
}
ans = (ans * sum) % MOD;
ans = (ans * inv[l]) % MOD;
ans = (ans * inv[sz]) % MOD;
ans = (ans * per[l+sz]) % MOD;
//cout<<"!"<<ans<<" "<<sum<<endl;
sz+=l;
i = e;
}else{
if(str[0][i]=='x'){
ans = (ans * (sz+1LL)) % MOD;
sz++;
}if(str[2][i]=='x'){
ans = (ans * (sz+1LL)) % MOD;
sz++;
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
396 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
27 ms |
760 KB |
Output is correct |
3 |
Correct |
7 ms |
504 KB |
Output is correct |
4 |
Correct |
28 ms |
760 KB |
Output is correct |
5 |
Correct |
30 ms |
776 KB |
Output is correct |
6 |
Correct |
31 ms |
760 KB |
Output is correct |
7 |
Correct |
28 ms |
760 KB |
Output is correct |
8 |
Correct |
28 ms |
804 KB |
Output is correct |
9 |
Correct |
29 ms |
760 KB |
Output is correct |
10 |
Correct |
27 ms |
760 KB |
Output is correct |
11 |
Correct |
30 ms |
760 KB |
Output is correct |
12 |
Correct |
28 ms |
760 KB |
Output is correct |
13 |
Correct |
4 ms |
760 KB |
Output is correct |
14 |
Correct |
7 ms |
760 KB |
Output is correct |
15 |
Correct |
9 ms |
760 KB |
Output is correct |
16 |
Correct |
8 ms |
768 KB |
Output is correct |
17 |
Correct |
7 ms |
760 KB |
Output is correct |
18 |
Correct |
7 ms |
732 KB |
Output is correct |
19 |
Correct |
7 ms |
732 KB |
Output is correct |
20 |
Correct |
7 ms |
760 KB |
Output is correct |
21 |
Correct |
2 ms |
760 KB |
Output is correct |
22 |
Correct |
8 ms |
636 KB |
Output is correct |
23 |
Correct |
7 ms |
760 KB |
Output is correct |
24 |
Correct |
8 ms |
760 KB |
Output is correct |
25 |
Correct |
7 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
11 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
400 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 |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
396 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
11 ms |
476 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
400 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
524 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
504 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
2 ms |
500 KB |
Output is correct |
46 |
Correct |
3 ms |
504 KB |
Output is correct |
47 |
Correct |
3 ms |
376 KB |
Output is correct |
48 |
Correct |
9 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
396 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
8 ms |
504 KB |
Output is correct |
14 |
Correct |
27 ms |
760 KB |
Output is correct |
15 |
Correct |
7 ms |
504 KB |
Output is correct |
16 |
Correct |
28 ms |
760 KB |
Output is correct |
17 |
Correct |
30 ms |
776 KB |
Output is correct |
18 |
Correct |
31 ms |
760 KB |
Output is correct |
19 |
Correct |
28 ms |
760 KB |
Output is correct |
20 |
Correct |
28 ms |
804 KB |
Output is correct |
21 |
Correct |
29 ms |
760 KB |
Output is correct |
22 |
Correct |
27 ms |
760 KB |
Output is correct |
23 |
Correct |
30 ms |
760 KB |
Output is correct |
24 |
Correct |
28 ms |
760 KB |
Output is correct |
25 |
Correct |
4 ms |
760 KB |
Output is correct |
26 |
Correct |
7 ms |
760 KB |
Output is correct |
27 |
Correct |
9 ms |
760 KB |
Output is correct |
28 |
Correct |
8 ms |
768 KB |
Output is correct |
29 |
Correct |
7 ms |
760 KB |
Output is correct |
30 |
Correct |
7 ms |
732 KB |
Output is correct |
31 |
Correct |
7 ms |
732 KB |
Output is correct |
32 |
Correct |
7 ms |
760 KB |
Output is correct |
33 |
Correct |
2 ms |
760 KB |
Output is correct |
34 |
Correct |
8 ms |
636 KB |
Output is correct |
35 |
Correct |
7 ms |
760 KB |
Output is correct |
36 |
Correct |
8 ms |
760 KB |
Output is correct |
37 |
Correct |
7 ms |
760 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
11 ms |
476 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
504 KB |
Output is correct |
55 |
Correct |
3 ms |
504 KB |
Output is correct |
56 |
Correct |
2 ms |
400 KB |
Output is correct |
57 |
Correct |
3 ms |
504 KB |
Output is correct |
58 |
Correct |
3 ms |
504 KB |
Output is correct |
59 |
Correct |
3 ms |
504 KB |
Output is correct |
60 |
Correct |
2 ms |
504 KB |
Output is correct |
61 |
Correct |
3 ms |
376 KB |
Output is correct |
62 |
Correct |
2 ms |
524 KB |
Output is correct |
63 |
Correct |
2 ms |
376 KB |
Output is correct |
64 |
Correct |
2 ms |
376 KB |
Output is correct |
65 |
Correct |
3 ms |
376 KB |
Output is correct |
66 |
Correct |
3 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
376 KB |
Output is correct |
68 |
Correct |
3 ms |
504 KB |
Output is correct |
69 |
Correct |
3 ms |
376 KB |
Output is correct |
70 |
Correct |
2 ms |
500 KB |
Output is correct |
71 |
Correct |
3 ms |
504 KB |
Output is correct |
72 |
Correct |
3 ms |
376 KB |
Output is correct |
73 |
Correct |
9 ms |
376 KB |
Output is correct |
74 |
Correct |
19 ms |
680 KB |
Output is correct |
75 |
Correct |
5 ms |
504 KB |
Output is correct |
76 |
Correct |
12 ms |
632 KB |
Output is correct |
77 |
Correct |
31 ms |
904 KB |
Output is correct |
78 |
Correct |
29 ms |
808 KB |
Output is correct |
79 |
Correct |
29 ms |
888 KB |
Output is correct |
80 |
Correct |
29 ms |
772 KB |
Output is correct |
81 |
Correct |
30 ms |
760 KB |
Output is correct |
82 |
Correct |
29 ms |
760 KB |
Output is correct |
83 |
Correct |
31 ms |
760 KB |
Output is correct |
84 |
Correct |
29 ms |
764 KB |
Output is correct |
85 |
Correct |
31 ms |
760 KB |
Output is correct |
86 |
Correct |
49 ms |
888 KB |
Output is correct |
87 |
Correct |
49 ms |
760 KB |
Output is correct |
88 |
Correct |
47 ms |
764 KB |
Output is correct |
89 |
Correct |
48 ms |
760 KB |
Output is correct |
90 |
Correct |
47 ms |
764 KB |
Output is correct |
91 |
Correct |
48 ms |
760 KB |
Output is correct |
92 |
Correct |
47 ms |
772 KB |
Output is correct |
93 |
Correct |
48 ms |
752 KB |
Output is correct |
94 |
Correct |
49 ms |
760 KB |
Output is correct |
95 |
Correct |
47 ms |
760 KB |
Output is correct |
96 |
Correct |
48 ms |
888 KB |
Output is correct |
97 |
Correct |
47 ms |
888 KB |
Output is correct |