# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365444 | 2021-02-11T17:02:44 Z | arnold518 | Solitaire (JOI16_solitaire) | C++14 | 2000 ms | 12268 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 6000; const ll MOD = 1e9+7; int N, cnt; char S[4][MAXN+10]; int A[4][MAXN+10]; int B[MAXN+10]; ll fac[MAXN+10], ifac[MAXN+10]; ll ans; ll dp1[MAXN+10][MAXN+10], dp2[MAXN+10][MAXN+10]; ll mypow(ll x, ll y) { if(y==0) return 1; if(y%2) return mypow(x, y-1)*x%MOD; ll t=mypow(x, y/2); return t*t%MOD; } ll inv(ll x) { return mypow(x, MOD-2); } ll ncr(ll n, ll r) { if(n<r) return 0; return fac[n]*ifac[r]%MOD*ifac[n-r]%MOD; } ll npr(ll n, ll r) { if(n<r) return 0; return fac[n]*ifac[n-r]%MOD; } int main() { fac[0]=1; ifac[0]=1; for(int i=1; i<=MAXN; i++) fac[i]=fac[i-1]*i%MOD; for(int i=1; i<=MAXN; i++) ifac[i]=inv(fac[i]); scanf("%d", &N); scanf(" %s", S[1]+1); scanf(" %s", S[2]+1); scanf(" %s", S[3]+1); for(int i=1; i<=N; i++) { A[1][i]=(S[1][i]=='x'); A[2][i]=(S[2][i]=='x'); A[3][i]=(S[3][i]=='x'); } A[1][0]=1; A[1][N+1]=1; A[2][0]=1; A[2][N+1]=1; A[3][0]=1; A[3][N+1]=1; for(int i=1; i<=N; i++) { if(A[1][i]) { if(A[1][i-1] || A[1][i+1]) { return !printf("0\n"); } } } for(int i=1; i<=N; i++) { if(A[3][i]) { if(A[3][i-1] || A[3][i+1]) { return !printf("0\n"); } } } int cnt=0; for(int i=1; i<=N; i++) { if(A[2][i]==0) { B[i]=-1; cnt+=A[1][i]+A[3][i]; } else { B[i]=A[1][i]+A[3][i]; } } int sz=0; vector<ll> V; vector<int> VV; VV.push_back(0); for(int i=1; i<=N; i++) if(B[i]==-1) VV.push_back(i); VV.push_back(N+1); sz=cnt; ans=fac[cnt]; for(int i=0; i+1<VV.size(); i++) { int l=VV[i]+1, r=VV[i+1]-1; if(l>r) continue; int val=0; for(int j=1; j<=B[l]; j++) dp1[l][j]=fac[B[l]]; dp2[l][B[l]+1]=fac[B[l]]; val+=B[l]+1; if(l==1) { for(int j=1; j<=B[l]; j++) dp1[l][j]=0; } for(int j=l+1; j<=r; j++) { for(int k=1; k<=val+B[j]+1; k++) { for(int p=B[j]; p<=B[j]; p++) { ll t=ncr(B[j], p)*npr(k-1, p)%MOD*npr(val+B[j]+1-k, B[j]-p)%MOD; for(int q=1; q<=val; q++) { dp2[j][k]+=dp2[j-1][q]*t%MOD; dp2[j][k]%=MOD; } for(int q=k-p; q<=val; q++) { dp2[j][k]+=dp1[j-1][q]*t%MOD; dp2[j][k]%=MOD; } } for(int p=0; p<B[j]; p++) { ll t=ncr(B[j], p)*npr(k-1, p)%MOD*npr(val+B[j]+1-k, B[j]-p)%MOD; for(int q=0; q<k-p; q++) { dp1[j][k]+=dp2[j-1][q]*t%MOD; dp1[j][k]%=MOD; } } } val+=B[j]+1; } ll t=0; for(int j=1; j<=val; j++) { if(r!=N) { t+=dp1[r][j]; t%=MOD; } t+=dp2[r][j]; t%=MOD; } ans=ans*ncr(sz+val, sz)%MOD*t%MOD; sz+=val; } printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 492 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 3 ms | 492 KB | Output is correct |
6 | Correct | 3 ms | 492 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 492 KB | Output is correct |
11 | Correct | 2 ms | 492 KB | Output is correct |
12 | Correct | 2 ms | 492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3564 KB | Output is correct |
2 | Correct | 6 ms | 6124 KB | Output is correct |
3 | Correct | 4 ms | 2540 KB | Output is correct |
4 | Correct | 8 ms | 8172 KB | Output is correct |
5 | Correct | 7 ms | 7660 KB | Output is correct |
6 | Correct | 8 ms | 7276 KB | Output is correct |
7 | Correct | 6 ms | 4972 KB | Output is correct |
8 | Correct | 8 ms | 8172 KB | Output is correct |
9 | Correct | 8 ms | 8428 KB | Output is correct |
10 | Correct | 5 ms | 4844 KB | Output is correct |
11 | Correct | 6 ms | 6380 KB | Output is correct |
12 | Correct | 8 ms | 8300 KB | Output is correct |
13 | Correct | 277 ms | 10604 KB | Output is correct |
14 | Correct | 505 ms | 11264 KB | Output is correct |
15 | Correct | 815 ms | 11756 KB | Output is correct |
16 | Correct | 308 ms | 10712 KB | Output is correct |
17 | Correct | 801 ms | 11756 KB | Output is correct |
18 | Correct | 478 ms | 11116 KB | Output is correct |
19 | Correct | 689 ms | 11372 KB | Output is correct |
20 | Correct | 812 ms | 11548 KB | Output is correct |
21 | Correct | 767 ms | 11628 KB | Output is correct |
22 | Correct | 1117 ms | 12268 KB | Output is correct |
23 | Correct | 742 ms | 11788 KB | Output is correct |
24 | Correct | 896 ms | 12012 KB | Output is correct |
25 | Correct | 890 ms | 12140 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 492 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 492 KB | Output is correct |
6 | Correct | 2 ms | 492 KB | Output is correct |
7 | Correct | 3 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 492 KB | Output is correct |
11 | Correct | 2 ms | 492 KB | Output is correct |
12 | Correct | 2 ms | 492 KB | Output is correct |
13 | Correct | 3 ms | 620 KB | Output is correct |
14 | Correct | 3 ms | 620 KB | Output is correct |
15 | Correct | 3 ms | 620 KB | Output is correct |
16 | Correct | 3 ms | 620 KB | Output is correct |
17 | Correct | 3 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 620 KB | Output is correct |
19 | Correct | 3 ms | 620 KB | Output is correct |
20 | Correct | 3 ms | 620 KB | Output is correct |
21 | Correct | 3 ms | 620 KB | Output is correct |
22 | Correct | 3 ms | 620 KB | Output is correct |
23 | Correct | 3 ms | 620 KB | Output is correct |
24 | Correct | 3 ms | 620 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 492 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 3 ms | 492 KB | Output is correct |
6 | Correct | 3 ms | 492 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 492 KB | Output is correct |
11 | Correct | 2 ms | 492 KB | Output is correct |
12 | Correct | 2 ms | 492 KB | Output is correct |
13 | Correct | 3 ms | 492 KB | Output is correct |
14 | Correct | 2 ms | 492 KB | Output is correct |
15 | Correct | 2 ms | 492 KB | Output is correct |
16 | Correct | 2 ms | 492 KB | Output is correct |
17 | Correct | 2 ms | 492 KB | Output is correct |
18 | Correct | 2 ms | 492 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 2 ms | 492 KB | Output is correct |
21 | Correct | 2 ms | 492 KB | Output is correct |
22 | Correct | 2 ms | 492 KB | Output is correct |
23 | Correct | 2 ms | 492 KB | Output is correct |
24 | Correct | 2 ms | 492 KB | Output is correct |
25 | Correct | 3 ms | 620 KB | Output is correct |
26 | Correct | 3 ms | 620 KB | Output is correct |
27 | Correct | 3 ms | 620 KB | Output is correct |
28 | Correct | 3 ms | 620 KB | Output is correct |
29 | Correct | 3 ms | 748 KB | Output is correct |
30 | Correct | 3 ms | 620 KB | Output is correct |
31 | Correct | 3 ms | 620 KB | Output is correct |
32 | Correct | 3 ms | 620 KB | Output is correct |
33 | Correct | 3 ms | 620 KB | Output is correct |
34 | Correct | 3 ms | 620 KB | Output is correct |
35 | Correct | 3 ms | 620 KB | Output is correct |
36 | Correct | 3 ms | 620 KB | Output is correct |
37 | Correct | 3 ms | 620 KB | Output is correct |
38 | Correct | 3 ms | 876 KB | Output is correct |
39 | Correct | 3 ms | 620 KB | Output is correct |
40 | Correct | 3 ms | 1644 KB | Output is correct |
41 | Correct | 3 ms | 1132 KB | Output is correct |
42 | Correct | 3 ms | 1260 KB | Output is correct |
43 | Correct | 3 ms | 1516 KB | Output is correct |
44 | Correct | 3 ms | 1132 KB | Output is correct |
45 | Correct | 3 ms | 1644 KB | Output is correct |
46 | Correct | 3 ms | 1388 KB | Output is correct |
47 | Correct | 3 ms | 1516 KB | Output is correct |
48 | Correct | 3 ms | 1772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 492 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 3 ms | 492 KB | Output is correct |
6 | Correct | 3 ms | 492 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 492 KB | Output is correct |
11 | Correct | 2 ms | 492 KB | Output is correct |
12 | Correct | 2 ms | 492 KB | Output is correct |
13 | Correct | 5 ms | 3564 KB | Output is correct |
14 | Correct | 6 ms | 6124 KB | Output is correct |
15 | Correct | 4 ms | 2540 KB | Output is correct |
16 | Correct | 8 ms | 8172 KB | Output is correct |
17 | Correct | 7 ms | 7660 KB | Output is correct |
18 | Correct | 8 ms | 7276 KB | Output is correct |
19 | Correct | 6 ms | 4972 KB | Output is correct |
20 | Correct | 8 ms | 8172 KB | Output is correct |
21 | Correct | 8 ms | 8428 KB | Output is correct |
22 | Correct | 5 ms | 4844 KB | Output is correct |
23 | Correct | 6 ms | 6380 KB | Output is correct |
24 | Correct | 8 ms | 8300 KB | Output is correct |
25 | Correct | 277 ms | 10604 KB | Output is correct |
26 | Correct | 505 ms | 11264 KB | Output is correct |
27 | Correct | 815 ms | 11756 KB | Output is correct |
28 | Correct | 308 ms | 10712 KB | Output is correct |
29 | Correct | 801 ms | 11756 KB | Output is correct |
30 | Correct | 478 ms | 11116 KB | Output is correct |
31 | Correct | 689 ms | 11372 KB | Output is correct |
32 | Correct | 812 ms | 11548 KB | Output is correct |
33 | Correct | 767 ms | 11628 KB | Output is correct |
34 | Correct | 1117 ms | 12268 KB | Output is correct |
35 | Correct | 742 ms | 11788 KB | Output is correct |
36 | Correct | 896 ms | 12012 KB | Output is correct |
37 | Correct | 890 ms | 12140 KB | Output is correct |
38 | Correct | 3 ms | 492 KB | Output is correct |
39 | Correct | 2 ms | 492 KB | Output is correct |
40 | Correct | 2 ms | 492 KB | Output is correct |
41 | Correct | 2 ms | 492 KB | Output is correct |
42 | Correct | 2 ms | 492 KB | Output is correct |
43 | Correct | 2 ms | 492 KB | Output is correct |
44 | Correct | 3 ms | 512 KB | Output is correct |
45 | Correct | 2 ms | 492 KB | Output is correct |
46 | Correct | 2 ms | 492 KB | Output is correct |
47 | Correct | 2 ms | 492 KB | Output is correct |
48 | Correct | 2 ms | 492 KB | Output is correct |
49 | Correct | 2 ms | 492 KB | Output is correct |
50 | Correct | 3 ms | 620 KB | Output is correct |
51 | Correct | 3 ms | 620 KB | Output is correct |
52 | Correct | 3 ms | 620 KB | Output is correct |
53 | Correct | 3 ms | 620 KB | Output is correct |
54 | Correct | 3 ms | 748 KB | Output is correct |
55 | Correct | 3 ms | 620 KB | Output is correct |
56 | Correct | 3 ms | 620 KB | Output is correct |
57 | Correct | 3 ms | 620 KB | Output is correct |
58 | Correct | 3 ms | 620 KB | Output is correct |
59 | Correct | 3 ms | 620 KB | Output is correct |
60 | Correct | 3 ms | 620 KB | Output is correct |
61 | Correct | 3 ms | 620 KB | Output is correct |
62 | Correct | 3 ms | 620 KB | Output is correct |
63 | Correct | 3 ms | 876 KB | Output is correct |
64 | Correct | 3 ms | 620 KB | Output is correct |
65 | Correct | 3 ms | 1644 KB | Output is correct |
66 | Correct | 3 ms | 1132 KB | Output is correct |
67 | Correct | 3 ms | 1260 KB | Output is correct |
68 | Correct | 3 ms | 1516 KB | Output is correct |
69 | Correct | 3 ms | 1132 KB | Output is correct |
70 | Correct | 3 ms | 1644 KB | Output is correct |
71 | Correct | 3 ms | 1388 KB | Output is correct |
72 | Correct | 3 ms | 1516 KB | Output is correct |
73 | Correct | 3 ms | 1772 KB | Output is correct |
74 | Correct | 7 ms | 6656 KB | Output is correct |
75 | Correct | 5 ms | 3564 KB | Output is correct |
76 | Correct | 5 ms | 4108 KB | Output is correct |
77 | Correct | 9 ms | 9068 KB | Output is correct |
78 | Correct | 10 ms | 9324 KB | Output is correct |
79 | Correct | 6 ms | 5740 KB | Output is correct |
80 | Correct | 9 ms | 8940 KB | Output is correct |
81 | Correct | 7 ms | 7788 KB | Output is correct |
82 | Correct | 9 ms | 9068 KB | Output is correct |
83 | Correct | 6 ms | 5996 KB | Output is correct |
84 | Correct | 5 ms | 5100 KB | Output is correct |
85 | Correct | 8 ms | 8044 KB | Output is correct |
86 | Execution timed out | 2072 ms | 8636 KB | Time limit exceeded |
87 | Halted | 0 ms | 0 KB | - |