ABC146A - Can't Wait for Holiday
Break through in two and a half minutes. Just write.
S = input()
if S == 'SUN':
print(7)
elif S == 'MON':
print(6)
elif S == 'TUE':
print(5)
elif S == 'WED':
print(4)
elif S == 'THU':
print(3)
elif S == 'FRI':
print(2)
elif S == 'SAT':
print(1)
Break through in 4 and a half minutes. Just write.
N = int(input())
S = input()
print(''.join(chr((ord(c) - ord('A') + N) % 26 + ord('A')) for c in S))
Break through in 16 minutes. At first glance, I did it recently. I copied the source code of ABC144E --Gluttony and rewrote is_ok. , Adjusted and poi. It took a lot of time to adjust, so I haven't got the formula to go around yet.
A, B, X = map(int, input().split())
def is_ok(N):
return A * N + B * len(str(N)) <= X
ok = 0
ng = 10 ** 9 + 1
while ng - ok > 1:
m = (ok + ng) // 2
if is_ok(m):
ok = m
else:
ng = m
print(ok)
ABC146D - Coloring Edges on Tree
Lost. It seems that there was an algorithm policy of breadth-first search .... The first one I wrote was TLE, and the one I rewrote was because the data structure was bad and I ate MLE ....
Hmmm, it's a pity that I can't pass this for 77 minutes.
from sys import setrecursionlimit
def genid(a, b):
if b < a:
a, b = b, a
return a * 100000 + b
def paint(currentNode, usedColor, parentNode, edges, colors):
color = 1
for childNode in edges[currentNode]:
if childNode == parentNode:
continue
if color == usedColor:
color += 1
colors[genid(currentNode, childNode)] = color
paint(childNode, color, currentNode, edges, colors)
color += 1
setrecursionlimit(100000)
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
edges = [[] for _ in range(N)]
for a, b in ab:
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
colors = {}
paint(0, -1, -1, edges, colors)
print(max(len(e) for e in edges))
for a, b in ab:
print(colors[genid(a - 1, b - 1)])
Recommended Posts