s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s560163810 | p02285 | u881590806 | 1449668448 | Python | Python | py | Runtime Error | 10 | 6392 | 2175 | def insert(tree,k):
y = None
x = tree
z = {'key':k, 'parent':None, 'left':None, 'right':None}
while x != None:
y = x
if x['key'] > k:
x = x['left']
else:
x = x['right']
z['parent'] = y
if y == None:
tree = z
elif y['key'] > k:
y... |
s679489398 | p02285 | u797673668 | 1454182412 | Python | Python3 | py | Runtime Error | 30 | 7768 | 2282 | class Tree:
root = None
def insert(self, node):
y = None
x = self.root
while x:
y = x
x = x.left if node.key < x.key else x.right
node.parent = y
if not y:
self.root = node
elif node.key < y.key:
y.left = node
... |
s247645851 | p02285 | u247976584 | 1455382247 | Python | Python3 | py | Runtime Error | 20 | 7892 | 2579 | class BinarySearchTree:
root = None
def insert(self, k):
y = None
x = self.root
z = Node(k)
while x:
y = x
if z.k < x.k:
x = x.l
else:
x = x.r
z.p = y
if y == None:
self.root... |
s387900155 | p02285 | u342312206 | 1463422152 | Python | Python3 | py | Runtime Error | 80 | 7776 | 5512 | import sys
import os
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert_node(self, node):
if node.value <= self.value:
if self.left is None:
self.left = node
else:
... |
s290572618 | p02285 | u890722286 | 1475422754 | Python | Python3 | py | Runtime Error | 20 | 7760 | 2354 | def insert(r, n):
if 0 == len(T):
T[n] = [None, None, None]
else:
if n < r:
left = T[r][0]
if left == None:
T[r][0] = n
T[n] = [None, None, r]
else:
insert(left, n)
if r < n:
right = T[r][1]
... |
s216977630 | p02285 | u890722286 | 1475426516 | Python | Python3 | py | Runtime Error | 30 | 7820 | 2717 | def insert(r, n):
if 0 == len(T):
T[n] = [None, None, None]
else:
if n < r:
left = T[r][0]
if left == None:
T[r][0] = n
T[n] = [None, None, r]
else:
insert(left, n)
if r < n:
right = T[r][1]
... |
s450938898 | p02285 | u367979558 | 1477437112 | Python | Python3 | py | Runtime Error | 30 | 7860 | 3481 | import sys
class Node:
def __init__(self, x, parent=None):
self.key = x
self.left = None
self.right = None
self.parent = parent
def append_child(self, child):
if self.key > child.key:
self.left = child
child.parent = self
elif self.key < ... |
s997698070 | p02285 | u159356473 | 1479113486 | Python | Python3 | py | Runtime Error | 0 | 0 | 1101 |
def Pre(t,l):
l.append(str(t.n))
if t.left!=None:
Pre(t.left,l)
if t.right!=None:
Pre(t.right,l)
def In(t,l):
if t.left!=None:
In(t.left,l)
l.append(str(t.n))
if t.right!=None:
In(t.right,l)
def BST3(A,n):
tree=None
for i in range(n):
if A[i]=="... |
s880062429 | p02285 | u159356473 | 1479113752 | Python | Python3 | py | Runtime Error | 30 | 7756 | 2373 | #coding:UTF-8
class Node:
def __init__(self,point):
self.n=point
self.left=None
self.right=None
def Insert(t,z):
y=None
x=t
while x!=None:
y=x
if z.n<x.n:
x=x.left
else:
x=x.right
if y==None:
return z
else:
... |
s135585703 | p02285 | u742013327 | 1480576471 | Python | Python3 | py | Runtime Error | 40 | 7844 | 3586 | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_A
#???????????? 15??? 8A????????????
def insert(root, insert_node):
focus_node = root
parent = None
while not focus_node == None:
parent = focus_node
if focus_node["data"] > insert_node["data"]:
focus_node = focu... |
s286631900 | p02285 | u811733736 | 1481003950 | Python | Python3 | py | Runtime Error | 30 | 7772 | 5861 | class Node(object):
root = None
def __init__(self, key, parent=None, left=None, right=None):
self.key = key
self.parent = parent
self.left = left
self.right = right
self.height = None
@classmethod
def insert(cls, z):
y = None
x = cls.root
... |
s612748559 | p02285 | u923668099 | 1485033821 | Python | Python3 | py | Runtime Error | 20 | 7884 | 3209 | import sys
NIL = -1
class Node:
def __init__(self, key):
self.key = key
self.parent = NIL
self.left = NIL
self.right = NIL
class Tree:
def __init__(self):
self.root = NIL
def insert(self, z):
y = NIL
x = self.root
while x != NIL:
... |
s380049206 | p02285 | u462831976 | 1489839444 | Python | Python3 | py | Runtime Error | 50 | 11704 | 5485 | # -*- coding: utf-8 -*-
import random
import sys
import os
class Tree:
def __init__(self):
self.root = None
def __str__(self):
if self.root == None:
return None
else:
return "TODO"
def print_inorder(self):
self.inorder_list = []
self.__ino... |
s136748110 | p02285 | u089830331 | 1493691624 | Python | Python3 | py | Runtime Error | 20 | 7648 | 1801 | class Node:
def __init__(self, num):
self.key = num
self.p = None
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
def insert(self, z):
y = None
x = self.root
while x != None:
y = x
if z.key < x.key:
x = x.left
... |
s658491441 | p02285 | u603049633 | 1496368528 | Python | Python3 | py | Runtime Error | 20 | 7800 | 2941 | #BinarySearchTree
class TreeNode():
def __init__(self):
self.key = None
self.parent = None
self.left = None
self.right = None
def inoder(self):
r=[]
if self.left:
r += self.left.inoder()
r += [self.key]
if self.right:
r += s... |
s266235921 | p02285 | u067677727 | 1498791300 | Python | Python3 | py | Runtime Error | 20 | 7900 | 3077 | import sys
class Node:
def __init__(self, x):
self.data = x
self.left = None
self.right = None
def insert(node, x):
if node == None:
return Node(x)
elif x == node.data:
return node
elif x < node.data:
node.left = Node.inse... |
s911997217 | p02285 | u067677727 | 1498791344 | Python | Python3 | py | Runtime Error | 30 | 7812 | 3077 | import sys
class Node:
def __init__(self, x):
self.data = x
self.left = None
self.right = None
def insert(node, x):
if node == None:
return Node(x)
elif x == node.data:
return node
elif x < node.data:
node.left = Node.inse... |
s957522152 | p02285 | u796784914 | 1500101679 | Python | Python | py | Runtime Error | 10 | 6496 | 3052 | import sys
def main():
n = input()
tree = MyBinaryTree(n)
for i in range(n):
cmd = map(str,raw_input().split())
if cmd[0] == "insert":
insert(tree,MyNode(int(cmd[1])))
elif cmd[0] == "print":
tree.inorder(tree.root)
print ""
tree.preor... |
s423814458 | p02285 | u193453446 | 1502259715 | Python | Python3 | py | Runtime Error | 20 | 7828 | 3080 |
import sys
YES = "yes"
NO = "no"
class Node:
def __init__(self, value, p = None, l = None, r = None):
self.key = value
self.p = p
self.left = l
self.right = r
def chgchild(parent, old, new = None):
if parent == None:
return
else:
# print("parent:{}".format(... |
s792540443 | p02285 | u491916705 | 1502717357 | Python | Python | py | Runtime Error | 10 | 6576 | 3713 | class Node():
def __init__(self, id, left=-1, right=-1, parent=-1, type=None):
self.id = id
self.left = left
self.right = right
self.parent = parent
def show(self):
print 'node %d: parent = %d, left = %d, right = %d' % (self.id, self.parent, self.left, self.right... |
s228178932 | p02285 | u519227872 | 1503239339 | Python | Python3 | py | Runtime Error | 20 | 7756 | 2483 | m = int(input())
class Node:
def __init__(self, key, left ,right):
self.key = key
self.left = left
self.right = right
class BinaryTree():
def __init__(self):
self.root = None
def getRoot(self):
return self.root
def setRoot(self, v):
self.root = v
... |
s092615453 | p02285 | u024715419 | 1510050987 | Python | Python3 | py | Runtime Error | 30 | 7888 | 2975 | class BinaryTree():
def __init__(self):
self.root = None
def insert(self, insert_node):
p = None
r = self.root
while r:
p = r
if insert_node.value < r.value:
r = r.left
else:
r = r.right
if not p:
... |
s741820554 | p02285 | u024715419 | 1510052250 | Python | Python3 | py | Runtime Error | 20 | 7824 | 2976 | class BinaryTree():
def __init__(self):
self.root = None
def insert(self, insert_node):
p = None
r = self.root
while r:
p = r
if insert_node.value < r.value:
r = r.left
else:
r = r.right
if not p:
... |
s335531148 | p02285 | u248416507 | 1512966532 | Python | Python | py | Runtime Error | 10 | 4864 | 3462 |
class Node(object):
def __init__(self, key):
self.left = None
self.right = None
self.parent = None
self.key = key
class Tree(object):
def __init__(self):
self.root = None
def insert(self, new_key):
x = self.root
y = None
while x is not... |
s833525987 | p02285 | u426534722 | 1518024018 | Python | Python3 | py | Runtime Error | 20 | 5624 | 3366 | import sys
readline = sys.stdin.readline
class Node:
__slots__ = ['value', 'p', 'left', 'right']
def __init__(self, value = None, p = None, left = None, right = None):
self.value = value
self.p = p
self.left = left
self.right = right
class BinTree:
__slots__ = ['_tree', 'resu... |
s049975866 | p02285 | u426534722 | 1518200760 | Python | Python3 | py | Runtime Error | 20 | 5624 | 2740 | import sys
readline = sys.stdin.readline
class Node:
__slots__ = ['value', 'left', 'right']
def __init__(self, value = None, left = None, right = None):
self.value = value
self.left = left
self.right = right
class BinTree:
__slots__ = ['_tree', 'result']
def __init__(self):
... |
s077990273 | p02285 | u426534722 | 1518200817 | Python | Python3 | py | Runtime Error | 20 | 5624 | 2846 | import sys
readline = sys.stdin.readline
class Node:
__slots__ = ['value', 'left', 'right']
def __init__(self, value = None, left = None, right = None):
self.value = value
self.left = left
self.right = right
class BinTree:
__slots__ = ['_tree', 'result']
def __init__(self):
... |
s340711662 | p02285 | u426534722 | 1518200864 | Python | Python3 | py | Runtime Error | 20 | 5624 | 2837 | import sys
readline = sys.stdin.readline
class Node:
__slots__ = ['value', 'left', 'right']
def __init__(self, value = None, left = None, right = None):
self.value = value
self.left = left
self.right = right
class BinTree:
__slots__ = ['_tree', 'result']
def __init__(self):
... |
s479544306 | p02285 | u177808190 | 1519676917 | Python | Python3 | py | Runtime Error | 30 | 6020 | 3770 | import collections
sent = -1
def insert(hoge, new_node, root):
#print(hoge)
parent_maybe = sent
now_looking = root
hoge[new_node]['node_id'] = new_node
while now_looking != sent:
parent_maybe = now_looking
if new_node < hoge[now_looking]['node_id']:
now_looking = hoge[no... |
s069318709 | p02285 | u177808190 | 1519682280 | Python | Python3 | py | Runtime Error | 30 | 6028 | 4155 | import collections
sent = None
def insert(hoge, new_node, root):
parent_maybe = sent
now_looking = root
hoge[new_node]['node_id'] = new_node
while now_looking != sent:
parent_maybe = now_looking
if new_node < hoge[now_looking]['node_id']:
now_looking = hoge[now_looking]['lef... |
s742306974 | p02285 | u177808190 | 1519721157 | Python | Python3 | py | Runtime Error | 30 | 6032 | 4164 | import collections
sent = None
def insert(hoge, new_node, root):
parent_maybe = sent
now_looking = root
hoge[new_node]['node_id'] = new_node
while now_looking != sent:
parent_maybe = now_looking
#print(hoge[now_looking], now_looking)
if new_node < hoge[now_looking]['node_id']:
... |
s502182930 | p02285 | u613534067 | 1522284191 | Python | Python3 | py | Runtime Error | 20 | 5616 | 2656 | # Binary Search Tree
class Node:
def __init__(self, v):
self.value = v
self.parent = None
self.left = None
self.right = None
# 再帰を使わないパターンの方が早い
def insert(node):
global root
y = None
x = root
while x is not None:
y = x
if node.value < x.value:
... |
s413123620 | p02285 | u126478680 | 1526977821 | Python | Python3 | py | Runtime Error | 30 | 5640 | 3155 | class BinaryTreeNode():
def __init__(self, val, parent=None, left=None, right=None):
self.parent = parent
self.left = None
self.right = None
self.val = val
def get_child_num(self):
num = 0
if self.left != None: num += 1
if self.right != None: num += 1
... |
s697770948 | p02285 | u912237403 | 1374055917 | Python | Python | py | Runtime Error | 0 | 0 | 2092 | import sys
tree={}
np = -1
home=0
tree[home]=[None, None, None]
def search(p, x):
node_pos=[None,None]
while p != None:
tmp = tree[p]
if tmp[0] == x:
node_pos[0] = p
return node_pos
node_pos[1] = p
if x < tmp[0]:
p = tmp[1]
else:
... |
s779959076 | p02285 | u912237403 | 1374056420 | Python | Python | py | Runtime Error | 20 | 4444 | 2091 | import sys
tree={}
np = -1
home=0
tree[home]=[None, None, None]
def search(p, x):
node_pos=[None,None]
while p != None:
tmp = tree[p]
if tmp[0] == x:
node_pos[0] = p
return node_pos
node_pos[1] = p
if x < tmp[0]:
p = tmp[1]
else:
... |
s039258973 | p02286 | u686180487 | 1559201043 | Python | Python3 | py | Runtime Error | 0 | 0 | 2030 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority):
self.key = key
self.priority = priority
self.left = None
self.right = None
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.left
s.left = t
return ... |
s788602531 | p02286 | u686180487 | 1559202368 | Python | Python3 | py | Runtime Error | 0 | 0 | 2037 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority):
self.key = key
self.priority = priority
self.left = None
self.right = None
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.left
s.left = t
return ... |
s360246109 | p02286 | u686180487 | 1559202550 | Python | Python3 | py | Runtime Error | 0 | 0 | 2053 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority):
self.key = key
self.priority = priority
self.left = None
self.right = None
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.left
s.left = t
return ... |
s604940630 | p02286 | u686180487 | 1559202639 | Python | Python3 | py | Runtime Error | 0 | 0 | 2077 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority, left=None, right=None):
self.key = key
self.priority = priority
self.left = left
self.right = right
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.lef... |
s605174680 | p02286 | u686180487 | 1559203552 | Python | Python3 | py | Runtime Error | 0 | 0 | 2068 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority, left=None, right=None):
self.key = key
self.priority = priority
self.left = left
self.right = right
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.lef... |
s477913671 | p02286 | u686180487 | 1559204035 | Python | Python3 | py | Runtime Error | 0 | 0 | 2084 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority, left=None, right=None):
self.key = key
self.priority = priority
self.left = left
self.right = right
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.lef... |
s645249951 | p02286 | u686180487 | 1559204359 | Python | Python3 | py | Runtime Error | 0 | 0 | 1999 | # -*- coding: utf-8 -*-
class Node:
def __init__(self, key, priority, left=None, right=None):
self.key = key
self.priority = priority
self.left = left
self.right = right
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.lef... |
s342737246 | p02286 | u825008385 | 1527002690 | Python | Python3 | py | Runtime Error | 0 | 0 | 2556 | # Treap
class Node():
def __init__(self, k, p):
self.k = k
self.p = p
self.left = None
self.right = None
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.left
s.left = t
return s
def ins... |
s718839646 | p02287 | u643021750 | 1545223782 | Python | Python3 | py | Runtime Error | 0 | 0 | 798 | #include<iostream>
using namespace std;
#define MAX 100000 // defineは文字列を指定した文字で置き換える。constは変数を格納している。
// 2分接点の各情報を出力する
int parent(int i) { return i / 2;}
int left(int i) { return 2 * i;}
int right(int i) { return 2 * i + 1;}
int main() {
int H, i, A[MAX+1]; // 1-オリジンのため +1する
cin >> H;
for (i =1; i <= H; i++)... |
s783922582 | p02287 | u130979865 | 1460500529 | Python | Python | py | Runtime Error | 0 | 0 | 472 | # -*- coding: utf-8 -*-
n = int(raw_input())
l = map(int, raw_input().split())
A = [0]
for i in range(n):
A.append(l[i])
print "node %d: key = %d, left key = %d, right key = %d, " %(1, A[1], A[2*1], A[2*1+1])
for i in range(2, int(n/2+1)):
print "node %d: key = %d, parent key = %d, left key = %d, right key = %... |
s850927894 | p02287 | u603356762 | 1470473459 | Python | Python3 | py | Runtime Error | 0 | 0 | 769 | n = int(input())
keys = list(map(int, input().split()))
#n=5
#heap_keys = [7,8,1,2,3]
heap = []
for i,x in enumerate(heap_keys):
node = i+1
key = x
parent_key = heap_keys[int(node/2)-1] if i > 0 else None
left_key = heap_keys[2*node-1] if 2*node-1 <len(heap_keys) else None
right_key = heap_keys[2*no... |
s250392539 | p02287 | u091533407 | 1500164750 | Python | Python3 | py | Runtime Error | 0 | 0 | 1227 | def print_heap():
for i in range(n):
if (i-1)//2 in range(n):
if 2*i+1 in range(n):
if 2*1+2 in range(n):
print("node {}: key = {}, parent key = {}, left key = {}, right key = {},"
.format(i+1, heap[i], heap[(i-1)//2], heap[2*i+1], he... |
s701368653 | p02287 | u135421061 | 1523855589 | Python | Python3 | py | Runtime Error | 0 | 0 | 692 | import sys
import numpy as np
def BinaryTree(array):
for i in range(1,len(array)):
print("node " + str(i) + ": key = " + str(array[i]),end="")
if(i != 1):
print(", parent key = " + str(array[int(i / 2)]),end="")
if(2*i < len(array)):
print(", left key = " + str(arra... |
s286274197 | p02287 | u135421061 | 1523855677 | Python | Python3 | py | Runtime Error | 0 | 0 | 694 | import sys
import numpy as np
def BinaryTree(array):
for i in range(1,len(array)):
print("node " + str(i) + ": key = " + str(array[i]),end="")
if(i != 1):
print(", parent key = " + str(array[int(i / 2)]),end="")
if(2*i < len(array)):
print(", left key = " + str(arra... |
s088216588 | p02287 | u135421061 | 1523855723 | Python | Python3 | py | Runtime Error | 0 | 0 | 694 | import sys
import numpy as np
def BinaryTree(array):
for i in range(1,len(array)):
print("node " + str(i) + ": key = " + str(array[i]),end="")
if(i != 1):
print(", parent key = " + str(array[int(i / 2)]),end="")
if(2*i < len(array)):
print(", left key = " + str(arra... |
s465232623 | p02287 | u135421061 | 1523855939 | Python | Python3 | py | Runtime Error | 0 | 0 | 682 | import sys
import numpy as np
def BinaryTree(array):
for i in range(1,len(array)):
print("node " + str(i) + ": key = " + str(array[i]),end="")
if(i != 1):
print(", parent key = " + str(array[int(i / 2)]),end="")
if(2*i < len(array)):
print(", left key = " + str(arra... |
s719250334 | p02287 | u135421061 | 1523855976 | Python | Python3 | py | Runtime Error | 0 | 0 | 682 | import sys
import numpy as np
def BinaryTree(array):
for i in range(1,len(array)):
print("node " + str(i) + ": key = " + str(array[i]),end="")
if(i != 1):
print(", parent key = " + str(array[int(i / 2)]),end="")
if(2*i < len(array)):
print(", left key = " + str(arra... |
s199345060 | p02287 | u135421061 | 1523855999 | Python | Python3 | py | Runtime Error | 0 | 0 | 682 | import sys
import numpy as np
def BinaryTree(array):
for i in range(1,len(array)):
print("node " + str(i) + ": key = " + str(array[i]),end="")
if(i != 1):
print(", parent key = " + str(array[int(i / 2)]),end="")
if(2*i < len(array)):
print(", left key = " + str(arra... |
s905206531 | p02287 | u724548524 | 1525409702 | Python | Python3 | py | Runtime Error | 0 | 0 | 309 | n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
print(f"node {i}: key = {a[i]}," + (f" parent key = {a[int(i / 2)]}," if i != 1: else "") + (f"{ left key = {a[2 * i]}, " if i * 2 <= n: else = "") + (f" right key = {a[2 * i + 1]}," if 2 * i + 1 <= n: else = ""))
|
s321964193 | p02287 | u559106458 | 1529408524 | Python | Python3 | py | Runtime Error | 0 | 0 | 705 | #coding-utf8
#Complete Binary Tree
list=[]
list.append("sentinel")
def parent(i):
return i//2
def left(i):
return i*2
def right(i):
return i*2+1
def main():
H=int(input())
for i in range(H):
i+=1
list.append(int(input()))
for i in range(H):
i+=1
print("node "... |
s239324120 | p02287 | u559106458 | 1529408574 | Python | Python3 | py | Runtime Error | 0 | 0 | 705 | #coding-utf8
#Complete Binary Tree
list=[]
list.append("sentinel")
def parent(i):
return i//2
def left(i):
return i*2
def right(i):
return i*2+1
def main():
H=int(input())
for i in range(H):
i+=1
list.append(int(input()))
for i in range(H):
i+=1
print("node "... |
s568942580 | p02287 | u559106458 | 1529408593 | Python | Python3 | py | Runtime Error | 0 | 0 | 705 | #coding-utf8
#Complete Binary Tree
list=[]
list.append("sentinel")
def parent(i):
return i//2
def left(i):
return i*2
def right(i):
return i*2+1
def main():
H=int(input())
for i in range(H):
i+=1
list.append(int(input()))
for i in range(H):
i+=1
print("node "... |
s261014024 | p02288 | u805716376 | 1551282300 | Python | Python3 | py | Runtime Error | 0 | 0 | 341 | H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
l=2*i;r=l+1
if r<H &&l<H :
if A[i]<A[l]:
if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
else:A[i],A[l]=A[l],A[i];h(l)
elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
elif l<H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.j... |
s648651381 | p02288 | u805716376 | 1551282333 | Python | Python3 | py | Runtime Error | 0 | 0 | 341 | H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
l=2*i;r=l+1
if r<H && l<H:
if A[i]<A[l]:
if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
else:A[i],A[l]=A[l],A[i];h(l)
elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
elif l<H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.j... |
s450718300 | p02288 | u879226672 | 1432123846 | Python | Python | py | Runtime Error | 0 | 0 | 546 | # coding: utf-8
def maxHeapify(A, i):
l = A[2*(i+1)-1]
r = A[2*(i+1)]
if l <= H and A[l] > A[i]:
largest = l
else:
largest = i
if r <= H and A[r] > A[largest]:
largest = r
if largest != i:???# i ???????????????????????§????????´???
A[i],A[largest] = A[largest],A[i... |
s666534089 | p02288 | u811733736 | 1481014527 | Python | Python3 | py | Runtime Error | 0 | 0 | 810 | def max_heapify(A, i):
l = 2 * i
r = 2 * i + 1
largest = i
if l <= len(A) and A[l] > A[i]:
largest = l
else:
largest = i
if r < len(A) and A[r] > A[largest]:
largest = r
if largest != i:
temp = A[i]
A[i] = A[largest]
A[largest] = temp
... |
s195331766 | p02288 | u742013327 | 1481621209 | Python | Python3 | py | Runtime Error | 20 | 7604 | 788 | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_B
#???????????? 17:55~
def maxHeapify(heap, index):
left_index = 2 * index
right_index = 2 * index + 1
left = heap[left_index] if left_index < len(heap) else -1
right = heap[right_index] if right_index < len(heap) else -1
largest_ind... |
s575975270 | p02288 | u112247126 | 1487816773 | Python | Python3 | py | Runtime Error | 0 | 0 | 569 | def maxHeapify(heap, i):
while (i + 1) * 2 <= len(heap):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] else i
largest = right if heap[right] > heap[largest]
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
... |
s350820194 | p02288 | u112247126 | 1487816885 | Python | Python3 | py | Runtime Error | 0 | 0 | 620 | def maxHeapify(heap, i):
while (i + 1) * 2 <= len(heap):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left <= len(heap) else i
largest = right if heap[right] > heap[largest] and right <= len(heap)
if largest != i:
heap[i], ... |
s359450692 | p02288 | u112247126 | 1487817436 | Python | Python3 | py | Runtime Error | 0 | 0 | 591 | def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left <= len(heap) else i
largest = right if heap[right] > heap[largest] and right <= len(heap) else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
... |
s331273783 | p02288 | u112247126 | 1487817506 | Python | Python3 | py | Runtime Error | 0 | 0 | 591 | def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left <= len(heap) else i
largest = right if heap[right] > heap[largest] and right <= len(heap) else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
... |
s058814189 | p02288 | u112247126 | 1487817598 | Python | Python3 | py | Runtime Error | 0 | 0 | 616 | def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left <= len(heap) else i
largest = right if heap[right] > heap[largest] and right <= len(heap) else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
... |
s892248710 | p02288 | u112247126 | 1487817724 | Python | Python3 | py | Runtime Error | 0 | 0 | 590 | def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left < len(heap) else i
largest = right if heap[right] > heap[largest] and right < len(heap) else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
ma... |
s741862508 | p02288 | u112247126 | 1487817779 | Python | Python3 | py | Runtime Error | 0 | 0 | 590 | def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left < len(heap) else i
largest = right if heap[right] > heap[largest] and right < len(heap) else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
ma... |
s002164390 | p02288 | u112247126 | 1487817803 | Python | Python3 | py | Runtime Error | 0 | 0 | 614 | def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left < len(heap) else i
largest = right if heap[right] > heap[largest] and right < len(heap) else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
ma... |
s700998177 | p02288 | u112247126 | 1487818072 | Python | Python3 | py | Runtime Error | 0 | 0 | 655 | # ????????????????????????????????????
def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if heap[left] > heap[i] and left < len(heap) else i
largest = right if heap[right] > heap[largest] and right < len(heap) else largest
if largest != i:
heap[i], heap[larg... |
s090628955 | p02288 | u150984829 | 1519611334 | Python | Python3 | py | Runtime Error | 0 | 0 | 229 | input()
A=[0]+list(map(int,input().split()))
H=len(A)
def h(i):
l=2*i;r,g=l+1,[i,l][A[i]<A[l]and l<H]
if A[g]<A[r]and r<H:g=r
if g!=i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))
|
s676329062 | p02288 | u150984829 | 1519612793 | Python | Python3 | py | Runtime Error | 0 | 0 | 222 | H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
g=A.index(max(A[i],A[i,2*i][2*i<H],A[i,2*i+1][2*i+1<H]))
if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))
|
s979642463 | p02288 | u150984829 | 1519614191 | Python | Python3 | py | Runtime Error | 0 | 0 | 258 | H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
l=2*i;r=l+1
g=i
if r<H and A[g]<A[r]:g=l if A[i]<A[l]else r
else:if l<H and A[i]<A[l]:g=l
if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))
|
s040704980 | p02288 | u135421061 | 1523861063 | Python | Python3 | py | Runtime Error | 0 | 0 | 880 | import numpy as np
import sys
def maxHeapify(array,i):
l = 2 * i
r = 2 * i + 1
largest = i
#print("i,array[i] ==: " + str(i) + ", " + str(array[i]))
#print(array)
if( l < (len(array))):
if(array[l] > array[i]):
largest = l
else:
largest = i
if( r < ... |
s055523782 | p02288 | u135421061 | 1523861378 | Python | Python3 | py | Runtime Error | 0 | 0 | 884 | import numpy as np
import sys
def maxHeapify(array,i):
l = 2 * i
r = 2 * i + 1
largest = i
#print("i,array[i] ==: " + str(i) + ", " + str(array[i]))
#print(array)
if( l < (len(array))):
if(array[l] > array[i]):
largest = l
else:
largest = i
if( r < ... |
s090252665 | p02289 | u007270338 | 1535531301 | Python | Python3 | py | Runtime Error | 0 | 0 | 998 | #coding: utf-8
A = []
inf = 100000000000
def maxHeapify(A, i):
l = 2 * i
r = 2 * i + 1
H = len(A)
if l <= H and A[l] > A[i]:
largest = l
else:
largest = i
if r <= H and A[r] > A[largest]:
largest = r
if largest != i:
A[i], A[largest] = A[largest], A[i] ... |
s205342381 | p02289 | u800534567 | 1540306919 | Python | Python3 | py | Runtime Error | 0 | 0 | 827 | #include <stdio.h>
#include <stdlib.h>
#define SIZE 2000000
int main() {
int A[SIZE];
int H=0;
int i, l, largest, tmp;
char com[20];
do {
fgets(com, 20, stdin);
if (com[0] == 'i') { // insert nn
A[++H] = atoi(com+7);
for (i=H; i>1 && A[i/2]<A[i];i/=2) {
tmp = A[i/2];
... |
s517861371 | p02289 | u800534567 | 1540307931 | Python | Python3 | py | Runtime Error | 0 | 0 | 1035 | #include <stdio.h>
#define SIZE 2000000
int myatoi(const char* p)
{
int n;
while (*p!='\n') {
n = n*10+*p-'0';
p++;
}
return n;
}
void putnum(int n)
{
int i;
char buf[20];
buf[19]='\0';
for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
puts(buf+i+1);
}javascript:void(0)
int main() {
int A[SIZE... |
s494703360 | p02289 | u800534567 | 1540307984 | Python | Python3 | py | Runtime Error | 0 | 0 | 1041 | #include <stdio.h>
#define SIZE 2000000
int myatoi(const char* p)
{
int n;
while (*p!='\n') {
n = n*10+*p-'0';
p++;
}
return n;
}
void putnum(int n)
{
int i;
char buf[20];
buf[19]='\0';
for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
puts(buf+i+1);
}
int main() {
int A[SIZE];
int H=0;
in... |
s600314357 | p02289 | u800534567 | 1540308472 | Python | Python3 | py | Runtime Error | 0 | 0 | 898 | #include <stdio.h>
#define SIZE 2000000
int myatoi(const char* p)
{
int n;
while (*p!='\n') {
n = n*10+*p-'0';
p++;
}
return n;
}
int main() {
int A[SIZE];
int H=0;
int i, l, largest, tmp;
char com[21];
do {
fgets(com, 20, stdin);
if (com[0] == 'i') {
A[++H] = myatoi(com+7);
... |
s661590400 | p02289 | u800534567 | 1540308486 | Python | Python3 | py | Runtime Error | 0 | 0 | 916 | #include <stdio.h>
#include <stdlib.h>
#define SIZE 2000000
int myatoi(const char* p)
{
int n;
while (*p!='\n') {
n = n*10+*p-'0';
p++;
}
return n;
}
int main() {
int A[SIZE];
int H=0;
int i, l, largest, tmp;
char com[21];
do {
fgets(com, 20, stdin);
if (com[0] == 'i') {
A[++H... |
s984669674 | p02289 | u800534567 | 1540308575 | Python | Python3 | py | Runtime Error | 0 | 0 | 930 | #include <stdio.h>
#include <stdlib.h>
#define SIZE 2000000
int myatoi(const char* p)
{
int n;
while (*p!='\n' && *p!='\r') {
n = n*10+*p-'0';
p++;
}
return n;
}
int main() {
int A[SIZE];
int H=0;
int i, l, largest, tmp;
char com[21];
do {
fgets(com, 20, stdin);
if (com[0] == 'i') {... |
s146479281 | p02289 | u357267874 | 1555719685 | Python | Python3 | py | Runtime Error | 20 | 5608 | 1739 | def get_parent(A, i):
if i == 1:
return None
else:
return i // 2
def get_left(A, i):
if len(A) > 2 * i:
return 2 * i
else:
return None
def get_right(A, i):
if len(A) > 2 * i + 1:
return 2 * i + 1
else:
return None
A = [-1] * 10
H = 0
def insert... |
s220645185 | p02289 | u554503378 | 1556535403 | Python | Python3 | py | Runtime Error | 0 | 0 | 1398 | #include <bits/stdc++.h>
using namespace std;
void insert(vector<int> &p_q,int last,int val){
p_q.push_back(val);
last++;
int last_p = (last-1)/2;
while(last >= 0 && p_q[last] > p_q[last_p]){
swap(p_q[last],p_q[last_p]);
last = last_p;
last_p = ((last-1)/2);
}
}
void make... |
s993890004 | p02289 | u491071312 | 1438061581 | Python | Python3 | py | Runtime Error | 0 | 0 | 231 | import asyncio
PQ = asyncio.PriorityQueue()
while True:
line = input().split()
if line[0] == 'insert':
PQ.put_nowait( line[1] )
elif line[0] == 'extract':
print(PQ.get_nowait())
else:
break |
s826825394 | p02289 | u148091382 | 1440837296 | Python | Python | py | Runtime Error | 0 | 0 | 1185 | def insert(array, new_value)
array << new_value
current = array.size-1
parent = current / 2
while (parent > 0) do
if (array[parent] < array[current]) then
array[parent], array[current] = array[current], array[parent]
current = parent
parent = current / 2
else
break
end
end
... |
s438932690 | p02289 | u247976584 | 1455521162 | Python | Python3 | py | Runtime Error | 0 | 0 | 1055 | from sys import stdin, exit
def max_heapify(a, i):
heap_size = a[0]
L = 2*i
R = 2*i + 1
if L <= heap_size and a[L] > a[i]:
largest = L
else:
largest = i
if R <= heap_size and a[R] > a[largest]:
largest = R
if largest != i:
a[i], a[largest] = a[largest], ... |
s977230915 | p02289 | u247976584 | 1455521220 | Python | Python3 | py | Runtime Error | 0 | 0 | 1063 | from sys import stdin, stdout, exit
def max_heapify(a, i):
heap_size = a[0]
L = 2*i
R = 2*i + 1
if L <= heap_size and a[L] > a[i]:
largest = L
else:
largest = i
if R <= heap_size and a[R] > a[largest]:
largest = R
if largest != i:
a[i], a[largest] = a[la... |
s966999980 | p02289 | u567281053 | 1461079555 | Python | Python | py | Runtime Error | 0 | 0 | 1090 | import sys
def parent(i):
return (i + 1) / 2 - 1
def left(i):
return 2 * i + 1
def right(i):
return 2 * i + 2
def sibling(i):
if i % 2 == 0:
return i - 1
else:
return i + 1
def insert(S, k):
S.append(k)
now = len(S) - 1
while True:
p = parent(now)
if ... |
s151338590 | p02289 | u567281053 | 1461249343 | Python | Python | py | Runtime Error | 0 | 0 | 1097 | import sys
def parent(i):
return (i + 1) / 2 - 1
def left(i):
return 2 * i + 1
def right(i):
return 2 * i + 2
def sibling(i):
if i % 2 == 0:
return i - 1
else:
return i + 1
def insert(S, k):
S.append(k)
idx = len(S) - 1
while True:
p = parent(idx)
if ... |
s012245291 | p02289 | u567281053 | 1461250172 | Python | Python | py | Runtime Error | 0 | 0 | 854 | import sys
def insert(S, k):
S.append(k)
idx = len(S) - 1
while True:
p = (i + 1) / 2 - 1
if p < 0 or S[idx] <= S[p]:
break
else:
S[idx], S[p] = S[p], S[idx]
idx = p
def maxHeapify(A, i, size):
l = 2 * i + 1
r = 2 * i + 2
if l < size... |
s751697551 | p02289 | u567281053 | 1461251562 | Python | Python | py | Runtime Error | 0 | 0 | 936 | import sys
def insert(k):
global S, last
S[last] = k
idx = last
while True:
p = (idx + 1) / 2 - 1
if S[idx] <= S[p]:
break
else:
S[idx], S[p] = S[p], S[idx]
idx = p
last += 1
def maxHeapify(i):
global S, last
l = 2 * i + 1
r =... |
s602235413 | p02289 | u949338836 | 1464678548 | Python | Python3 | py | Runtime Error | 0 | 0 | 219 | #coding:utf-8
#1_9_C
s = set()
while True:
cmd = input().split()
if cmd[0] == "end":
break
elif cmd[0] == "insert":
l.add(int(cmd[1]))
else:
print(max(s))
l.remove(max(s)) |
s947226950 | p02289 | u027872723 | 1476634717 | Python | Python3 | py | Runtime Error | 0 | 0 | 1537 | # -*- coding: utf_8 -*-
level = False
def debug(v):
if level:
print(v)
class PriorityQueue:
def __init__(self, size):
self.queue = []
def insert(self, key):
self.queue.append(key)
self.heapIncreaseKey()
debug(self.queue)
def heapIncreaseKey(self):
h = ... |
s518606491 | p02289 | u027872723 | 1476634752 | Python | Python3 | py | Runtime Error | 0 | 0 | 1537 | # -*- coding: utf_8 -*-
level = False
def debug(v):
if level:
print(v)
class PriorityQueue:
def __init__(self, size):
self.queue = []
def insert(self, key):
self.queue.append(key)
self.heapIncreaseKey()
debug(self.queue)
def heapIncreaseKey(self):
h = ... |
s949007172 | p02289 | u027872723 | 1476636869 | Python | Python3 | py | Runtime Error | 0 | 0 | 1715 | # -*- coding: utf_8 -*-
import sys
level = False
def debug(v):
if level:
print(v)
class PriorityQueue:
def __init__(self, size):
self.queue = [-1] * size
self.tail = 0
def insert(self, key):
self.queue[tail] = key
self.tail += 1
self.heapIncreaseKey()
... |
s166638525 | p02289 | u027872723 | 1476637448 | Python | Python3 | py | Runtime Error | 0 | 0 | 1740 | # -*- coding: utf_8 -*-
import sys
level = False
def debug(v):
if level:
print(v)
class PriorityQueue:
def __init__(self, size):
self.queue = [-1] * size
self.tail = 0
def insert(self, key):
self.queue[self.tail] = key
self.tail += 1
self.heapIncreaseKey()
... |
s499363262 | p02289 | u022407960 | 1479465412 | Python | Python3 | py | Runtime Error | 0 | 0 | 2039 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def max_heapify(index):
left, right, largest = 2 * index, 2 * index + 1, None
if left <= heap_length and heap_array[left] > heap_array[index]:
largest = left
else:
largest = index
if right <= heap_length and heap_array[right] ... |
s293292893 | p02289 | u112247126 | 1487832763 | Python | Python3 | py | Runtime Error | 0 | 0 | 1108 | import sys
from numpy import inf
def insert(heap, key):
heap.append(-inf)
heapIncreaseKey(heap, key)
def parent(i):
return (i - 1) // 2
def heapIncreaseKey(heap, key):
heap[len(heap) - 1] = key
i = len(heap) - 1
while i > 0 and heap[parent(i)] < heap[i]:
heap[i], heap[parent(i)] = hea... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.