```C++ #include <iostream> #include <map> #include <unordered_map> #include <string> using namespace std; int main() { // map<string, int> mp; // O(logN) // mp["a"] = 2, mp["b"] = 1, mp["c"] = 3 // unordered_map<string, int> mp; // O(1) unordered_map<int, int> mp; // alphabet = {a, b, c, d, e}; // 11001 <-> abe // 00011 <-> de // aabac <-> 11100 <-> 28 // mask // 11111 ^ 11100 = 00011 int n, m; long long ans = 0; cin >> n >> m; long long mask = 0; // 64個0 for (int i=0;i<n;i++) { // 00000000001 // 00000000010 // 00000000100 // 00000001000 // --------------- // 11111111111 mask = mask | (1 << i); } // O(m) for (int i=0;i<m;i++) { string str; cin >> str; // [26][12] // "ZYX.....DCBAl....dcba" long long tmp = 0; // tmp = 0000001000000 for (int i=0;i<str.size();i++) { if ('A' <= str[i] && str[i] <= 'Z') { // 'A' -> 00000000001000000000 tmp = tmp | (1 << (12+str[i]-'A')); } else { tmp = tmp | (1 << (str[i]-'a')); } } mp[tmp] ++; if (mp.find(mask^tmp) != mp.end()) { ans += mp[tmp] * mp[mask^tmp]; } } cout << ans << endl; } /* map: map = {"": 0} map["a"] ++; map = {"a": 1}; map["a"] ++; map = {"a": 2}; map["asdf"] += 5; map = {"a": 2, "asdf": 5}; // query if (map.find("a") != map.end()) { cout << map["a"] << endl; } */ ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up