Last active
August 29, 2015 14:06
-
-
Save cocodrips/904bc7b9e1129cd828f4 to your computer and use it in GitHub Desktop.
Pythonではじめる競技プログラミング 例題の解答例
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
import collections | |
def solve(A, B, C, D): | |
count = 0 | |
AB = create_pairs(A, B) | |
CD = create_pairs(C, D) | |
for k, v in AB.items(): | |
count += CD[-k] * v | |
return count | |
def create_pairs(S, T): | |
pairs = collections.Counter() | |
for i in S: | |
for j in T: | |
pairs[i + j] += 1 | |
return pairs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment