Solve ABC167 A ~ C with Python

Introduction

It was three completes from A to C.

A problem

Problem

** Thoughts ** Just compare

s = input()
t = input()

n = len(t)
if s == t[:n-1]:
    print('Yes')
else:
    print('No')

B problem

Problem

** Thoughts ** 2WA () without noticing the deadly typo

a, b, c, k = map(int,input().split())

if a >= k:  #all k a
    print(k)
elif a + b >= k: #If you take c, it will decrease, so take it from b
    print(a)
else:
    n = k - (a + b)
    ans = a + -1 * n
    print(ans)

C problem

Problem

** Thoughts ** I was impatient with 2WA at B, so I was late to submit it. Withstands a typical bit full search, N is small enough.

n, m, x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]

costs = []
for i in range(2 ** n):
    flag = True
    cost = 0
    algos = [0] * m
    op = [False] * n
    for j in range(n):
        if ((i >> j) & 1):
            op[n - j - 1] = True
    #print(op)
    for j in range(n):
        if op[j]:
            for k, u in enumerate(ca[j][1:]):
                algos[k] += u
            cost += ca[j][0]
    for j in algos:
        if j < x:
            flag = False
    if flag:
        costs.append(cost)

if len(costs) == 0:
    print(-1)
else:
    print(min(costs))

D problem

Problem

** Thoughts ** I found a loop and sought the remainder, but I couldn't pass it in about 8 cases and WA.

Summary

The last three ABCs are WAs in A and B each time, so I have to calm down and solve it. See you again, good night.

Recommended Posts

Solve ABC168 A ~ C with Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve ABC166 A ~ D with Python
Solve ABC036 A ~ C in Python
Solve ABC037 A ~ C in Python
Solve ABC175 A, B, C in Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Solve AtCoder ABC168 with python (A ~ D)
ABC163 C problem with python3
ABC188 C problem with python3
Solve AtCoder ABC 186 with Python
ABC187 C problem with python
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
ABC127 A, B, C Explanation (python)
ABC166 in Python A ~ C problem
Solved AtCoder ABC 114 C-755 with Python3
ABC128 A, B, C commentary (python)
ABC126 A, B, C Explanation (python)
Solve Atcoder ABC176 (A, B, C, E) in 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!
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
I wanted to solve ABC160 with Python
Solve ABC165 A, B, D in Python
I wanted to solve ABC172 with Python
Solve Sudoku with Python
Solve ABC169 in Python
ABC147 C --HonestOrUnkind2 [Python]
Solve POJ 2386 with python
I wanted to solve the ABC164 A ~ D problem with Python
Solve A ~ D of yuki coder 247 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!
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
[Python] Solve equations with sympy
AtCoder ABC 177 Python (A ~ E)
AtCoder ABC 178 Python (A ~ E)
ABC129 A, B, C commentary
Solve ABC176 E in Python
ABC memorandum [ABC163 C --managementr] (Python)
AtCoder ABC 176 Python (A ~ E)
Solve ABC175 D in Python
Make a fortune with Python
AtCoder ABC 182 Python (A ~ D)
Create a directory with python
Try embedding Python in a C ++ program with pybind11
Make a breakpoint on the c layer with 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!
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
[Python] What is a with statement?
solver> Link> Solve Excel Solver with python
ABC memorandum [ABC159 C --Maximum Volume] (Python)
Embed a Python interpreter into a C ++ app with pybind11 + cmake