Codeforces Round #207 (Div. 1) B. Xenia and Hamming

Source: Internet
Author: User

Codeforces Round #207 (Div. 1) B. Xenia and Hamming

 

Solution
Set lena to the length of string a, lenb to the length of string B, gcd, lcm, gcd for lena and lenb, lcm... You will find a coequal relationship. First, the lcm length is one cycle. Within one lcm length, each character of a is touched and only touched once with each character in the same coequal position of B, then it's easy. Find out the answer and try again with lcm ..
My code
//Hello. I'm Peter.#include
  
   #include
   
    #include
    
     #include
     
      #include
      
       #include
       
        #include
        
         #include#include
         
          #include
          
           #include
           
            #include
            
             #include
             
              #include
              
               #include
               
                #include
                using namespace std;typedef long long ll;typedef long double ld;typedef unsigned long long ull;#define peter cout< b; i--)#define repin(i, a, b) for (int i = a; i <= b; i++)#define depin(i, a, b) for (int i = a; i >= b; i--)#define pi 3.1415926535898#define eps 1e-6#define MOD 1000000007#define MAXN 1000010#define N#define Mll n,m,lena,lenb,d,l,sum;char a[MAXN],b[MAXN];int c[MAXN][26];int main(){ cin>>n>>m; scanf(%s%s,a,b); lena=len(a),lenb=len(b); d=__gcd(lena,lenb); l=lena/d*lenb; int t=0; rep(i,0,lena){ c[t++][a[i]-'a']+=1; if(t==d) t=0; } t=0; sum=l; rep(i,0,lenb){ sum-=c[t++][b[i]-'a']; if(t==d) t=0; } sum=(n*lena/l)*sum; cout< 
               
              
             
            
           
          
         
        
       
      
     
    
   
  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.