ABC memorandum [ABC157 C --Guess The Number] (Python)

Problem statement

If there are integers greater than or equal to $ 0 $ that meet the following conditions, output the smallest of them. If no such integer exists, print $ -1 $. It is exactly $ N $ digit in decimal notation. ($ 0 $ is an integer with $ 1 $ digits. For other integers, notation with 0 at the beginning is not allowed.) Counting from the left, the $ s_i $ digit is $ c_i $. $ (i = 1,2, ⋯, M) $

Constraints

All inputs are integers 1≤N≤3 0≤M≤5 1≤s_i≤N 0≤c_i≤9

ABC157 C - Guess The Number

solution

From the problem statement, the integer to be calculated is 3 digits, so we will calculate by brute force.

N, M = map(int,input().split())
s = []
c = []
for i in range(M):
  S, C = map(int,input().split())
  s.append(S)
  c.append(C)


for i in range(10 ** (N + 1)):
  Str = str(i)
  
  if len(Str) == N and all([Str[s[j] - 1] == str(c[j]) for j in range(M)]):
      print(Str)
      exit()

print(-1)

The if in the second for uses the all function. The all function returns True when all the elements of an object, such as lists and tuples, are true. Here, it is judged whether all the conditions are met.

Recommended Posts

ABC memorandum [ABC157 C --Guess The Number] (Python)
ABC memorandum [ABC163 C --managementr] (Python)
ABC memorandum [ABC159 C --Maximum Volume] (Python)
ABC memorandum [ABC161 C --Replacing Integer] (Python)
ABC memorandum [ABC158 C --Tax Increase] (Python)
ABC147 C --HonestOrUnkind2 [Python]
ABC memorandum [ABC160 C --Traveling Salesman around Lake] (Python)
ABC163 C problem with python3
[python] Random number generation memorandum
ABC188 C problem with python3
ABC187 C problem with python
Solve ABC163 A ~ C with Python
ABC127 A, B, C Explanation (python)
ABC166 in Python A ~ C problem
Solve ABC168 A ~ C with Python
Solve ABC036 A ~ C in Python
Solved AtCoder ABC 114 C-755 with Python3
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
ABC128 A, B, C commentary (python)
Solve ABC158 A ~ C with Python
ABC126 A, B, C Explanation (python)
Solve ABC037 A ~ C in Python
Python memorandum
[AtCoder commentary] Win the ABC165 C problem "Many Requirements" with Python!
Python Memorandum 2
Python memorandum
python memorandum
python memorandum
Python memorandum
python memorandum
Python memorandum
Solve ABC175 A, B, C in Python
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
Beginner ABC154 (Python)
How to use the C library in Python
Output the number of CPU cores in Python
Python basics memorandum
Python pathlib memorandum
AtCoder ABC 174 Python
[AtCoder explanation] Control the A, B, (C), D problems of ABC165 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
Calculate the total number of combinations with python
AtCoder ABC 098 C --Attention Thinking about the answer
Beginner ABC155 (Python)
python C ++ notes
python, openFrameworks (c ++)
A memorandum about the Python tesseract wrapper library
Beginner ABC157 (Python)
Python memorandum [links]
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
AtCoder ABC 175 Python
Check if the string is a number in python
python beginners tried to predict the number of criminals
[Python] A program that counts the number of valleys
How to get the number of digits in Python