Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.96 KB | None | 0 0
  1.  
  2. /*===============*\
  3. |  ID: TMANDZU    |
  4. |    LANG: C++    |
  5. \*===============*/
  6. //Tornike Mandzulashvili
  7. //std::ios_base::sync_with_stdio (false);
  8.  
  9. #include <time.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <algorithm>
  13. #include <stack>
  14. #include <math.h>
  15. #include <vector>
  16. #include <string>
  17. #include <iomanip>
  18. #include <map>
  19. #include <assert.h>
  20. #include <queue>
  21. #include <iostream>
  22. #include <set>
  23. #include <cstring>
  24. #include <deque>
  25. #include <fstream>
  26. #include <bitset>
  27.  
  28. #define endl '\n'
  29. #define deb(x) cout << "> " << #x << " : " << (x) << endl;
  30. #define EPS 0.0000001
  31. #define Pi 3.1415926535897932384626433832795028841971
  32. #define hash1 1000003
  33. #define hash2 1000033
  34. #define md 1000000009
  35. #define INF ((1<<30)-1)
  36. #define pb push_back
  37. #define mp make_pair
  38. #define S size()
  39. #define MX(aa,bb) (aa>bb?aa:bb)
  40. #define MN(aa,bb) (aa<bb?aa:bb)
  41. #define fi first
  42. #define se second
  43. #define PI pair < int , int >
  44. #define REP(i,a,n) for(i=a;i<n;i++)
  45. #define sc scanf
  46. #define pt printf
  47. #define big long long
  48. #define VI vector < int >
  49. #define DID (long long)
  50. #define ll long long
  51. #define AL(a) (a).begin(),(a).end()
  52. #define INFF DID INF*INF
  53. #define debug 1
  54.  
  55. using namespace std;
  56.  
  57. const int T = 1e6 + 5;
  58.  
  59. char a[T],b[T],c[T];
  60. ll dp[T][2][2];
  61. int CNT[2][2][2][2][30][30][30];
  62.  
  63. int get(char k){
  64.     if (k=='?')
  65.         return 26;
  66.     return k-'a';
  67. }
  68.  
  69. void pre(){
  70.             int i=1;
  71.             for (int x=0;x<2;x++)
  72.             for (int y=0;y<2;y++){
  73.                 for (int newx=0;newx<2;newx++)
  74.                 for (int newy=0;newy<2;newy++)
  75.                     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))
  76.                     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))
  77.                     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)){
  78.                     if (x && !newx)
  79.                         continue;
  80.                     if (y && !newy)
  81.                         continue;
  82.                     char st = 'a'+1,fn = 'z'+ 1;
  83.                     if (b[i-1]!='?')
  84.                         st = b[i-1] , fn = b[i-1];
  85.  
  86.                     ll num = 0;
  87.                     for (char ch = st;ch<=fn;ch++){
  88.                         int raod1 = 1;
  89.                         if (y && newy){
  90.                             raod1*=(a[i-1]=='?' ? 26 : 1);
  91.                         }
  92.                         if (!y && newy){
  93.                             if (a[i-1]=='?')
  94.                                 raod1*=(int)(ch-'a'-1);
  95.                             else
  96.                             if (a[i-1]<ch)
  97.                                 raod1 *= 1;
  98.                             else
  99.                                 raod1=0;
  100.                         }
  101.                         if (!y && !newy){
  102.                             if (a[i-1]=='?' || a[i-1]==ch)
  103.                                 raod1*=1;
  104.                             else
  105.                                 raod1=0;
  106.                         }
  107.  
  108.                         int raod2 = 1;
  109.                         if (x && newx){
  110.                             raod2*=(c[i-1]=='?' ? 26 : 1);
  111.                         }
  112.                         if (!x && newx){
  113.                             if (c[i-1]=='?')
  114.                                 raod2*=(int)('z'+1-ch);
  115.                             else
  116.                             if (c[i-1]>ch)
  117.                                 raod2 *= 1;
  118.                             else
  119.                                 raod2=0;
  120.                         }
  121.                         if (!x && !newx){
  122.                             if (c[i-1]=='?' || c[i-1]==ch)
  123.                                 raod2*=1;
  124.                             else
  125.                                 raod2=0;
  126.                         }
  127.  
  128.                         num+=raod1*raod2;
  129.                     }
  130.                     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;
  131.                 }
  132.             }
  133. }
  134.  
  135. int main(){
  136.  /*   #ifndef ONLINE_JUDGE
  137.         freopen("text.in","r",stdin);  //freopen("text.out","w",stdout);
  138.     #endif
  139. */
  140. //freopen("text.in","r",stdin);
  141.     pre();
  142.  
  143.     int t;
  144.     scanf("%d\n",&t);
  145.     while (t--){
  146.         int la = 0,lb = 0,lc = 0;
  147.         while (1){
  148.             char ch = getchar();
  149.             if (ch == '\n')
  150.                 break;
  151.             if (ch!='?')
  152.                 ch++;
  153.             a[la++]=ch;
  154.         }
  155.         while (1){
  156.             char ch = getchar();
  157.             if (ch == '\n')
  158.                 break;
  159.             if (ch!='?')
  160.                 ch++;
  161.             b[lb++]=ch;
  162.         }
  163.         while (1){
  164.             char ch = getchar();
  165.             if (ch == '\n')
  166.                 break;
  167.             if (ch!='?')
  168.                 ch++;
  169.             c[lc++]=ch;
  170.         }
  171.         int n = 0;
  172.         n = max(n,(int)la);
  173.         n = max(n,(int)lb);
  174.         n = max(n,(int)lc);
  175.  
  176.         for (int i=la;i<n;i++)
  177.             a[i]='a';
  178.         for (int i=lb;i<n;i++)
  179.             b[i]='a';
  180.         for (int i=lc;i<n;i++)
  181.             c[i]='a';
  182.  
  183.  
  184.         dp[0][0][0]=1;
  185.         for (int i=1;i<=n;i++){
  186.             int A = a[i-1] == '?' ? 26 : a[i-1]-'a';
  187.             int B = b[i-1] == '?' ? 26 : b[i-1]-'a';
  188.             int C = c[i-1] == '?' ? 26 : c[i-1]-'a';
  189.             for (int newx=0;newx<2;newx++)
  190.             for (int newy=0;newy<2;newy++){
  191.             for (int x=0;x<2;x++)
  192.             for (int y=0;y<2;y++){
  193.                     dp[i][newx][newy]+=dp[i-1][x][y]*CNT[x][y][newx][newy][A][B][C];
  194.                 }
  195.                 dp[i][newx][newy]%=md;
  196.             }
  197.         }
  198.  
  199.         printf("%d\n",dp[n][1][1]);
  200.  
  201.         for (int i=0;i<=n+2;i++){
  202.             for (int x=0;x<2;x++)
  203.                 for (int y=0;y<2;y++)
  204.                 dp[i][x][y]=0;
  205.         }
  206.  
  207.     }
  208.  
  209.  
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement