Nothing to note
for _ in range(int(input())):
int = int(input())
n: list[int] = list(map(int, input().split()))
a: for i in range(n - 1):
if abs(a[i + 1] - a[i]) not in (5, 7):
print("NO")
break
else:
print("YES")
My submission has been hacked and exceeded the time limit.
from collections import defaultdict
for _ in range(int(input())):
= map(int, input().split())
n, k
= defaultdict(int)
d for _ in range(k):
= map(int, input().split())
b, c += c
d[b]
print(sum(sorted(d.values(), reverse=True)[:n]))
but my solution seems to be the same as the one on the editorial, and its time complexity should be O(klogk). sorted() uses Timsort…
I tried to browse others' solutions, but Codeforces does not offer a convenient UI for that.
My gut feeling is that there is a pitfall when using Python, as Python is not a good language for competitive programming, but it may not be that important for me right now. I want to focus on data structures & algorithms, not useful techniques for competitive programming.
The approach to breaking down the problem and thinking about functions I would want to use worked this time. I feel that I broke a wall with this problem.
Just the same as everyday programming (and all other matters in life), breaking down a big problem into smaller ones and dealing with them one by one worked.
def count_occurrance(a: list[str], t) -> int:
int = 0
count: for i in range(len(a) - 3):
if "".join(a[i : i + 4]) == t:
+= 1
count return count
def flatten_layer(mat: list[list[str]], n: int, m: int, layer: int) -> list[str]:
assert layer >= 0
list[str] = []
result: # up, excluding two edges
for col_i in range(layer + 1, m - layer - 1):
result.append(mat[layer][col_i])# right
for row_i in range(layer, n - layer):
- layer - 1])
result.append(mat[row_i][m
# bottom, excluding two edges
for col_i in range(m - layer - 2, layer, -1):
- layer - 1][col_i])
result.append(mat[n # left
for row_i in range(n - layer - 1, layer - 1, -1):
result.append(mat[row_i][layer])
# circulate
3])
result.extend(result[:
return result
for _ in range(int(input())):
= map(int, input().split())
n, m = []
mat for _ in range(n):
list(input()))
mat.append(
int = 0
res: for i in range(min(n // 2, m // 2)):
list[str] = flatten_layer(mat, n, m, i)
flat_layer: += count_occurrance(flat_layer, "1543")
res
print(res)
Protein bars 450 Protein chips 150 Sushi bowl 800 Salad 200 Pocky 200
Total 1800 kcal
MUST:
uv
is fast” means and if it's
importantTODO: