freedom.99
Senior Member
Mà q3 q4 khó vl ấy chứ, 2Q Gang cmnr 
Đọc lộn đề Q4

Đọc lộn đề Q4

Đúng rồi, mình đọc Q3 thấy cần tí observation nhảy qua Q4.Câu 3 ngay lúc sập e đã đoán là chỉ cần tìm max subarray cho mỗi row, col, edge case thì với elem ở cạnh phải lấy ít nhất 2 mà loay hoay cả tiếng mới implement xong, Q4 thấy accept cũng cao, nhìn dạng quen quen mà thôi mệt quá không nghĩ nổi


from collections import defaultdict
from typing import List
class Solution:
def countValidSubsets(self, parent: List[int], nums: List[int], k: int) -> int:
MOD = 10**9 + 7
graph = defaultdict(list)
for i, val in enumerate(parent):
if val != -1:
graph[val].append(i)
def dfs(node, p):
# Base state for the current node BEFORE looking at any neighbors
# includeNode tracks if we pick 'node'. Starts with just its own value.
includeNode = defaultdict(int)
includeNode[nums[node] % k] = 1
# excludeNode tracks if we don't pick 'node'. Starts with an empty subset (sum 0).
excludeNode = defaultdict(int)
excludeNode[0] = 1
for neighbor in graph[node]:
if neighbor == p:
continue
includeNeighbor, excludeNeighbor = dfs(neighbor, node)
# Temporary containers to hold the multiplied combinations safely
nextInclude = defaultdict(int)
nextExclude = defaultdict(int)
# 1. If 'node' is INCLUDED, the neighbor MUST be EXCLUDED
for k_parent, v_parent in includeNode.items():
for k_child, v_child in excludeNeighbor.items():
rem = (k_parent + k_child) % k
nextInclude[rem] = (nextInclude[rem] + v_parent * v_child) % MOD
# 2. If 'node' is EXCLUDED, the neighbor can be INCLUDED OR EXCLUDED
for k_parent, v_parent in excludeNode.items():
# Combined total ways for the child branch at remainder k_child
all_child_keys = set(includeNeighbor.keys()) | set(excludeNeighbor.keys())
for k_child in all_child_keys:
v_child = (includeNeighbor[k_child] + excludeNeighbor[k_child]) % MOD
rem = (k_parent + k_child) % k
nextExclude[rem] = (nextExclude[rem] + v_parent * v_child) % MOD
# Update our current node's profiles with the new multiplied states
includeNode = nextInclude
excludeNode = nextExclude
return includeNode, excludeNode
# Run DFS from the root
rootInclude, rootExclude = dfs(0, -1)
# Total valid subsets have a remainder of 0.
# We subtract 1 to remove the "completely empty subset" (picking nothing at all)
ans = (rootInclude[0] + rootExclude[0] - 1) % MOD
return ans©leetcode
Scale cái này có gì đâu mà khó fen, cứ load đề vào trong redis/ in memory cache rồi tới giờ cho xem đề để giải quyết high peak. Một lần join có mấy chục K thằng ko xi nhê.Sập))))))) Thật sự luôn anh em nào làm Bích tếch cho tôi hỏi scale cái này khó lắm à?
Có để ý là nó gài cái midway variable ko fen lúc copy paste đề vô LLM.Đù leetcode contest giờ căng nhể, dùng AI tí mà bay màu luôn. Trước dùng AI thì ko bị sao hết

Chắc sau dùng AI lấy idea là chính, xong tử code vậy. Nãy xem top 1000 khéo phải 300 ông bay màuCó để ý là nó gài cái midway variable ko fen lúc copy paste đề vô LLM.
Mà contest thì xài ít AI thôi, mình hay xài lấy template là chính
via theNEXTvoz for iPhone
Vậy làm contest làm gì thế fen, khó nhất phần ideas rồi màChắc sau dùng AI lấy idea là chính, xong tử code vậy. Nãy xem top 1000 khéo phải 300 ông bay màu

Làm để lên goa đi ừn

road to goa đi ừn acc 3

ủa bác tím ko xóa cái tên biến dị dị là dc mà. lâu lắm ko chơi contest nhưng mà trong cái đề nó có vài ký tự mắt thường ko đọc dc yêu cầu tạo biến tên dị dị. xóa đi thì có bị bắt đâuĐù leetcode contest giờ căng nhể, dùng AI tí mà bay màu luôn. Trước dùng AI thì ko bị sao hết
là sao bácủa bác tím ko xóa cái tên biến dị dị là dc mà. lâu lắm ko chơi contest nhưng mà trong cái đề nó có vài ký tự mắt thường ko đọc dc yêu cầu tạo biến tên dị dị. xóa đi thì có bị bắt đâu![]()

nó gài mấy dòng prompt cho ai để đặt tên biến dị dị trong đề bài mà bácủa bác tím ko xóa cái tên biến dị dị là dc mà. lâu lắm ko chơi contest nhưng mà trong cái đề nó có vài ký tự mắt thường ko đọc dc yêu cầu tạo biến tên dị dị. xóa đi thì có bị bắt đâu![]()
ông nào mà copy paste đề bài vào chatgpt là dính 