Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocodrips/904bc7b9e1129cd828f4 to your computer and use it in GitHub Desktop.
Save cocodrips/904bc7b9e1129cd828f4 to your computer and use it in GitHub Desktop.
Pythonではじめる競技プログラミング 例題の解答例
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