1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * ޱ BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) #define lbound(v,x) lower_bound(all(v),x)-v.begin() mt19937 sd(random_device{}()); int qpow(int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } int exgcd(int x,int y,int &a,int &b){ if(y==0){ a=1;b=0; return x; } int d=exgcd(y,x%y,a,b); int z=b; b=a-b*(x/y); a=z; return d; } int _x_,_y_; inline int inverse(int x,int y=MOD){ exgcd(x,y,_x_,_y_); return (_x_+y)%y; } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } int n; string s[3]; int f[2005][6005][2]; int a[2005]; int A(int x,int y){ return fac[x+y]*inv[x]%MOD; } void Main() { cin>>n; cin>>s[1]>>s[0]>>s[2]; REP(i,1,3){ REP(j,1,n)if(s[i][j]=='x'&&s[i][j-1]=='x')over(0) } if(s[1][0]=='x'||s[1][n-1]=='x'||s[2][0]=='x'||s[2][n-1]=='x')over(0) vector<int>v; REP(i,1,3){ REP(j,0,n)if(s[i][j]=='x'&&s[0][j]=='o')v.pb(1); } REP(i,0,n)REP(j,0,3)a[i]+=s[j][i]=='x'; REP(i,0,n)if(s[0][i]=='x'){ int x=i,sum=0; while(x<n&&s[0][x]=='x'){ sum+=a[x]; ++x; } i=x; v.pb(sum); } int sum=0,ans=1; init(n*3); for(auto i:v)(ans*=binom(sum+=i,i))%=MOD; REP(l,0,n)if(s[0][l]=='x'){ int r=l,sum=0; while(r<n&&s[0][r]=='x'){ sum+=a[r]; ++r; } --r; REP(i,l,r+1)REP(j,0,sum+1)REP(p,0,2)f[i][j][p]=0; if(l==0){ f[l][a[l]-1][0]=f[l][a[l]-1][1]=fac[a[l]-1]; }else{ REP(i,0,a[l]){ f[l][i][0]=fac[a[l]-1]; f[l][i][1]=i==a[l]-1? fac[i]:0; } } sum=a[l]; REP(i,l+1,r+1){ int S=0; REP(j,1,sum+1){// Լ ǰ (S+=f[i-1][j-1][1])%=MOD; REP(p,0,a[i]){//ѡ Լ λ ã м Լ ǰ REP(o,0,2)if(o==0||p==a[i]-1){// ұߵ ״̬ (f[i][j+p][o]+=S*A(j,p)%MOD*A(sum-j,a[i]-1-p)*binom(a[i]-1,p))%=MOD; } } } S=0; for(int j=sum-1;j>=0;--j){ (S+=f[i-1][j][0])%=MOD; REP(o,0,2){ (f[i][j+a[i]-1][o]+=S*A(j,a[i]-1))%=MOD; } } sum+=a[i]; } int res=0; if(r==n-1){ REP(i,0,sum){ (res+=f[r][i][1])%=MOD; } }else{ REP(i,0,sum){ (res+=f[r][i][0])%=MOD; } } (ans*=res)%=MOD; l=r; } over(ans) } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("chessmen.in","r",stdin); freopen("chessmen.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 3081
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By