Submission #105832

#TimeUsernameProblemLanguageResultExecution timeMemory
105832Pro_ktmrSolitaire (JOI16_solitaire)C++14
10 / 100
10 ms896 KiB
#include<bits/stdc++.h> using namespace std; #define LL long long #define MP(a,b) make_pair(a,b) #define MOD 1000000007 int N; string S[3]; int st[3][2000]; LL wa[2000]; int c = 0; LL dp[1<<16] = {}; LL solve(int now){ if(now == (1<<c)-1) return 1; if(dp[now] != 0) return dp[now]; LL re = 0; if(st[1][0] == 0 && (now>>0)%2 == 0) re += solve(now+(1<<0)); for(int i=1; i<N-1; i++){ if( st[0][i] != -1 && (now>>st[0][i])%2 == 0 && (st[0][i-1] == -1 || (now>>st[0][i-1])%2 == 1) && (st[0][i+1] == -1 || (now>>st[0][i+1])%2 == 1) ) re += solve(now+(1<<st[0][i])); if( st[2][i] != -1 && (now>>st[2][i])%2 == 0 && (st[2][i-1] == -1 || (now>>st[2][i-1])%2 == 1) && (st[2][i+1] == -1 || (now>>st[2][i+1])%2 == 1) ) re += solve(now+(1<<st[2][i])); if( st[1][i] != -1 && (now>>st[1][i])%2 == 0 && (st[1][i-1] == -1 || (now>>st[1][i-1])%2 == 1) && (st[1][i+1] == -1 || (now>>st[1][i+1])%2 == 1) ) re += solve(now+(1<<st[1][i])); else if( st[1][i] != -1 && (now>>st[1][i])%2 == 0 && (st[0][i] == -1 || (now>>st[0][i])%2 == 1) && (st[2][i] == -1 || (now>>st[2][i])%2 == 1) ) re += solve(now+(1<<st[1][i])); } if(st[1][N-1] == c-1 && (now>>(c-1))%2 == 0) re += solve(now+(1<<(c-1))); return dp[now] = re % MOD; } int main(){ cin >> N >> S[0] >> S[1] >> S[2]; if(S[0][0] == 'x' || S[0][N-1] == 'x' || S[2][0] == 'x' || S[2][N-1] == 'x'){ cout << 0 << endl; return 0; } for(int i=0; i<N-1; i++){ if(S[0][i] == 'x' && S[0][i+1] == 'x'){ cout << 0 << endl; return 0; } if(S[2][i] == 'x' && S[2][i+1] == 'x'){ cout << 0 << endl; return 0; } } for(int i=0; i<N; i++){ if(S[0][i] == 'o') st[0][i] = -1; else{ st[0][i] = c; c++; } if(S[1][i] == 'o') st[1][i] = -1; else{ st[1][i] = c; c++; } if(S[2][i] == 'o') st[2][i] = -1; else{ st[2][i] = c; c++; } } if(c > 16) return -1; cout << solve(0) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...