-
Notifications
You must be signed in to change notification settings - Fork 2
/
bgm.cpp
76 lines (59 loc) · 1.2 KB
/
bgm.cpp
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
69
70
71
72
73
74
75
76
#include <cstdio>
#include <string>
#include <map>
#include <iostream>
#include <cmath>
using namespace std;
string key = "BESIGOM";
string words[3] = {"BESSIE","GOES","MOO"};
map<char,int*> alphabet;
map<char,int> indexOf;
int num;
int curLayout[7];
long long ans = 0;
void setup(){
for(int x = 0;x<key.length();x++){
alphabet[key[x]] = new int[7];
for(int a = 0;a<7;a++) alphabet[key[x]][a] = 0;
indexOf[key[x]] = x;
}
}
bool pass(){
for(int a = 0;a<3;a++){
int sum = 0;
for(int x = 0;x<words[a].length();x++){
sum+=curLayout[indexOf[words[a][x]]];
}
if(sum%7==0) return true;
}
return false;
}
int main(){
freopen("bgm.in","r",stdin);
freopen("bgm.out","w",stdout);
setup();
cin >> num;
for(int x = 0;x<num;x++){
char c;
int in;
cin >> c >> in;
in %=7;
if(in<0) in += 7; // if less than 0
alphabet[c][in]++;
}
int all = pow(7,7);//0 to 7^7-1 is all the possible values for everything
for(int x = 0;x<all;x++){
int curAssign = x;
for(int a = 0;a<7;a++){
curLayout[a] = curAssign%7;
curAssign/=7;
}
if(pass()){
long long add = 1;
for(int a = 0; a<7;a++)
add*=alphabet[key[a]][curLayout[a]];
ans += add;
}
}
cout << ans << endl;
}