thảo luận Leetcode mỗi ngày

  • Người tạo chủ đề Người tạo chủ đề _Gia_Cat_Luong_
  • Ngày bắt đầu Ngày bắt đầu
Trạng thái
Không mở để trả lời thêm.
ngài đấm hard như con contest toàn 4/4 xuống thị phàm chốn này chăng
ZJqL4rW.png
Chủ tịch giả nghèo :shame:


via theNEXTvoz for iPhone
 
rating 2873, AC 28.3%, Hard real đấy ae, ko phải giả cầy đâu, cook luôn chứ làm làm gì nữa :angry:
kiếm bài medium khác làm bù daily, câu sv này đi pv mà hỏi là nó ko muốn tuyển mình rồi :burn_joss_stick: :amazed:
 
Sửa lần cuối:
Hard lại còn AC dưới 30% thì thôi xem solution luôn cho nhanh, đâm đầu vào lại mất toi 1 ngày. Bài này gặp lúc interview thì chào thân ái và tạm biệt luôn đỡ tốn time 2 bên :D
 
rating 2873, AC 28.3%, Hard real đấy ae, ko phải giả cầy đâu, cook luôn chứ làm làm gì nữa :angry:
kiếm bài medium khác làm bù daily, câu sv này đi pv mà hỏi là nó ko muốn tuyển mình rồi :burn_joss_stick: :amazed:
cái rating này hình như chấm theo cái AC , vừa đọc dưới phần discuss thì là cop 1 bài bên codeforce rating 2k4, vừa đào mộ thì là bài 6 điểm trong contest 346
zFNuZTA.png
, chỉ có 131/20k người giải dc
kH9BFd2.gif
 
Sửa lần cuối:
cái rating này hình như chấm theo cái AC , vừa đọc dưới phần discuss thì là cop 1 bài bên codeforce rating 2k3, vừa đào mộ thì là bài 6 điểm trong contest 346
zFNuZTA.png
, chỉ có 131/20k người giải dc
kH9BFd2.gif
yep, cái này là theo Elo rating system đó fency.
Elo 2k8 thế này như trong cờ vua là siêu đại kiện tướng rồi đó :beauty:
 
Sửa lần cuối:
Ngon, quá easy :ah: để rating gần 2k9 ra doạ người tí thôi :ah:
Python:
class Solution:
    def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:
        graph = defaultdict(list)
        for edge in edges:
            if edge[2] != -1:
                graph[edge[0]].append((edge[1], edge[2]))
                graph[edge[1]].append((edge[0], edge[2]))

        def dijktra(source):
            visitedAt = [inf]*n
            visitedAt[source] = 0
            pq = []
            pq.append((0, source))
            while pq:
                dist, vertex = heapq.heappop(pq)
                if dist > visitedAt[vertex]:
                    continue

                if vertex == destination:
                    return dist

                for neighbor, weight in graph[vertex]:
                    neighborWeight = dist + weight
                    if neighborWeight < visitedAt[neighbor]:
                        visitedAt[neighbor] = neighborWeight
                        heapq.heappush(pq, (neighborWeight, neighbor))

            return inf

        ans = []
        previousDistance = dijktra(source)
        for i in range(len(edges)):
            f,t,w = edges[i]
            if w != -1:
                ans.append([f, t, w])
                continue
            
            graph[f].append((t, 1))
            graph[t].append((f, 1))
            shortedDistance = dijktra(source)
            if shortedDistance <= target and shortedDistance < previousDistance:
                graph[f][-1] = (t, target - shortedDistance + 1)
                graph[t][-1] = (f, target - shortedDistance + 1)
                ans.append([f, t, target - shortedDistance + 1])
                for j in range(i + 1, len(edges)):
                    f,t,w = edges[j]
                    if w != -1:
                        ans.append([f, t, w])
                    else:
                        ans.append([f,t, 2*10**9])

                break

            previousDistance = shortedDistance
            ans.append([f,t, 1])

        shortedDistance = dijktra(source)
        return [] if shortedDistance != target else ans
 
Ngon, quá easy :ah: để rating gần 2k9 ra doạ người tí thôi :ah:
Python:
class Solution:
    def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:
        graph = defaultdict(list)
        for edge in edges:
            if edge[2] != -1:
                graph[edge[0]].append((edge[1], edge[2]))
                graph[edge[1]].append((edge[0], edge[2]))

        def dijktra(source):
            visitedAt = [inf]*n
            visitedAt[source] = 0
            pq = []
            pq.append((0, source))
            while pq:
                dist, vertex = heapq.heappop(pq)
                if dist > visitedAt[vertex]:
                    continue

                if vertex == destination:
                    return dist

                for neighbor, weight in graph[vertex]:
                    neighborWeight = dist + weight
                    if neighborWeight < visitedAt[neighbor]:
                        visitedAt[neighbor] = neighborWeight
                        heapq.heappush(pq, (neighborWeight, neighbor))

            return inf

        ans = []
        previousDistance = dijktra(source)
        for i in range(len(edges)):
            f,t,w = edges[i]
            if w != -1:
                ans.append([f, t, w])
                continue
           
            graph[f].append((t, 1))
            graph[t].append((f, 1))
            shortedDistance = dijktra(source)
            if shortedDistance <= target and shortedDistance < previousDistance:
                graph[f][-1] = (t, target - shortedDistance + 1)
                graph[t][-1] = (f, target - shortedDistance + 1)
                ans.append([f, t, target - shortedDistance + 1])
                for j in range(i + 1, len(edges)):
                    f,t,w = edges[j]
                    if w != -1:
                        ans.append([f, t, w])
                    else:
                        ans.append([f,t, 2*10**9])

                break

            previousDistance = shortedDistance
            ans.append([f,t, 1])

        shortedDistance = dijktra(source)
        return [] if shortedDistance != target else ans
Đúng người bảo vệ có khác mọi thứ đều easy :beauty: :beauty: :beauty:
 
Ngon, quá easy :ah: để rating gần 2k9 ra doạ người tí thôi :ah:
Python:
class Solution:
    def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:
        graph = defaultdict(list)
        for edge in edges:
            if edge[2] != -1:
                graph[edge[0]].append((edge[1], edge[2]))
                graph[edge[1]].append((edge[0], edge[2]))

        def dijktra(source):
            visitedAt = [inf]*n
            visitedAt[source] = 0
            pq = []
            pq.append((0, source))
            while pq:
                dist, vertex = heapq.heappop(pq)
                if dist > visitedAt[vertex]:
                    continue

                if vertex == destination:
                    return dist

                for neighbor, weight in graph[vertex]:
                    neighborWeight = dist + weight
                    if neighborWeight < visitedAt[neighbor]:
                        visitedAt[neighbor] = neighborWeight
                        heapq.heappush(pq, (neighborWeight, neighbor))

            return inf

        ans = []
        previousDistance = dijktra(source)
        for i in range(len(edges)):
            f,t,w = edges[i]
            if w != -1:
                ans.append([f, t, w])
                continue
           
            graph[f].append((t, 1))
            graph[t].append((f, 1))
            shortedDistance = dijktra(source)
            if shortedDistance <= target and shortedDistance < previousDistance:
                graph[f][-1] = (t, target - shortedDistance + 1)
                graph[t][-1] = (f, target - shortedDistance + 1)
                ans.append([f, t, target - shortedDistance + 1])
                for j in range(i + 1, len(edges)):
                    f,t,w = edges[j]
                    if w != -1:
                        ans.append([f, t, w])
                    else:
                        ans.append([f,t, 2*10**9])

                break

            previousDistance = shortedDistance
            ans.append([f,t, 1])

        shortedDistance = dijktra(source)
        return [] if shortedDistance != target else ans
đúng là với ngôi sao thì ở đâu cũng là sân khấu. Rating 2k9 với rating 1k cũng ko có gì khác nhau
zFNuZTA.png
 
Đúng người bảo vệ có khác mọi thứ đều easy :beauty: :beauty: :beauty:
Bài này mình đoán đoán tí thôi rồi thấy có vẻ match với hint nên code thử xem, chứ nhìn thấy rating 2k9 sợ quá.
Vẽ cái graph ra thì thấy nếu source và destination nó bị disconnect bởi các cạnh -1 thì có 2 trường hợp.
1) Nối 1 cạnh -1 vào mà nó giảm distance xuống, nghĩa là cái cạnh -1 nó contribute vô đường đi ngắn nhất.
2) Nối 1 cạnh -1 vào mà distance ko giảm xuống, nghĩa là cạnh -1 đấy nó ko contribute vô đường đi ngắn nhất.
Rồi tới bước chọn value cho các cạnh -1, nếu chọn value là 1 mà distance giảm xuống vẫn lớn hơn target thì tiếp tục tìm cạnh khác, vì 1 là số nhỏ nhất mà vẫn ko ăn thua nên bỏ qua cạnh vừa rồi.
Còn nếu chọn value là 1 mà distance giảm xuống nhỏ hơn target thì việc còn lại chỉ cần tăng cái weight lên cho nó match với target là xong, các cạnh còn lại mark là 2*10^9 để nó khỏi contribute vô kết quả.
 
Ngon, quá easy :ah: để rating gần 2k9 ra doạ người tí thôi :ah:
Python:
class Solution:
    def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:
        graph = defaultdict(list)
        for edge in edges:
            if edge[2] != -1:
                graph[edge[0]].append((edge[1], edge[2]))
                graph[edge[1]].append((edge[0], edge[2]))

        def dijktra(source):
            visitedAt = [inf]*n
            visitedAt[source] = 0
            pq = []
            pq.append((0, source))
            while pq:
                dist, vertex = heapq.heappop(pq)
                if dist > visitedAt[vertex]:
                    continue

                if vertex == destination:
                    return dist

                for neighbor, weight in graph[vertex]:
                    neighborWeight = dist + weight
                    if neighborWeight < visitedAt[neighbor]:
                        visitedAt[neighbor] = neighborWeight
                        heapq.heappush(pq, (neighborWeight, neighbor))

            return inf

        ans = []
        previousDistance = dijktra(source)
        for i in range(len(edges)):
            f,t,w = edges[i]
            if w != -1:
                ans.append([f, t, w])
                continue
          
            graph[f].append((t, 1))
            graph[t].append((f, 1))
            shortedDistance = dijktra(source)
            if shortedDistance <= target and shortedDistance < previousDistance:
                graph[f][-1] = (t, target - shortedDistance + 1)
                graph[t][-1] = (f, target - shortedDistance + 1)
                ans.append([f, t, target - shortedDistance + 1])
                for j in range(i + 1, len(edges)):
                    f,t,w = edges[j]
                    if w != -1:
                        ans.append([f, t, w])
                    else:
                        ans.append([f,t, 2*10**9])

                break

            previousDistance = shortedDistance
            ans.append([f,t, 1])

        shortedDistance = dijktra(source)
        return [] if shortedDistance != target else ans
đúng là người ngày làm chục câu, contest đều đặn khác với mấy thằng vô công rồi nghề, bài dễ lên gáy, bài khó cop sol lắm :beauty:
 
Bài này mình đoán đoán tí thôi rồi thấy có vẻ match với hint nên code thử xem, chứ nhìn thấy rating 2k9 sợ quá.
Vẽ cái graph ra thì thấy nếu source và destination nó bị disconnect bởi các cạnh -1 thì có 2 trường hợp.
1) Nối 1 cạnh -1 vào mà nó giảm distance xuống, nghĩa là cái cạnh -1 nó contribute vô đường đi ngắn nhất.
2) Nối 1 cạnh -1 vào mà distance ko giảm xuống, nghĩa là cạnh -1 đấy nó ko contribute vô đường đi ngắn nhất.
Rồi tới bước chọn value cho các cạnh -1, nếu chọn value là 1 mà distance giảm xuống vẫn lớn hơn target thì tiếp tục tìm cạnh khác, vì 1 là số nhỏ nhất mà vẫn ko ăn thua nên bỏ qua cạnh vừa rồi.
Còn nếu chọn value là 1 mà distance giảm xuống nhỏ hơn target thì việc còn lại chỉ cần tăng cái weight lên cho nó match với target là xong, các cạnh còn lại mark là 2*10^9 để nó khỏi contribute vô kết quả.
O0w112T.png
Ngày anh em được phát card không còn xa nữa rồi
jJnsOYE.png
Có CEO của FAANG nào chơi voz không?
 
Em nghĩ bây giờ các thím tính xem card bao nhiêu hợp lí là vừa, mất lòng trước được lòng sau vậy, em đề nghị tính như này.
Mỗi lần @freedom.9 gạch ai thì người đó +2$, còn nếu ưng thì +1$
ig3L68e.png
Sinh hoạt trong thread này hơn 2 tháng từ lúc @freedom.9 join thì auto 10$. Các bác thấy ổn không, có ít quá không, em sợ đòi hỏi ít quá bác ấy tưởng mình coi thường
cWAd7AE.png
 
Em nghĩ bây giờ các thím tính xem card bao nhiêu hợp lí là vừa, mất lòng trước được lòng sau vậy, em đề nghị tính như này.
Mỗi lần @freedom.9 gạch ai thì người đó +2$, còn nếu ưng thì +1$
ig3L68e.png
Sinh hoạt trong thread này hơn 2 tháng từ lúc @freedom.9 join thì auto 10$. Các bác thấy ổn không, có ít quá không, em sợ đòi hỏi ít quá bác ấy tưởng mình coi thường
cWAd7AE.png
em thấy thế là hơi ít FAANG síc phích mấy trăm k $ 1 năm tặng vài đô lẻ này k bõ
1BW9Wj4.png
 
Em nghĩ bây giờ các thím tính xem card bao nhiêu hợp lí là vừa, mất lòng trước được lòng sau vậy, em đề nghị tính như này.
Mỗi lần @freedom.9 gạch ai thì người đó +2$, còn nếu ưng thì +1$
ig3L68e.png
Sinh hoạt trong thread này hơn 2 tháng từ lúc @freedom.9 join thì auto 10$. Các bác thấy ổn không, có ít quá không, em sợ đòi hỏi ít quá bác ấy tưởng mình coi thường
cWAd7AE.png
Mình nhận cung cấp dịch vụ Clone nâng bi thuê trong f91 nhé:

  • Clone năm hoạt động cao 2013, 2014. Join Date khác nhau khó bị phát hiện.
  • Nâng bi có quote đầy đủ, dẫn chứng hiệu quả, không khen hời hợt.
  • Cách comment đa dạng, đa nhân cách.
  • Có hỗ trợ chửi đổng, tổ lái, công kích cá nhân và tìm lỗi chính tả.
  • Hoạt động bền bỉ, sẵn sàng chi viện khi khách hàng comment đuối sức.
  • Thích hợp ngược dòng, ngược gió, cân topic. :beauty: :beauty: :beauty:
 
Trạng thái
Không mở để trả lời thêm.

Thống kê chủ đề

Ngày tạo
_Gia_Cat_Luong_,
Người trả lời cuối
Vipluckystar,
Trả lời
17.755
Lượt xem
1.212.963
Quay lại
Lên đầu trang