Daily AtCoder # 35 in Python

Introduction

Last time Boot camp for Beginners is coming.

#35 ABC096-C

** Thoughts ** Look for an isolated black square. I'm checking all the points in for minutes.

h, w = map(int,input().split())
s = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check = 0
            for x, y in ([1,0],[0,1],[0,-1],[-1,0]):
                new_h, new_w = i + x, j + y
                #print(new_h,new_w)
                if new_h < 0 or new_h >= h or new_w < 0 or new_w >= w:
                    continue
                if s[new_h][new_w] == '.':
                    check += 1
            if check == 4: #There is no black in 4 directions
                print('No')
                quit()
print('Yes')

ABC063-C

** Thoughts ** The highest point is when you answer all the questions correctly. However, if the number of correct answers to all the questions is a multiple of 10, it will be 0 as it is. Therefore, mod 10 is confirmed by subtracting from the highest score in ascending order of score.

n = int(input())
s = [int(input()) for _ in range(n)]

s.sort()
ans = sum(s)
if ans % 10 != 0:
    print(ans)
    quit()
else:
    for i in range(n):
        if (ans-s[i]) % 10 != 0:
            print(ans-s[i])
            quit()

print(0)

ARC073-C

** Thoughts ** The process is divided according to whether or not the shower is on at $ t_i $. If there is a shower, the remaining shower time at $ t_i $ will be overwritten by $ t $. If there is no shower, there will be a shower from $ t_i $ to $ t + t_i $.

n, t = map(int,input().split())
time = list(map(int,input().split()))

ans = 0
wait = 0
for i in range(n):
    if i == 0:
        ans += t
        wait += t
    if wait <= time[i]:
        ans += t
        wait = time[i] + t
    else:
        c = (wait - time[i])
        ans -= c
        ans += t
        wait = time[i] + t

print(ans)

ABC088-C

** Thoughts ** Since the difference of the same column and row is the same like (2,1)-(1,1) and (3,1)-(2,1), implement with for. ← It seems to be easier to solve

c = [list(map(int,input().split())) for _ in range(3)]

for i in range(2):
    for j in range(1,3):
        if c[i][j] - c[i][j-1] != c[i+1][j] - c[i+1][j-1]:
            print('No')
            quit()
for i in range(1,3):
    for j in range(2):
        #print(c[i][j] , c[i-1][j])
        #print(c[i][j+1] , c[i-1][j+1])
        if c[i][j] - c[i-1][j] != c[i][j+1] - c[i-1][j+1]:
            print('No')
            quit()
print('Yes')

diverta 2019 Programming Contest-B

** Thoughts ** Full search. I TLE it with python, so I put it out with pypy.

r, g, b, n = map(int,input().split())

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        bule_ball = (n - (r * i + g * j)) // b
        sum_ball = bule_ball * b + i * r + j * g
        #print(i,j,bule_ball)
        if bule_ball >= 0 and sum_ball == n:
            ans += 1

print(ans)

ABC073-C

** Thoughts ** If you check using a checklist of numbers, $ A_i $ is large, so TLE. So, sort $ A $ and compare each adjacent element. Here, if the number of occurrences of $ A_i $ is an even number, it will not remain until the end, so the oddness of the number of appearances is judged. In terms of bool, the flag that was initially True when the number of occurrences is even is inverted at the boundary with the next element. Therefore, the authenticity of the flag is judged when adjacent elements are no longer the same.

n = int(input())
a = [int(input()) for _ in range(n)]

a.sort()
a.append(0)
ans = 0
flag = True
for i in range(1,n+1):
    if a[i] == a[i-1]:
        flag = not flag
    else:
        if flag:
            ans += 1
        flag = True
    #print(flag)
    #print(a[i])
print(ans)

Summary

If I couldn't write a full search cleanly, I should have issued it with PyPy. see you,

Recommended Posts

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
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
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 # 25 in Python
Daily AtCoder # 12 in Python
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 # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda