Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define CLR(a) memset(a,0,sizeof(a))
- #define SET(a) memset(a,-1,sizeof(a))
- #define pb push_back
- #define ALL(a) a.begin(),a.end()
- #define IT iterator
- #define ff first
- #define ss second
- #define MP make_pair
- #define EPS 1e-9
- #define INF 1000000007
- typedef long long Long;
- #define MAX 1000007
- #define MOD 1000000009
- char str[3][MAX+7];
- long vi[MAX+7][2][2],TRUE;
- Long tot[MAX+7][2][2];
- long Lim;
- long totCand( char c1, char c2, long t ){
- if( c1==0 ) c1 = 'a'-1;
- if( c2==0 ) c2 = 'a'-1;
- int v = 0;
- if( t==-1 ){
- if( c1=='?' ) v = c2-'a';
- else v = c1<c2;
- }
- else if( t==0 ){
- if( c1=='?' ) v = 1;
- else v = c1==c2;
- }
- else if( t==1 ){
- if( c1=='?' ) v = 'z'-c2;
- else v = c1>c2;
- }
- return max( v,0 );
- }
- Long Find( long I, bool e1, bool e2 ){
- if( I==Lim ) return e1==false and e2==false;
- if( vi[I][e1][e2]==TRUE ) return tot[I][e1][e2];
- vi[I][e1][e2] = TRUE;
- tot[I][e1][e2] = 0;
- Long i,j,k;
- vector<char> cand;
- if( str[1][I]!='?' ) cand.pb( str[1][I] );
- else{
- for( i='a';i<='z';i++ ) cand.pb( i );
- }
- for( k=0;k<cand.size();k++ ){
- char c = cand[k];
- for( i=-1;i<=1;i++ ){
- for( j=-1;j<=1;j++ ){
- long cnt1 = 0, cnt2 = 0;
- bool te1,te2;
- if( i==-1 ) cnt1 = totCand( str[0][I], c, -1 ), te1 = false;
- else if( i==0 ) cnt1 = totCand( str[0][I], c, 0 ), te1 = e1;
- else if( i==1 ) cnt1 = (e1==false)*totCand( str[0][I], c, 1 ), te1 = false;
- if( j==-1 ) cnt2 = (e2==false)*totCand( str[2][I], c, -1 ), te2 = false;
- else if( j==0 ) cnt2 = totCand( str[2][I], c, 0 ), te2 = e1;
- else if( j==1 ) cnt2 = totCand( str[2][I], c, 1 ), te2 = false;
- tot[I][e1][e2] += cnt1*cnt2*Find( I+1, te1, te2 );//cout<<
- }
- }
- }
- tot[I][e1][e2] %= MOD;
- return tot[I][e1][e2];
- }
- int main( void )
- {
- long i,j,u,Icase,k=0;
- freopen("text1.txt","r",stdin );
- cin>>Icase;
- while( Icase-- ){
- Lim = 0;
- CLR( str );
- for( i=0;i<3;i++ ){
- scanf("%s",str[i] );
- Lim = max( Lim, (long)strlen( str[i] ) );
- }
- TRUE++;
- long ans = Find( 0,true,true );
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement