Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*===============*\
- | ID: TMANDZU |
- | LANG: C++ |
- \*===============*/
- //Tornike Mandzulashvili
- //std::ios_base::sync_with_stdio (false);
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <algorithm>
- #include <stack>
- #include <math.h>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <map>
- #include <assert.h>
- #include <queue>
- #include <iostream>
- #include <set>
- #include <cstring>
- #include <deque>
- #include <fstream>
- #include <bitset>
- #define endl '\n'
- #define deb(x) cout << "> " << #x << " : " << (x) << endl;
- #define EPS 0.0000001
- #define Pi 3.1415926535897932384626433832795028841971
- #define hash1 1000003
- #define hash2 1000033
- #define md 1000000009
- #define INF ((1<<30)-1)
- #define pb push_back
- #define mp make_pair
- #define S size()
- #define MX(aa,bb) (aa>bb?aa:bb)
- #define MN(aa,bb) (aa<bb?aa:bb)
- #define fi first
- #define se second
- #define PI pair < int , int >
- #define REP(i,a,n) for(i=a;i<n;i++)
- #define sc scanf
- #define pt printf
- #define big long long
- #define VI vector < int >
- #define DID (long long)
- #define ll long long
- #define AL(a) (a).begin(),(a).end()
- #define INFF DID INF*INF
- #define debug 1
- using namespace std;
- const int T = 1e6 + 5;
- char a[T],b[T],c[T];
- ll dp[T][2][2];
- int CNT[2][2][2][2][30][30][30];
- int get(char k){
- if (k=='?')
- return 26;
- return k-'a';
- }
- void pre(){
- int i=1;
- for (int x=0;x<2;x++)
- for (int y=0;y<2;y++){
- for (int newx=0;newx<2;newx++)
- for (int newy=0;newy<2;newy++)
- for (a[i-1]='a';(a[i-1]>='a' && a[i-1]<='z'+1) || a[i-1]=='?';a[i-1] = (a[i-1] == ('z'+1) ? '?' : a[i-1]+1))
- for (b[i-1]='a';(b[i-1]>='a' && b[i-1]<='z'+1) || b[i-1]=='?';b[i-1] = (b[i-1] == ('z'+1) ? '?' : b[i-1]+1))
- for (c[i-1]='a';(c[i-1]>='a' && c[i-1]<='z'+1) || c[i-1]=='?';c[i-1] = (c[i-1] == ('z'+1) ? '?' : c[i-1]+1)){
- if (x && !newx)
- continue;
- if (y && !newy)
- continue;
- char st = 'a'+1,fn = 'z'+ 1;
- if (b[i-1]!='?')
- st = b[i-1] , fn = b[i-1];
- ll num = 0;
- for (char ch = st;ch<=fn;ch++){
- int raod1 = 1;
- if (y && newy){
- raod1*=(a[i-1]=='?' ? 26 : 1);
- }
- if (!y && newy){
- if (a[i-1]=='?')
- raod1*=(int)(ch-'a'-1);
- else
- if (a[i-1]<ch)
- raod1 *= 1;
- else
- raod1=0;
- }
- if (!y && !newy){
- if (a[i-1]=='?' || a[i-1]==ch)
- raod1*=1;
- else
- raod1=0;
- }
- int raod2 = 1;
- if (x && newx){
- raod2*=(c[i-1]=='?' ? 26 : 1);
- }
- if (!x && newx){
- if (c[i-1]=='?')
- raod2*=(int)('z'+1-ch);
- else
- if (c[i-1]>ch)
- raod2 *= 1;
- else
- raod2=0;
- }
- if (!x && !newx){
- if (c[i-1]=='?' || c[i-1]==ch)
- raod2*=1;
- else
- raod2=0;
- }
- num+=raod1*raod2;
- }
- CNT[x][y][newx][newy][a[i-1] == '?' ? 26 : (int)(a[i-1]-'a')][b[i-1] == '?' ? 26 : (int)(b[i-1]-'a')][c[i-1] == '?' ? 26 : (int)(c[i-1]-'a')]=num;
- }
- }
- }
- int main(){
- /* #ifndef ONLINE_JUDGE
- freopen("text.in","r",stdin); //freopen("text.out","w",stdout);
- #endif
- */
- //freopen("text.in","r",stdin);
- pre();
- int t;
- scanf("%d\n",&t);
- while (t--){
- int la = 0,lb = 0,lc = 0;
- while (1){
- char ch = getchar();
- if (ch == '\n')
- break;
- if (ch!='?')
- ch++;
- a[la++]=ch;
- }
- while (1){
- char ch = getchar();
- if (ch == '\n')
- break;
- if (ch!='?')
- ch++;
- b[lb++]=ch;
- }
- while (1){
- char ch = getchar();
- if (ch == '\n')
- break;
- if (ch!='?')
- ch++;
- c[lc++]=ch;
- }
- int n = 0;
- n = max(n,(int)la);
- n = max(n,(int)lb);
- n = max(n,(int)lc);
- for (int i=la;i<n;i++)
- a[i]='a';
- for (int i=lb;i<n;i++)
- b[i]='a';
- for (int i=lc;i<n;i++)
- c[i]='a';
- dp[0][0][0]=1;
- for (int i=1;i<=n;i++){
- int A = a[i-1] == '?' ? 26 : a[i-1]-'a';
- int B = b[i-1] == '?' ? 26 : b[i-1]-'a';
- int C = c[i-1] == '?' ? 26 : c[i-1]-'a';
- for (int newx=0;newx<2;newx++)
- for (int newy=0;newy<2;newy++){
- for (int x=0;x<2;x++)
- for (int y=0;y<2;y++){
- dp[i][newx][newy]+=dp[i-1][x][y]*CNT[x][y][newx][newy][A][B][C];
- }
- dp[i][newx][newy]%=md;
- }
- }
- printf("%d\n",dp[n][1][1]);
- for (int i=0;i<=n+2;i++){
- for (int x=0;x<2;x++)
- for (int y=0;y<2;y++)
- dp[i][x][y]=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement