
trash lang hay do thằng leetcode setup code C# để test gà thế?

Ngon
min heap cho đỡ đau đầuBài 2 dùng binary search đúng k ae? t thì dùng min heap,![]()

Có contest thì cứ vào thi thôi bác, bác rating 1k5 chắc mới làm quen, chưa thi nhiều.Xem tệp đính kèm 2696350
Đề dễ hơn hẳn tuần trước mà sợ choke nên skip mất contest này. Rating đang có 1577, các bác cho em bí kíp luyện lên 1900 với
Vl code trên ide
Toàn thế mà, top nó toàn code = IDE + có sẵn template như Bi search, Trie, UF, Segment Tree... nên code nhanh lắmVl code trên ide

Q3 nói thật mình còn thấy khó tiếp cận hơn Q4. Q4 làm toàn TLE không optimize nổi.Q3 medium 5đ tưởng đơn giản mà đề dị thật. May còn 40p thì mới có 200 accepted nên em biết contest này 2Q cũng ko bị trừ nhiều lắm
class Solution:
def minStartingIndex(self, s: str, pattern: str) -> int:
base = 60
MOD = 10**18 + 7
n = len(pattern)
lastBase = pow(base, n - 1, MOD)
basePowers = [pow(base, i, MOD) for i in range(n)]
if len(s) < n:
return -1
def calculateHash(target):
currentHash = 0
for i in range(n):
currentHash = (currentHash * base + (ord(target[i]) - ord('a'))) % MOD
return currentHash
def getHashList(pattern):
hashResult = set()
currentHash = calculateHash(pattern)
for i in range(n):
order = ord(pattern[i]) - ord('a')
originalContribution = (order * basePowers[n - i - 1]) % MOD
newHash = (currentHash - originalContribution + MOD) % MOD
if newHash < 0:
newHash += MOD
for j in range(26):
modifiedHash = (newHash + (j * basePowers[n - i - 1]) % MOD) % MOD
hashResult.add(modifiedHash)
return hashResult
patternHashes = getHashList(pattern)
h2 = calculateHash(s[:n])
if h2 in patternHashes:
return 0
left = 0
for i in range(n, len(s)):
h2 = (h2 - (ord(s[left]) - ord('a')) * lastBase) % MOD
h2 = (h2 * base + (ord(s[i]) - ord('a'))) % MOD
left += 1
if h2 < 0:
h2 += MOD
if h2 in patternHashes:
return left
return -1
Thấy tụi nó dùng zfunction pass ầm ầm mà,Q3 đọc đề thấy khó tiếp cận quá nên bỏ
Q4 xài Rabin Karp như thế này thì pass còn 1 test case, đm đời đúng đen
Python:class Solution: def minStartingIndex(self, s: str, pattern: str) -> int: base = 60 MOD = 10**18 + 7 n = len(pattern) lastBase = pow(base, n - 1, MOD) basePowers = [pow(base, i, MOD) for i in range(n)] if len(s) < n: return -1 def calculateHash(target): currentHash = 0 for i in range(n): currentHash = (currentHash * base + (ord(target[i]) - ord('a'))) % MOD return currentHash def getHashList(pattern): hashResult = set() currentHash = calculateHash(pattern) for i in range(n): order = ord(pattern[i]) - ord('a') originalContribution = (order * basePowers[n - i - 1]) % MOD newHash = (currentHash - originalContribution + MOD) % MOD if newHash < 0: newHash += MOD for j in range(26): modifiedHash = (newHash + (j * basePowers[n - i - 1]) % MOD) % MOD hashResult.add(modifiedHash) return hashResult patternHashes = getHashList(pattern) h2 = calculateHash(s[:n]) if h2 in patternHashes: return 0 left = 0 for i in range(n, len(s)): h2 = (h2 - (ord(s[left]) - ord('a')) * lastBase) % MOD h2 = (h2 * base + (ord(s[i]) - ord('a'))) % MOD left += 1 if h2 < 0: h2 += MOD if h2 in patternHashes: return left return -1

Con mẹ nó có thằng xài C++ code y chang mình nó pass hết. Đm đời đm PythonThấy tụi nó dùng zfunction pass ầm ầm mà,![]()

Tầm sư học code đi, t lấy rate thấp thôi,Con mẹ nó có thằng xài C++ code y chang mình nó pass hết. Đm đời đm Python

Thôi lần này t quyết tâm đi học C++ rồi, ko thể nào cay hơn được. Mấy contest rồiTầm sư học code đi, t lấy rate thấp thôi,![]()
