Panasonic Programming Contest 2020 3 Complete (Python3 95:30 8WA) I will post the solution of A ~ C.
Click here for the link for Panasonic Programming Contest 2020 https://atcoder.jp/contests/panasonic2020
A-Kth Term
Problem statement
Output the Kth term of the following sequence of length 32.
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_a
I think that you should put this sequence in the list and output the Kth input.
Submission code
main.py
k = int(input())
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(x[k-1])
B-Bishop
Problem statement
There are vertical H-mass and horizontal W-mass boards. A bishop piece is placed in the square in the upper left corner of this board. How many squares can you reach by repeating the movement of 0 or more pieces as you like? For example, when the frame is in the figure, the place where you can move at one time is the red square. https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b
I can't understand at all even if I glance at the problem statement. So, if you look at the figures of Input Example 1 and Input Example 2, you will notice that the colored cells are the numbers obtained by rounding up the number of cells hw / 2.
However, when h = 1 or w = 1 as shown in the figure below, the number of squares that are always colored is 1.
Submission code
main.py
import math
h,w = map(int, input().split(' '))
if h == 1 or w == 1:
print(1)
else:
res = math.ceil(h*w / 2)
print(res)
C-Sqrt Inequality
Problem statement
$ \ Sqrt {a} + \ sqrt {b} <\ sqrt {c} $? https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
Let's write the code as it is with the problem statement.
main.py
import math
a,b,c = map(int, input().split(' '))
if math.sqrt(a) + math.sqrt(b) < math.sqrt(c):
print('Yes')
else:
print('No')
If this is the case, WA will appear. Therefore
From $ \ sqrt {a} + \ sqrt {b}> 0 $ and $ \ sqrt {c}> 0 $
Addendum: The code below was incorrect and has been fixed. (2020/3/16)
check.py
from math import sqrt as sq
a = 250000000
b = 250000000
c = 10**9
while sq(a) + sq(b) >= sq(c):
a += 1
b -= 1
print(a,b)
print(4*a*b, (c-a-b)**2)
print(sq(a)+sq(b)<sq(c))
print(4*a*b < (c-a-b)**2)
250000001 249999999
249999999999999996 250000000000000000
False
True
250000002 249999998
249999999999999984 250000000000000000
False
True
250000003 249999997
249999999999999964 250000000000000000
False
True
250000004 249999996
249999999999999936 250000000000000000
False
True
250000005 249999995
249999999999999900 250000000000000000
False
True
250000006 249999994
249999999999999856 250000000000000000
False
True
250000007 249999993
249999999999999804 250000000000000000
True
True
Submission code
main.py
import math
a,b,c = map(int, input().split(' '))
x = 4 * a * b
y = c - a -b
if y <= 0:
print('No')
elif x < y**2:
print('Yes')
else:
print('No')
It can also be c-a-b <0.
Recommended Posts