Created
September 12, 2014 08:24
-
-
Save pascaljp/d7895f2fd9e09cb55890 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <hash_map> | |
int solve(const vector<int>& A, | |
const vector<int>& B, | |
const vector<int>& C, | |
const vector<int>& D) { | |
int count = 0; | |
hash_map<int, int> AB = create_pairs(A, B); | |
hash_map<int, int> CD = create_pairs(C, D); | |
for (const auto& pair : AB) { | |
count += pair.second * CD[-pair.first]; | |
} | |
return count; | |
} | |
hash_map<int, int> create_pairs(const vector<int>& S, const vector<int>& T) { | |
hash_map<int, int> pairs; | |
for (const int s : S) { | |
for (const int t : T) { | |
pairs[s + t]++; | |
} | |
} | |
return pairs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment