Advertisement
Guest User

gfgdf

a guest
Nov 23rd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define CLR(a) memset(a,0,sizeof(a))
  5. #define SET(a) memset(a,-1,sizeof(a))
  6. #define pb push_back
  7. #define ALL(a) a.begin(),a.end()
  8. #define IT iterator
  9. #define ff first
  10. #define ss second
  11. #define MP make_pair
  12. #define EPS 1e-9
  13. #define INF 1000000007
  14.  
  15. typedef long long Long;
  16.  
  17. #define MAX 1000007
  18. #define MOD 1000000009
  19.  
  20. char str[3][MAX+7];
  21. long vi[MAX+7][2][2],TRUE;
  22. Long tot[MAX+7][2][2];
  23. long Lim;
  24.  
  25. long totCand( char c1, char c2, long t ){
  26.     if( c1==0 ) c1 = 'a'-1;
  27.     if( c2==0 ) c2 = 'a'-1;
  28.     int v = 0;
  29.     if( t==-1 ){
  30.         if( c1=='?' ) v = c2-'a';
  31.         else v = c1<c2;
  32.     }
  33.     else if( t==0 ){
  34.         if( c1=='?' ) v = 1;
  35.         else v = c1==c2;
  36.     }
  37.     else if( t==1 ){
  38.         if( c1=='?' ) v = 'z'-c2;
  39.         else v = c1>c2;
  40.     }
  41.     return max( v,0 );
  42. }
  43.  
  44. Long Find( long I, bool e1, bool e2 ){
  45.     if( I==Lim ) return e1==false and e2==false;
  46.     if( vi[I][e1][e2]==TRUE ) return tot[I][e1][e2];
  47.     vi[I][e1][e2] = TRUE;
  48.     tot[I][e1][e2] = 0;
  49.     Long i,j,k;
  50.     vector<char> cand;
  51.     if( str[1][I]!='?' ) cand.pb( str[1][I] );
  52.     else{
  53.         for( i='a';i<='z';i++ ) cand.pb( i );
  54.     }
  55.     for( k=0;k<cand.size();k++ ){
  56.         char c = cand[k];
  57.         for( i=-1;i<=1;i++ ){
  58.             for( j=-1;j<=1;j++ ){
  59.                 long cnt1 = 0, cnt2 = 0;
  60.                 bool te1,te2;
  61.                 if( i==-1 ) cnt1 = totCand( str[0][I], c, -1 ), te1 = false;
  62.                 else if( i==0 ) cnt1 = totCand( str[0][I], c, 0 ), te1 = e1;
  63.                 else if( i==1 ) cnt1 = (e1==false)*totCand( str[0][I], c, 1 ), te1 = false;
  64.  
  65.                 if( j==-1 ) cnt2 = (e2==false)*totCand( str[2][I], c, -1 ), te2 = false;
  66.                 else if( j==0 ) cnt2 = totCand( str[2][I], c, 0 ), te2 = e1;
  67.                 else if( j==1 ) cnt2 = totCand( str[2][I], c, 1 ), te2 = false;
  68.  
  69.                 tot[I][e1][e2] += cnt1*cnt2*Find( I+1, te1, te2 );//cout<<
  70.             }
  71.         }
  72.     }
  73.     tot[I][e1][e2] %= MOD;
  74.     return tot[I][e1][e2];
  75. }
  76.  
  77. int main( void )
  78. {
  79.     long i,j,u,Icase,k=0;
  80.  
  81.     freopen("text1.txt","r",stdin );
  82.  
  83.     cin>>Icase;
  84.     while( Icase-- ){
  85.         Lim = 0;
  86.         CLR( str );
  87.         for( i=0;i<3;i++ ){
  88.             scanf("%s",str[i] );
  89.             Lim = max( Lim, (long)strlen( str[i] ) );
  90.         }
  91.         TRUE++;
  92.         long ans = Find( 0,true,true );
  93.         cout<<ans<<endl;
  94.     }
  95.  
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement