[Python] ARC006A (set strongest theory) [AtCoder]

I thought the set set was the strongest, so make a note.

ARC006A Difficulty:238 The problem itself is simple. The key to achieving high performance in competitive professionals is how quickly and smartly you can write!

You can solve it without using set, but this time I will try to solve it using set.

Prior knowledge of the set set

You can do something like a Venn diagram in high school math! ʻA | B: Union ʻA & B: Intersection ʻA ^ B: Exclusive OR (only one of them is true Bitwise XOR) ʻA-B: Difference set (only in A)

In particular···

test.py


A={1,2,3,5,6}
B={2,4,5,7}
print(A|B)
print(A&B)
print(A^B)
print(A-B)

Output result スクリーンショット 2020-03-21 14.03.22.png

set strong (confident) There seems to be various uses

When you actually use ARC006A with set, it looks like this

test.py


def I(): return int(input())
def LI(): return list(map(int,input().split()))
E = set(LI()) #Receive as a set!
B = I()
L = set(LI()) #Receive as a set!
ans = 0
count = len(E&L) #Intersection! !! !!
if count==5 and B in L:
    ans = 2
else:
    ans = {6:1,5:3,4:4,3:5}[count] if count>=3 else 0
print(ans)

If you have the knowledge of this set in mind, you should be able to code this problem in less than 3 minutes! You can solve it without knowing this, but if you know it, you can solve it quickly = I think you can become a strong person.

end!

Recommended Posts

[Python] ARC006A (set strongest theory) [AtCoder]
atCoder 173 Python
Atcoder standard input set for beginners (python)
Python set arithmetic
Python set arithmetic
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Solve AtCoder 167 with python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Automate AtCoder submission (Python)
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Python Golf Tech (AtCoder)
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python