ABC187 C problem with python

ABC187 C Problem 1-SAT

Correct answer

N = int(input())
S = set(input() for i in range(N))
for s in S:
    if "!" + s in S:
        print(s)
        exit()
print("satisfiable")

point

x in list is computational complexity order O (N) x in set can be easily melted by using the fact that the complexity order is O (1). The reason seems to be that the set type data puts each value in a function called a hash function and connects the values ​​that come out. The following article was easy to understand, so I will post a link

Easy to understand the hash table

Refer to the above article and give an easy-to-understand example of how x in set works internally. Consider whether the element of set = {23,7,11,4,10} contains 9. Considering a hash function with hash (x) = x% 5 Since hash (23) = 3, hash (7) = 2, hash (11) = 1, hash (4) = 4, hash (10) = 0 Stores 10 in the memory address 0, 11 in the 1st address, 7 in the 2nd address, 23 in the 3rd address, and 4 in the 4th address.

Since hash (9) = 4 here, check the number stored in the memory at address 4. As a result, it can be seen that 9 is not included in the set because the number contained is 4 and not 9.

In the above example, in the list, it can be seen that the value had to be confirmed at all addresses 1 to 4, but by using set, only address 4 had to be confirmed.

A word

In this contest, I stumbled upon this problem and melted it for about 40 minutes. I couldn't solve it without such knowledge of the problem, so I should have rounded it up. If it's an inspirational problem, it may be solved by taking time, but if it's a knowledge problem, it's impossible. However, I don't know if the problem I'm solving is a knowledge problem or a flash problem, so if I can't do it for 30 minutes, I'll skip it and move on to the next problem.

Recommended Posts

ABC163 C problem with python3
ABC188 C problem with python3
ABC187 C problem with python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Solve ABC163 A ~ C with Python
ABC166 in Python A ~ C problem
Solved AtCoder ABC 114 C-755 with Python3
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
ABC147 C --HonestOrUnkind2 [Python]
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Solve AtCoder ABC166 with python
ABC memorandum [ABC163 C --managementr] (Python)
Solve AtCoder ABC 186 with Python
ABC memorandum [ABC159 C --Maximum Volume] (Python)
Call C from Python with DragonFFI
Create Awaitable with Python / C API
ABC127 A, B, C Explanation (python)
Solve ABC166 A ~ D with Python
ABC memorandum [ABC161 C --Replacing Integer] (Python)
Solve ABC036 A ~ C in Python
ABC memorandum [ABC158 C --Tax Increase] (Python)
ABC128 A, B, C commentary (python)
AtCoder Beginner Contest 174 C Problem (Python)
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC188 A, B, C problems with Python!
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
Solving with Ruby and Python AtCoder ABC011 C Dynamic programming
AtCoder ABC151 Problem D Speed comparison in C ++ / Python / PyPy
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
Beginner ABC156 (Python)
FizzBuzz with Python3
Solve ABC175 A, B, C in Python
Scraping with Python
Statistics with python
Scraping with Python
AtCoder ABC 174 Python
Python with Go
Algorithm in Python (ABC 146 C Binary Search
Twilio with Python
AtCoder ABC187 Python
I wanted to solve ABC160 with Python
Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
[C] [python] Read with AquesTalk on Linux
Play with 2016-Python
Japanese file enumeration with Python2 system on Windows (5C problem countermeasure)
Tested with Python
AtCoder ABC188 Python
ABC memorandum [ABC157 C --Guess The Number] (Python)
with syntax (Python)
python, openFrameworks (c ++)
Solve AtCoder ABC168 with python (A ~ D)
I wanted to solve the ABC164 A ~ D problem with Python
Bingo with python
Beginner ABC157 (Python)
Use C ++ functions from python with pybind11
Solving with Ruby, Perl, Java, and Python AtCoder ABC 065 C factorial
AtCoder ABC 175 Python