finish extra/find-the-access-codes #13

Merged
seongbeom_park merged 3 commits from extra/find-the-access-codes into main 2022-04-29 18:26:13 +00:00
2 changed files with 14 additions and 27 deletions
Showing only changes of commit 0d75806e4a - Show all commits

View File

@ -31,7 +31,7 @@
## Encrypted message ## Encrypted message
CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQMQVBkPERkECQAWDVwXX1BGEwgJBAwCBFRVHQRGUlFBShwaDVZTGBUFVUdBShsVA1tZBwNGUlFB ShoVB1wXX1BGFAQOSklOQR5HGh5AVRY= CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQMQVBkPERkECQAWDVwXX1BGEwgJBAwCBFRVHQRGUlFBShwaDVZTGBUFVUdBShsVA1tZBwNGUlFB ShoVB1wXX1BGFAQOSklOQR5HGh5AVRY=
## Extra ## Extra Level
* Requested problems after level 5 clear * Requested problems after level 5 clear
### dodge-the-laser ### dodge-the-laser
@ -68,5 +68,9 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM
* Reference * Reference
* [Maximum Matching in General Graph](https://www.secmem.org/blog/2020/04/18/Blossom/) * [Maximum Matching in General Graph](https://www.secmem.org/blog/2020/04/18/Blossom/)
### extra/prepare-the-bunnies-escape ### prepare-the-bunnies-escape
* Completed in: 3 hrs, 17 mins, 20 secs. * Completed in: 3 hrs, 17 mins, 20 secs.
### find-the-access-codes
* Completed in: 1 hr, 6 mins, 52 secs.

View File

@ -1,30 +1,15 @@
def solution(l): def solution(l):
edges = {n : {'count': 1, 'multiple': set(), 'divisor': set()} for n in set(l)} nodes = {i: [] for i in range(len(l))}
for i in range(len(l)): for i in range(len(l)):
x = l[i]
if edges[x]['count'] > 1:
continue
for j in range(i+1, len(l)): for j in range(i+1, len(l)):
y = l[j] x, y = l[i], l[j]
if x == y: if y % x == 0:
edges[x]['count'] += 1 nodes[i] += [j]
elif x > y and x % y == 0:
edges[x]['divisor'].add(y)
edges[y]['multiple'].add(x)
elif y > x and y % x == 0:
edges[x]['multiple'].add(y)
edges[y]['divisor'].add(x)
result = 0 result = 0
for x in edges: for i in nodes:
# 1. (d, x, m) for j in nodes[i]:
result += len(edges[x]['divisor']) * len(edges[x]['multiple']) result += len(nodes[j])
# 2. (d, x, x) (x, x, m)
if edges[x]['count'] >= 2:
result += len(edges[x]['divisor']) + len(edges[x]['multiple'])
# 3. (x, x, x)
if edges[x]['count'] >= 3:
result += 1
return result return result
@ -32,9 +17,7 @@ tests = [
([1, 1, 1], 1), ([1, 1, 1], 1),
([1, 2, 3, 4, 5, 6], 3), ([1, 2, 3, 4, 5, 6], 3),
([2, 3, 4], 0), ([2, 3, 4], 0),
([1, 1, 2, 3, 4, 5, 6], 8), ([1, 1, 2, 3, 4, 5, 6], 11),
([3 for i in range(2000)], 1),
([i for i in range(1, 2000)], 40777),
] ]
for i, o in tests: for i, o in tests: