[Violence Enumeration] Codeforces Vanya and Label

Vanya and Label
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 109 + 7.

To represent the string as a number in numeral system with base 64 Vanya uses the following rules:

  • digits from '0' to '9' correspond to integers from 0 to 9;
  • letters from 'A' to 'Z' correspond to integers from 10 to 35;
  • letters from 'a' to 'z' correspond to integers from 36 to 61;
  • letter '-' correspond to integer 62;
  • letter '_' correspond to integer 63.
Input

The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.

Output

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.

Examples
input
Copy
with
output
Copy
3
input
Copy
V_V
output
Copy
9
input
Copy
Codeforces
output
Copy
130653412
Note

For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.

In the first sample, there are 3 possible solutions:

  1. z&_ = 61&63 = 61 = z
  2. _&z = 63&61 = 61 = z
  3. z&z = 61&61 = 61 = z

Meaning of the questions: to give you a string s, the character is mapped to some figures, and asked how many of the same string length of the string-by-bit AND get still get the string s

Thinking: Look how many of each species could, then they multiplied and modulo, is the answer, noting that only a maximum of 64 characters, so O (n * n) Violence, 4096 * 1e5 probably within one second at 4e8 finish

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int amn=1e5+5,mod=1e9+7;
 4 char a[amn];
 5 int main(){
 6     ios::sync_with_stdio(0);
 7     cin>>a;
 8     long long ans=1,sum;
 9     int len=strlen(a),in,jg;
10     for(int i=0;i<len;i++){
11         if(a[i]>='0'&&a[i]<='9')in=a[i]-'0';
12         else if(a[i]>='A'&&a[i]<='Z')in=a[i]-'A'+10;
13         else if(a[i]>='a'&&a[i]<='z')in=a[i]-'a'+36;
14         else if(a[i]=='-')in=62;
15         else in=63;
16         sum=0;
17         for(int j=0;j<=63;j++){
18             for(int k=0;k<=63;k++){
19                 jg=j&k;
20                 if(jg==in)sum++;
21             }
22         }
 23 is          ANS = ((% MOD ANS) * (MOD SUM%))% MOD;
 24      }
 25      the printf ( " % LLD \ n- " , ANS);
 26 is  }
 27  / * **
 28  give you a string s, the character mapping for a number of figures, and asked how many of the same string length of the string-by-bit aND get still get the string S
 29  to see how many of each species could, then they multiplied and modulo, is the answer , noting that only a maximum of 64 characters, so O (n * n) violence, 4096 * 1e5 probably can finish within one second in 4E8
 30  ** * /

 

Guess you like

Origin www.cnblogs.com/brainm/p/11310872.html