Codeforces355-div2C Vanya and Label

Problem - C - Codeforces

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.

文字列$s$と$\&$を取った時に等しくなる$2$つの文字列の組み合わせいくつあるか? $mod\ 10 ^9 + 7$で求める.

各桁についての組み合わせを出して掛けていった.組み合わせを全探索して組み合わせ数を出した. $\&と==$では$==$のほうが優先度が高いのでちゃんと括弧でくくる.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <bitset>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  vector<char> v;
  map<char, int> m;
  rep(i, 10) {
      m['0'+i] = i;
      v.push_back('0'+i);
  }

  rep(i, 26) {
      m['A'+i] = 10 + i;
      m['a'+i] = 36 + i;

      v.push_back('A'+i);
      v.push_back('a'+i);
  }

  m['-'] = 62;
  m['_'] = 63;
  v.push_back('-');
  v.push_back('_');

  map<char, ll> cnt;
  sort(v.begin(), v.end());

  rep(i, v.size()) {
      rep(j, v.size()) {
          rep(k, v.size()) {
              if((m[v[j]] & m[v[k]]) == m[v[i]]) {
                  cnt[v[i]]++;
              }
          }
      }
  }

  ll ans = 1;
  string s;
  cin >> s;

  rep(i, s.size()) {
      ans *= cnt[s[i]];
      ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}
Jun 2nd, 2016