message
stringlengths
2
19.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
322
108k
cluster
float64
15
15
__index_level_0__
int64
644
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,363
15
132,726
Yes
output
1
66,363
15
132,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,364
15
132,728
Yes
output
1
66,364
15
132,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,365
15
132,730
Yes
output
1
66,365
15
132,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,366
15
132,732
No
output
1
66,366
15
132,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,367
15
132,734
No
output
1
66,367
15
132,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,368
15
132,736
No
output
1
66,368
15
132,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell ...
instruction
0
66,369
15
132,738
No
output
1
66,369
15
132,739
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i - a_i (if 1 ≀ i - a_i) or to the position i + a_i (if i + a_i ≀ n). For each position i from 1 to n you want to know the mini...
instruction
0
66,548
15
133,096
Tags: dfs and similar, graphs, shortest paths Correct Solution: ``` from collections import deque n = int(input()) A = [int(x) for x in input().strip().split()] distance = [-1] * n edge = [[] for i in range(n)] def bfs(): queue = deque() for v in range(n): if distance[v] != -1: queue.appe...
output
1
66,548
15
133,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i - a_i (if 1 ≀ i - a_i) or to the position i + a_i (if i + a_i ≀ n). For each p...
instruction
0
66,557
15
133,114
Yes
output
1
66,557
15
133,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i - a_i (if 1 ≀ i - a_i) or to the position i + a_i (if i + a_i ≀ n). For each p...
instruction
0
66,563
15
133,126
No
output
1
66,563
15
133,127
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,714
15
133,428
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` n,m,d = map(int,input().split()) a = [] ans = [] for _ in range(n): inn = list(map(int,input().split())) a = a+inn a.sort() meanSet = [a[len(a)//2],a[(len(a)//2)-1]] for m in meanSet: temp = 0 for v in a: ret =...
output
1
66,714
15
133,429
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,715
15
133,430
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` a,b,d=map(int,input().split()) ans=[] if(a==1 and b==1): print(0) exit() for i in range(a): z=list(map(int,input().split())) ans.extend(z) ans.sort() arr=[] total=0 for i in range(1,len(ans)): arr.append(ans[i]-ans...
output
1
66,715
15
133,431
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,716
15
133,432
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` import itertools n, m, d = map(int, input().split()) a = [] for _ in range(n): a += list(map(int, input().split())) a.sort() # print(a) a = list((a[i] - a[0]) for i in range(n * m)) # print(a) if any([a[i] % d != 0 for i in rang...
output
1
66,716
15
133,433
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,717
15
133,434
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` import sys n, m, d = map(int, input().split()) a = [] for _ in range(n): a += [int(x) for x in input().split()] a.sort() for i in range(n*m-1, -1, -1): a[i] -= a[0] if a[i]%d!=0: print("-1") break else: ...
output
1
66,717
15
133,435
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,718
15
133,436
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` matrix = [] m, n, d = map(int, input().split()) for i in range(m): row = list(map(int, input().split())) for i in range(n): matrix.append(row[i]) matrix.sort() f = 0 z = matrix[0]%d for i in range(1,m*n): if(z != matrix[i]%d): ...
output
1
66,718
15
133,437
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,719
15
133,438
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` """ Author: Sagar Pandey """ # ---------------------------------------------------Import Libraries--------------------------------------------------- import sys import time import os from math import sqrt, log, log2, ceil, log10,...
output
1
66,719
15
133,439
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,720
15
133,440
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` def PoloMatrix(eles,n,m,d): x = int((n*m -1)/2) for i in range(n*m): y = eles[-1] - eles[i] if y%d != 0: print("-1") return ans = sum(eles[x+1:])-sum(eles[:x+1]) if n*m %2 == 1: ans += eles[x] print(int(ans/d)) n,m,...
output
1
66,720
15
133,441
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of...
instruction
0
66,721
15
133,442
Tags: brute force, dp, implementation, sortings, ternary search Correct Solution: ``` n,m,d=map(int,input().split()) a=[] for i in range(n): a+=(list(map(int,input().split()))) ans=0 a.sort() mid=a[len(a)//2] for i in a: x=abs(i-mid) if x%d!=0: print(-1) exit() ans+=x//d print(ans) ...
output
1
66,721
15
133,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,722
15
133,444
Yes
output
1
66,722
15
133,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,723
15
133,446
Yes
output
1
66,723
15
133,447
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,724
15
133,448
Yes
output
1
66,724
15
133,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,725
15
133,450
Yes
output
1
66,725
15
133,451
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,726
15
133,452
No
output
1
66,726
15
133,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,727
15
133,454
No
output
1
66,727
15
133,455
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,728
15
133,456
No
output
1
66,728
15
133,457
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's repr...
instruction
0
66,729
15
133,458
No
output
1
66,729
15
133,459
Provide a correct Python 3 solution for this coding contest problem. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, ...
instruction
0
67,037
15
134,074
"Correct Solution: ``` def comb(n, k): x, y = 1, 1 k = min(k, n-k) for i in range(k): x *= n - i x %= MOD y *= i + 1 y %= MOD return x*pow(y, MOD-2, MOD) % MOD def modinv(a): b=MOD (x, lastx) = (0, 1) (y, lasty) = (1, 0) while b != 0: q = a // b ...
output
1
67,037
15
134,075
Provide a correct Python 3 solution for this coding contest problem. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, ...
instruction
0
67,038
15
134,076
"Correct Solution: ``` n, m, k = map(int, input().split()) mod = 10**9+7 N = 2*10**5+50 fac = [1]*(N+1) finv = [1]*(N+1) for i in range(N): fac[i+1] = fac[i] * (i+1) % mod finv[-1] = pow(fac[-1], mod-2, mod) for i in reversed(range(N)): finv[i] = finv[i+1] * (i+1) % mod def cmb1(n, r, mod): if r <0 or r >...
output
1
67,038
15
134,077
Provide a correct Python 3 solution for this coding contest problem. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, ...
instruction
0
67,039
15
134,078
"Correct Solution: ``` MOD = 10**9 + 7 N, M, K = map(int, input().split()) def getComb(n, k, MOD): if n < k: return 0 if n-k < k: k = n-k comb = 1 for x in range(n-k+1, n+1): comb = (comb * x) % MOD d = 1 for x in range(1, k+1): d = (d * x) % MOD comb *= pow...
output
1
67,039
15
134,079
Provide a correct Python 3 solution for this coding contest problem. For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor. * insert($x$): Insert $x$ before the element indicated by...
instruction
0
67,240
15
134,480
"Correct Solution: ``` import collections class CursorList(): def __init__(self): self.vector = collections.deque() self.cursor = 0 def insert(self, x): self.vector.appendleft(x) return self def move(self, d): self.vector.rotate(-d) self.cursor += d ...
output
1
67,240
15
134,481
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,251
15
134,502
Tags: binary search, two pointers Correct Solution: ``` import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 MAXRIGHT = 10 ** 9 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def ...
output
1
67,251
15
134,503
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,252
15
134,504
Tags: binary search, two pointers Correct Solution: ``` from collections import namedtuple import sys HS = namedtuple('HS', 'x1 x2 y') n, m = [int(w) for w in input().split()] vs = [int(input()) for _ in range(n)] hs = [HS(*[int(w) for w in input().split()]) for _ in range(m)] vs.sort() hr = len([s for s in hs if s...
output
1
67,252
15
134,505
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,253
15
134,506
Tags: binary search, two pointers Correct Solution: ``` n,m=map(int, input().split()) cols=[] for i in range(n): cols.append(int(input())) rows=[] for i in range(m): k=list(map(int, input().split())) if k[0]==1: rows.append(k[1]) ans=n+m cols.sort() rows.sort() cols.append(int(1e9)) j=0 rem=0 # pri...
output
1
67,253
15
134,507
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,254
15
134,508
Tags: binary search, two pointers Correct Solution: ``` from bisect import bisect_left def readint(): return int(input()) def readline(): return [int(c) for c in input().split()] # similar to 45311982 def main(): MAX = 10**9 n, m = readline() v = sorted([readint() for _ in range(n)]) h = []...
output
1
67,254
15
134,509
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,255
15
134,510
Tags: binary search, two pointers Correct Solution: ``` from bisect import bisect n, m = map(int, input().split()) vv = sorted([int(input()) for _ in range(n)]) hh = [0] * n rr = 0 for _ in range(m): one, x, _ = map(int, input().split()) if one == 1: if x == 1000000000: rr += 1 else: ind = bis...
output
1
67,255
15
134,511
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,256
15
134,512
Tags: binary search, two pointers Correct Solution: ``` n,m = map(int,input().split()) x = [0]*(n+1) for i in range(n): x[i] = int(input()) x[n] = 1000000000 vert = [] for i in range(m): x1,x2,y = map(int,input().split()) if x1 == 1: vert.append(x2) vert.sort() x.sort() cur = 0 minicount = n+m k = l...
output
1
67,256
15
134,513
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,257
15
134,514
Tags: binary search, two pointers Correct Solution: ``` #n=int(input()) n,m=map(int,input().split()) vert=[] for i in range(n): v=int(input()) vert.append(v) horz=[] for i in range(m): x1,x2,y=map(int,input().split()) if x1==1: horz.append(x2) vert.sort() horz.sort() vert.append(1000000000...
output
1
67,257
15
134,515
Provide tags and a correct Python 3 solution for this coding contest problem. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the...
instruction
0
67,258
15
134,516
Tags: binary search, two pointers Correct Solution: ``` n, m = map(int, input().split()) ver = [int(input()) for _ in range(n)] ver.append(10 ** 9) hor = [] for _ in range(m): x1, x2, y = map(int, input().split()) if x1 == 1: hor.append(x2) hor.sort() ver.sort() j = 0 ans = 10 ** 18 for i in range(n + 1...
output
1
67,258
15
134,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,259
15
134,518
Yes
output
1
67,259
15
134,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,260
15
134,520
Yes
output
1
67,260
15
134,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,261
15
134,522
Yes
output
1
67,261
15
134,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,262
15
134,524
Yes
output
1
67,262
15
134,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,263
15
134,526
No
output
1
67,263
15
134,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,264
15
134,528
No
output
1
67,264
15
134,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,265
15
134,530
No
output
1
67,265
15
134,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for...
instruction
0
67,266
15
134,532
No
output
1
67,266
15
134,533
Provide tags and a correct Python 3 solution for this coding contest problem. Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the fo...
instruction
0
67,267
15
134,534
Tags: dp Correct Solution: ``` def f(x, m): if x < m: return (m, x) else: return (m * 2 - x, m) n = int(input()) d = {0 : [0]} for i in range(n): x, y = map(int, input().split()) m = max(x, y) if m in d: if x == m: d[m].append(y) else: d[m].ap...
output
1
67,267
15
134,535
Provide tags and a correct Python 3 solution for this coding contest problem. Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the fo...
instruction
0
67,268
15
134,536
Tags: dp Correct Solution: ``` import collections, heapq def dijkstra(g, st): """Dijkstra method""" n = len(g) d = [float('inf')] * n d[st] = 0 que = [(0, st)] # (min_dist, vertex) heapq.heapify(que) while len(que) > 0: dist, v0 = heapq.heappop(que) if d[v0] < dist: c...
output
1
67,268
15
134,537
Provide tags and a correct Python 3 solution for this coding contest problem. Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the fo...
instruction
0
67,269
15
134,538
Tags: dp Correct Solution: ``` def get_input_list(): return list(map(int, input().split())) def sort_(p): np = [] for i in p: np.append([i[0],-i[1]]) np.sort() return np def distance(A,B): return abs(B[0] - A[0]) + abs(B[1] - A[1]) n = int(input()) p_ = [] for _ in range(n): p_.append(get_input_list()) d = {}...
output
1
67,269
15
134,539
Provide tags and a correct Python 3 solution for this coding contest problem. Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the fo...
instruction
0
67,270
15
134,540
Tags: dp Correct Solution: ``` from collections import defaultdict n = int(input()) points = defaultdict(list) points[0].append((0,0)) for i in range(n): x,y = map(int,input().split()) points[max(x,y)].append((x,y)) for level in points: points[level].sort(key=lambda x:(x[0],-x[1])) levels = sorted(points.keys()) dp ...
output
1
67,270
15
134,541