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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s551471556 | p02319 | u209989098 | 1532170196 | Python | Python3 | py | Runtime Error | 0 | 0 | 231 | a,b = map(int,input())
dp = [0 for i in range(b+1)]
for i in range(a):
x,y = map(int,input())
for j in range(b,y+1,y):
pp = x + dp[j-y]
if pp > dp[j]:
dp[j] = pp
print(max(dp))
|
s124119068 | p02319 | u797673668 | 1486636172 | Python | Python3 | py | Runtime Error | 20 | 7704 | 400 | n, knapsack = map(int, input().split())
dp = [0] * (knapsack + 1)
for i in range(n):
value, weight = map(int, input().split())
for j in range(knapsack - weight, 0, -1):
if not dp[j]:
continue
new_value = dp[j] + value
if dp[j + weight] < new_value:
dp[j + weight] ... |
s785259324 | p02321 | u837811962 | 1497316708 | Python | Python3 | py | Runtime Error | 0 | 0 | 334 | N,W = map(int,input().split())
v = [0]*N;w = [0]*N
for i in range(N):
v[i],w[i] = map(int,input().split())
value = [0 for i in range(W+1)]
for i in range(N):
for j in range(W,W/2,-1):
if j<w[i]:
value[j] = value[j]
else:
value[j] = max(value[j],value[j-w[i]]+v[i])
p... |
s085938583 | p02323 | u894114233 | 1473835899 | Python | Python | py | Runtime Error | 0 | 0 | 763 | v,e=map(int,raw_input().split())
dist=[[float("inf")]*v for _ in xrange(v)]
for i in xrange(e):
????????s,t,d=map(int,raw_input().split())
????????dist[s][t]=d
dp=[[float('inf')]*(v) for _ in xrange(1<<v)]
dp[1][0]=0
for i in xrange(1<<v):
????????for j in xrange(v):
????????????????if dp[i][j]==float('inf'):continue
... |
s661463424 | p02324 | u567380442 | 1428024531 | Python | Python3 | py | Runtime Error | 0 | 0 | 1556 | def warshall_floyd(distance_table, point_size):
for k in range(point_size):
for i in range(point_size):
for j in range(point_size):
if distance_table[i][j] > distance_table[i][k] + distance_table[k][j]:
distance_table[i][j] = distance_table[i][k] + distance_ta... |
s168027305 | p02324 | u567380442 | 1428024837 | Python | Python3 | py | Runtime Error | 0 | 0 | 1562 | def warshall_floyd(distance_table, point_size):
for k in range(point_size):
for i in range(point_size):
for j in range(point_size):
if distance_table[i][j] > distance_table[i][k] + distance_table[k][j]:
distance_table[i][j] = distance_table[i][k] + distance_ta... |
s758341024 | p02324 | u797673668 | 1470185196 | Python | Python3 | py | Runtime Error | 0 | 0 | 774 | from collections import defaultdict
v, e = map(int, input().split())
links = [defaultdict(int) for _ in range(v)]
bests = [None] * (1 << v)
for _ in range(e):
s, t, d = map(int, input().split())
links[s][t] = max(links[s][t], d)
bests[0] = {0: 0}
for visited, best in enumerate(bests):
if best is None:
... |
s591958812 | p02325 | u797673668 | 1492076383 | Python | Python3 | py | Runtime Error | 770 | 57072 | 531 | def calc(p1, p2, v):
dists_v = dists[v]
if v == n - 1:
return dists_v[p1] + dists_v[p2]
if visited[p1][p2]:
return dp[p1][p2]
dp[p1][p2] = min(dists_v[p1] + calc(p2, v, v + 1), dists_v[p2] + calc(p1, v, v + 1))
visited[p1][p2] = True
return dp[p1][p2]
n = int(input())
points = ... |
s454231088 | p02325 | u797673668 | 1492076471 | Python | Python3 | py | Runtime Error | 730 | 57044 | 571 | import sys
sys.setrecursionlimit(1000)
def calc(p1, p2, v):
dists_v = dists[v]
if v == n - 1:
return dists_v[p1] + dists_v[p2]
if visited[p1][p2]:
return dp[p1][p2]
dp[p1][p2] = min(dists_v[p1] + calc(p2, v, v + 1), dists_v[p2] + calc(p1, v, v + 1))
visited[p1][p2] = True
return... |
s547840486 | p02326 | u303753902 | 1458883823 | Python | Python3 | py | Runtime Error | 30 | 7668 | 662 | def solve():
H, W = map(int, input().split())
c = []
for _ in range(H):
c.append(list(map(int, input().split())))
dp = [[0] * W for _ in range(H)]
for x in range(H):
dp[x][0] = 1 if c[x][0] == 0 else 0
for y in range(H):
dp[0][y] = 1 if c[0][y] == 0 else 0
for x in... |
s442858440 | p02326 | u603049633 | 1496971601 | Python | Python3 | py | Runtime Error | 20 | 7728 | 544 | import sys
H,W = map(int, input().split())
C = [list(map(int,i.split())) for i in sys.stdin.readlines()]
G =[[None for i in range(W)] for j in range(H)]
for i in range(W):
if C[0][i] == 0:
G[0][i] = 1
else: G[0][i] = 0
for i in range(H):
if C[i][0] == 0:
G[i][0] = 1
else: G[i][0] = 0
ans = []
for ... |
s025257760 | p02326 | u603049633 | 1496971716 | Python | Python3 | py | Runtime Error | 30 | 7720 | 585 | import sys
H,W = map(int, input().split())
C = [list(map(int,i.split())) for i in sys.stdin.readlines()]
G =[[None for i in range(W)] for j in range(H)]
ans = []
for i in range(W):
if C[0][i] == 0:
G[0][i] = 1
ans.append(1)
else: G[0][i] = 0
for i in range(H):
if C[i][0] == 0:
G[i][0] = 1
... |
s556707021 | p02326 | u426534722 | 1499181297 | Python | Python3 | py | Runtime Error | 0 | 0 | 449 | import sys
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [list(map(int, i.split())) for i in sys.stdin.readlines()]
for x in range(h):
dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
for j in range(1, w):
... |
s087095708 | p02326 | u426534722 | 1499181319 | Python | Python3 | py | Runtime Error | 0 | 0 | 450 | import sys
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [list(map(int, i.split())) for i in sys.stdin.readlines()]
for x in range(h):
dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
for j in range(1, w):
... |
s168332299 | p02326 | u811733736 | 1503060852 | Python | Python3 | py | Runtime Error | 0 | 0 | 1070 | class LargestSquare():
def __init__(self, map):
self.max_width = 0
self.map = []
self.dp = []
for r in map:
self.dp.append([int((x==0)) for x in r])
self.map.append(r[:])
def find(self):
for row in range(1, len(self.dp)):
for col in ra... |
s134564688 | p02326 | u662418022 | 1522756701 | Python | Python3 | py | Runtime Error | 0 | 0 | 547 | # -*- coding: utf-8 -*-
if __name__ == '__main__':
H, W = map(int, input().split())
C = []
dp = []
for i in range(H):
l = input().split()
C.append([int(x) for x in l])
dp.append([(int(x) + 1) % 2 for x in l])
max_width = 1
for i in range(1, H):
for j in range(... |
s165002935 | p02327 | u755162050 | 1469543516 | Python | Python3 | py | Runtime Error | 40 | 7640 | 1096 | def new_max_rectangle(array):
max_area = 0
for i in range(len(array)):
min_height = array[i]
width = 1
for j in range(i, len(array)):
if array[j] == 0:
width = 1
if j <= i:
min_height = array[j + 1]
continue... |
s634967680 | p02328 | u426534722 | 1503196259 | Python | Python3 | py | Runtime Error | 0 | 0 | 662 | import sys
readline = sys.stdin.readline
_input = sys.stdin.readlines()
if len(_input) < 2:
print("In preparation.")
exit()
n = int(_input[0])
li = list(map(int, _input[1]))
def largest_histogram(histogram):
if len(histogram) == 0: return 0
histogram = list(histogram)
max_h = max(n, max(histogram))
... |
s681863589 | p02328 | u260980560 | 1508001491 | Python | Python3 | py | Runtime Error | 20 | 7572 | 313 | N = int(input())
*H, = map(int, input().split())
st = [(0, -1)]
ans = 0
for i in range(N):
h = H[i]
base = i
while h <= st[-1][0]:
h0, j = st.pop()
ans = max(ans, (i-j)*h0)
base = j
st.append((h, base))
while st:
h0, j = st.pop()
ans = max(ans, (N-j)*h0)
print(ans) |
s032089221 | p02329 | u131811591 | 1531717243 | Python | Python3 | py | Runtime Error | 0 | 0 | 556 | import sys
from collections import defaultdict
def read():
n, v = map(int, sys.stdin.readline().split())
a = tuple(map(int, sys.stdin.readline().split()))
b = tuple(map(int, sys.stdin.readline().split()))
c = tuple(map(int, sys.stdin.readline().split()))
d = tuple(map(int, sys.stdin.readline().spl... |
s357775765 | p02329 | u837811962 | 1499162773 | Python | Python3 | py | Runtime Error | 0 | 0 | 374 | from collections import Counter
N,V = map(int,input().split())
cnt = 0
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = tuple(map(int,input().split()))
d = tuple(map(int,input().split()))
ab = Counter(ai+bi for ai in a for bi in b)
cd = Counter(ci+di for ci in c for di in d)
cnt = sum(ab[... |
s597230843 | p02330 | u546285759 | 1491289537 | Python | Python3 | py | Runtime Error | 14220 | 657280 | 354 | from itertools import combinations as C
N, K, L, R= map(int, input().split())
a = list(map(int, input().split()))
v = [i for i in range(N)]
ans = 0
for ii in list(C(v, K)):
tmp = 0
flag = True
for i in ii:
tmp += a[i]
if tmp > R:
flag = False
break
if flag and tmp... |
s717379257 | p02335 | u011621222 | 1540363131 | Python | Python3 | py | Runtime Error | 0 | 0 | 238 |
# -*- coding: utf-8 -*-
# 文字列の入力
import math
n,k = map(int ,input().split())
def comb1(n, r):
if n == 0 or r == 0: return 1
return (comb1(n, r-1) * (n-r+1) / r )%1000000007
ans = (comb(k, n))%1000000007
print(ans)
|
s885877809 | p02343 | u684241248 | 1531913987 | Python | Python3 | py | Runtime Error | 0 | 0 | 1694 | # -*- coding: utf-8 -*-
class DisjointSets:
'''
Implementing disjoint sets using disjoint sets forests structure.
--- methods ---
__init__(size): size should be the number of elements in this disjoint sets
unite(x, y): unite sets that contain x and y into a new set
same(x, y): check if x and y ... |
s207032997 | p02343 | u684241248 | 1531914119 | Python | Python3 | py | Runtime Error | 20 | 5624 | 1679 | # -*- coding: utf-8 -*-
class DisjointSets:
'''
Implementing disjoint sets using disjoint sets forests structure.
--- methods ---
__init__(size): size should be the number of elements in this disjoint sets
unite(x, y): unite sets that contain x and y into a new set
same(x, y): check if x and y ... |
s064368844 | p02343 | u684241248 | 1531914150 | Python | Python3 | py | Runtime Error | 20 | 5628 | 1679 | # -*- coding: utf-8 -*-
class DisjointSets:
'''
Implementing disjoint sets using disjoint sets forests structure.
--- methods ---
__init__(size): size should be the number of elements in this disjoint sets
unite(x, y): unite sets that contain x and y into a new set
same(x, y): check if x and y ... |
s768493111 | p02343 | u099826363 | 1556163725 | Python | Python3 | py | Runtime Error | 200 | 7500 | 1267 | from sys import exit
class UnionFind():
#負の値は根で集合の個数
#正の値は次の要素を返す
def __init__(self,size):
self.table = [-1 for _ in range(size)]
#集合の代表を求める
def find(self,x):
if self.table[x] < 0:return x
root = self.find(self.table[x])
self.table[x] = root
return root
... |
s555776315 | p02343 | u567380442 | 1427587809 | Python | Python3 | py | Runtime Error | 160 | 6980 | 492 | import sys
f = sys.stdin
def unite(x, y):
global dat
x, y = find(dat, x), find(dat, y)
if x != y:
dat[x] = y
def same(x, y):
global dat
x, y = find(dat, x), find(dat, y)
print(1 if x == y else 0)
def find(dat, x):
if dat[x] < 0:
return x
dat[x] = find(dat, dat[x])
r... |
s721872058 | p02343 | u633068244 | 1432618752 | Python | Python | py | Runtime Error | 0 | 0 | 868 | class UnionFind:
def __init__(self, size):
self.rank = [0] * size
self.par = range(size)
self.g_num = size
def find(self, x):
if x == self.par[x]: return x
self.par[x] = self.find(self.par[x])
return self.par[x]
def same(self, x, y):
return self.find(x)... |
s815452243 | p02343 | u571345655 | 1434456086 | Python | Python | py | Runtime Error | 10 | 4244 | 637 | # coding=utf-8
elemNum, queryNum = map(int, raw_input().rstrip().split())
sets = [set([i]) for i in range(elemNum)]
def unite(x, y):
for i, s in enumerate(sets):
if x in s:
ix = i
sx = sets[i]
elif y in s:
iy = i
sy = sets[i]
sets.pop(ix)
se... |
s260772104 | p02343 | u873482706 | 1446031969 | Python | Python | py | Runtime Error | 10 | 6280 | 709 | n, q = map(int, raw_input().split())
lis = []
for i in range(n):
lis.append(set(str(i)))
for i in range(q):
c, x, y = raw_input().split()
if c == '0':
index1 = index2 = None
for i, s in enumerate(lis):
if x in s:
index1 = i
elif y in s:
... |
s982033026 | p02343 | u873482706 | 1446033711 | Python | Python | py | Runtime Error | 0 | 0 | 805 | n, q = map(int, raw_input().split())
lis = []
for i in range(n):
lis.append(set([str(i)]))
for i in range(q):
c, x, y = line.rstrip().split()
if c == '0':
index1 = index2 = None
for i, s in enumerate(lis):
if x in s:
index1 = i
elif y in s:
... |
s786280275 | p02343 | u797673668 | 1455595461 | Python | Python3 | py | Runtime Error | 20 | 7648 | 351 | def find(x):
global set_list
return x if set_list[x] == x else find(set_list[x])
n, q = map(int, input().split())
set_list = list(range(n))
while q:
op, x, y = map(int, input().split())
if op:
print(1 if find(x) == find(y) else 0)
else:
if x > y:
x, y = y, x
se... |
s278355214 | p02343 | u797673668 | 1455595561 | Python | Python3 | py | Runtime Error | 13160 | 8860 | 357 | def find(x):
global set_list
return x if set_list[x] == x else find(set_list[x])
n, q = map(int, input().split())
set_list = list(range(n))
while q:
op, x, y = map(int, input().split())
if op:
print(1 if find(x) == find(y) else 0)
else:
if x > y:
x, y = y, x
se... |
s208222938 | p02343 | u894114233 | 1460772207 | Python | Python | py | Runtime Error | 0 | 0 | 929 | def findset(x):
global nodes
if nodes[x].parent==x:
return x
else:
nodes[x].parent=findset(nodes[x].parent)
return nodes[x].parent
def unite(x,y):
global rank,nodes
if rank[nodes[x].parent]<rank[nodes[y].parent]:
nodes[nodes[x].parent].parent=nodes[nodes[y].parent].p... |
s610237324 | p02343 | u894114233 | 1460772750 | Python | Python | py | Runtime Error | 10 | 6320 | 1008 | class node:
def __init__(self,parent):
self.parent=parent
def findset(x):
global nodes
if nodes[x].parent==x:
return x
else:
nodes[x].parent=findset(nodes[x].parent)
def unite(x,y):
global rank,nodes
findset(x)
findset(y)
if rank[nodes[x].parent]<rank[nodes[y].p... |
s462127819 | p02343 | u107876975 | 1462250861 | Python | Python3 | py | Runtime Error | 0 | 0 | 952 | class UnionFind:
def __init__(self, *xs):
self.p = {}
self.rank = {}
self.make_set(xs)
def make_set(self, *xs):
for x in xs:
self.p[x] = x
self.rank[x] = 0
def union(self, x, y):
self.link(self.find_set(x), self.find_set(y))
def find_se... |
s635280123 | p02343 | u203261375 | 1467466030 | Python | Python3 | py | Runtime Error | 30 | 7696 | 574 | n,q = map(int, input().split())
s = [[i] for i in range(n)]
for i in range(q):
com,x,y = map(int, input().split())
if com == 0:
indexx,indexy = -1,-1
for j in range(len(s)):
if x in s[j]:
indexx = j
if y in s[j]:
indexy = j
s[indexx... |
s326397638 | p02343 | u072053884 | 1467529039 | Python | Python3 | py | Runtime Error | 20 | 7656 | 615 | import sys
f_i = sys.stdin
n, q = map(int, f_i.readline().split())
S = [[i] for i in range(n)]
for l in f_i:
com, x, y = map(int, l.split())
for e in S:
if x in e and y in e:
if com == 1:
print(1)
break
elif x in e:
if com == 0:
... |
s300749328 | p02343 | u072053884 | 1467532527 | Python | Python3 | py | Runtime Error | 0 | 0 | 758 | import sys
f_i = sys.stdin
n, q = map(int, f_i.readline().split())
S = set([frozenset([i]) for i in range(n)])
def unite(sets, v1, v2):
s1 = None
s2 = None
for s in sets:
if v1 in s and v2 in s:
return None
elif v1 in s:
s1 = s
elif v2 in s:
s2... |
s574590663 | p02343 | u436587708 | 1469617416 | Python | Python | py | Runtime Error | 10 | 6268 | 524 | def find_group(x):
return [x in g for g in groups].index(True)
n, q = map(int, raw_input().split())
groups = [set([i]) for i in range(n)]
for i in range(q):
com, x, y = map(int, raw_input().split())
if com == 0:
ind1 = find_group(x)
g1 = groups.pop(ind1)
ind2 = find_group(... |
s023518286 | p02343 | u979507074 | 1477582842 | Python | Python | py | Runtime Error | 0 | 0 | 626 | n, q = map(int, input().split(" "))
items = [i for i in range(n)]
parent = [i for i in range(n)]
def root(s):
if parent[s] == s:
return s
else:
parent[s] = root(parent[s])
return parent[s]
def same(s1, s2):
if parent[s1] == parent[s2]:
print("1")
else:
print("0"... |
s605452100 | p02343 | u979507074 | 1477582911 | Python | Python | py | Runtime Error | 0 | 0 | 626 | n, q = map(int, input().split(" "))
items = [i for i in range(n)]
parent = [i for i in range(n)]
def root(s):
if parent[s] == s:
return s
else:
parent[s] = root(parent[s])
return parent[s]
def same(s1, s2):
if parent[s1] == parent[s2]:
print("1")
else:
print("0"... |
s501059862 | p02343 | u979507074 | 1477583346 | Python | Python3 | py | Runtime Error | 0 | 0 | 839 | n, q = map(int, input().split(" "))
items = [i for i in range(n)]
parent = [i for i in range(n)]
def root(s):
if parent[s] == s:
return s
else:
parent[s] = root(parent[s])
return parent[s]
def same(s1, s2):
if root[s1] == root[s2]:
print("1")
else:
print("0")
d... |
s883553188 | p02343 | u979507074 | 1477583390 | Python | Python3 | py | Runtime Error | 160 | 8456 | 622 | n, q = map(int, input().split(" "))
items = [i for i in range(n)]
parent = [i for i in range(n)]
def root(s):
if parent[s] == s:
return s
else:
parent[s] = root(parent[s])
return parent[s]
def same(s1, s2):
if root(s1) == root(s2):
print("1")
else:
print("0")
d... |
s941148901 | p02343 | u494314211 | 1481028323 | Python | Python3 | py | Runtime Error | 0 | 0 | 1157 | # ?????????O(n)????????£???????????????
class union_find(object):
"""union-find tree"""
def __init__(self, length):
self.length = length
self.unionnumber=0
self.unionlist=[[]]
self.num=list(-1 for i in range(length))
def unite(self,i,j):
if self.num[i]==-1:
if self.num[j]==-1:
self.unionl... |
s831500151 | p02343 | u798803522 | 1488257902 | Python | Python3 | py | Runtime Error | 20 | 7672 | 827 | def root(x,rt):
if rt[x] == x:
return x
else:
while rt[x] != x:
rt[x] = root(rt[x],rt)
return rt[x]
def union(x,y,rt,rank):
rootx = rt[x]
rooty = rt[y]
if rootx == rooty:
return 0
else:
if rank[rootx] < rank[rooty]:
rt[rooty] = ... |
s460626177 | p02343 | u798803522 | 1488258456 | Python | Python3 | py | Runtime Error | 190 | 7992 | 837 | def root(x,rt):
if rt[x] == x:
return x
else:
while rt[x] != x:
rt[x] = root(rt[x],rt)
return rt[x]
def union(x,y,rt,rank):
rootx = root(x,rt)
rooty = root(y,rt)
if rootx == rooty:
return 0
else:
if rank[rootx] < rank[rooty]:
rt... |
s361901204 | p02343 | u923668099 | 1488616720 | Python | Python3 | py | Runtime Error | 130 | 9324 | 1046 | import sys
def solve():
n, q = map(int, sys.stdin.readline().split())
uf = UnionFind(n)
ans = []
for lp in range(q):
c, x, y = map(int, sys.stdin.readline().split())
if c == 0:
uf.unite(x, y)
else:
ans.append(1 if uf.is_same(x, y) else 0)
print(*an... |
s850653966 | p02343 | u370086573 | 1497716660 | Python | Python3 | py | Runtime Error | 210 | 8088 | 1035 | class DisjoinSet:
def __init__(self, size):
self.rank = [0 for _ in range(size)]
self.p = [0 for _ in range(size)]
for i in range(n):
self.makeSet(i)
def makeSet(self, x):
self.p[x] = x
self.rank[x] = x
def same(self, x, y):
print(int(self.findSe... |
s602855407 | p02343 | u408216289 | 1499267323 | Python | Python | py | Runtime Error | 80 | 7260 | 640 | PARENT = {}
def MAKE_SET(v):
PARENT.update({v : v})
def FIND_SET(u):
if PARENT[u] == u:
return u
else:
return FIND_SET(PARENT[u])
def UNION(u, v):
u_root = FIND_SET(u)
v_root = FIND_SET(v)
PARENT[u_root] = v_root
def SAME(u, v):
return FIND_SET(u) == FIND_SET(v)
n, q = ... |
s187045659 | p02343 | u855199458 | 1503136077 | Python | Python3 | py | Runtime Error | 30 | 7688 | 661 | # -*- coding: utf-8 -*-
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)] # [next, rank]
def find(i):
if tree[i][0] == -1:
group = i
else:
group = find(tree[i][0])
return group
def unite(x, y):
px = find(x)
py = find(y)
if tree[px][1] == tr... |
s381906799 | p02343 | u451187291 | 1503854389 | Python | Python3 | py | Runtime Error | 0 | 0 | 637 | # encoding: "utf-8"
class Unreachable(Exception):
pass
def main():
[n, q] = [int(x) for x in input().split()]
setlist = list()
for i in range(n):
setlist.append(set(i))
for _ in range(q):
run(setlist)
def run(setlist):
com, x, y = [int(x) for x in input().split()]
if com... |
s723660516 | p02343 | u451187291 | 1503857000 | Python | Python3 | py | Runtime Error | 20 | 7724 | 1416 | # encoding: "utf-8"
class Unreachable(Exception):
pass
class SetManager:
def __init__(self, n):
self.data = list()
for i in range(n):
self.data.append((i, {i}))
def ref(self, i):
return self.data[i][1]
def set(self, i, value):
self.data[i] = (i, value)
... |
s193760834 | p02343 | u451187291 | 1503857058 | Python | Python3 | py | Runtime Error | 20 | 7748 | 1416 | # encoding: "utf-8"
class Unreachable(Exception):
pass
class SetManager:
def __init__(self, n):
self.data = list()
for i in range(n):
self.data.append((i, {i}))
def ref(self, i):
return self.data[i][1]
def set(self, i, value):
self.data[i] = (i, value)
... |
s290628805 | p02343 | u451187291 | 1503857461 | Python | Python3 | py | Runtime Error | 30 | 7732 | 1416 | # encoding: "utf-8"
class Unreachable(Exception):
pass
class SetManager:
def __init__(self, n):
self.data = list()
for i in range(n):
self.data.append((i, {i}))
def ref(self, i):
return self.data[i][1]
def set(self, i, value):
self.data[i] = (i, value)
... |
s961508069 | p02343 | u272785173 | 1505237310 | Python | Python3 | py | Runtime Error | 230 | 8272 | 1092 | class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n)]
self.rank = [1 for i in range(n)]
def root(self, v):
if self.parent[v] == v:
self.parent[v] = v
else:
self.parent[v] = self.root(self.parent[v])
return self.... |
s960537405 | p02343 | u045830275 | 1512089002 | Python | Python3 | py | Runtime Error | 20 | 5612 | 1260 | def is_in_sameset(S, x, y) :
if x <= S and y <= S :
return True
else :
return False
def main() :
n, q = [int(i) for i in input().split()]
set_list = [{i} for i in range(n)]
com = []
x = []
y = []
for _ in range(q) :
tmp = input().split()
com.append(int... |
s957664295 | p02343 | u658913995 | 1512382409 | Python | Python3 | py | Runtime Error | 220 | 5988 | 889 | # It took me about 40 minutes to finsih this assignment.
# The task itself is relatively simple, since we have sample code on handouts.
# One problem I met was that in case 22, I had a "RecursionError" (maximum recursion depth exceeded in comparison).
# The solution was simple: import sys, and add a line "sys.setrecurs... |
s187723663 | p02343 | u912143677 | 1522416961 | Python | Python3 | py | Runtime Error | 190 | 6048 | 921 | class UnionFind:
def __init__(self, n):
self.rank = [0]*n
self.parent = [i for i in range(n)]
def find(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def merge(sel... |
s620937581 | p02343 | u525685480 | 1523882593 | Python | Python3 | py | Runtime Error | 20 | 5604 | 758 | # -*- coding:utf-8 -*-
def unite(list_s, x, y):
for idx, elem in enumerate(list_s):
if x in list_s[idx]:
x_list = list_s[idx]
if y in list_s[idx]:
for num in list_s[idx]:
x_list.append(num)
del list_s[idx]
return list_s
def same(list_s, x, y... |
s784980121 | p02343 | u825008385 | 1524363513 | Python | Python3 | py | Runtime Error | 0 | 0 | 1656 | # Disjoint Set: Union Find Trees
[p, rank] = [[], []]
[n, q] = list(map(int, input().split()))
w = [0 for i in range(n)]
path_c = [[] for i in range(n)]
def makeSet(x):
global p, rank
p.append(x)
rank.append(0)
def findSet(x):
global p
if x != p[x]:
p[x] = findSet(p[x])
return p[x]
de... |
s974559931 | p02343 | u893844544 | 1524453894 | Python | Python3 | py | Runtime Error | 20 | 5596 | 521 | n, nq = map(int, input().split())
ss = [set([i]) for i in range(n)]
for _ in range(nq):
q,x,y = map(int, input().split())
if q == 0:
sx = {}
sy = {}
for s in ss:
if x in s:
sx = s
if y in s:
sy = s
ss.remove(sx)
ss... |
s054107047 | p02343 | u589025755 | 1527140031 | Python | Python3 | py | Runtime Error | 210 | 5988 | 995 | class UnionFind:
def __init__(self, max_size):
self.max_size = max_size
self.dat = [i for i in range(self.max_size)]
def find(self, vertex):
if self.dat[vertex] is vertex: return vertex
self.dat[vertex] = self.find(self.dat[vertex])
return self.dat[vertex]
def merge... |
s017792600 | p02343 | u624914682 | 1527502813 | Python | Python3 | py | Runtime Error | 0 | 0 | 679 | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int root(int i,vector<int> &set){
if(set[i]==-1){
return i;
}else{
int result=root(set[i],set);
set[i]=result;
return result;
}
}
int main(){
int n,q;
cin >> n >> q;
vector<int> set(n,-1... |
s670350247 | p02343 | u368083894 | 1527935361 | Python | Python3 | py | Runtime Error | 240 | 6312 | 1083 |
class UnionFindTree:
def __init__(self):
self.cnt = []
self.par = []
def add(self, n):
assert n == len(self.par), "Invalid Value"
self.par.append(n)
self.cnt.append(1)
def find(self, x):
if self.par[x] == x:
return x
else:
s... |
s271391911 | p02343 | u733620181 | 1528112931 | Python | Python3 | py | Runtime Error | 11830 | 6896 | 394 | def get():
return input()
def lastIndex(ref, i):
if ref[i] == i:
return i
else:
return lastIndex(ref, ref[i])
n, q = map(int, get().split())
ref = list(range(n))
for _ in range(q):
com, a, b = map(int, get().split())
if com == 0:
# unit
ref[lastIndex(ref, b)] = lastIndex(ref, a)
else:
# same
if la... |
s825255168 | p02343 | u733620181 | 1528113666 | Python | Python3 | py | Runtime Error | 11930 | 6900 | 478 | def get():
return input()
def lastIndex(ref, i):
if ref[i] == i:
return i
else:
return lastIndex(ref, ref[i])
n, q = map(int, get().split())
ref = list(range(n))
for _ in range(q):
com, a, b = map(int, get().split())
if com == 0:
# unit
ref[lastIndex(ref, b)... |
s278336119 | p02343 | u733620181 | 1528120206 | Python | Python3 | py | Runtime Error | 11860 | 6896 | 478 | def get():
return input()
def lastIndex(ref, i):
if ref[i] == i:
return i
else:
return lastIndex(ref, ref[i])
n, q = map(int, get().split())
ref = list(range(n))
for _ in range(q):
com, a, b = map(int, get().split())
if com == 0:
# unit
ref[lastIndex(ref, b)... |
s263604994 | p02343 | u089116225 | 1528907018 | Python | Python3 | py | Runtime Error | 0 | 0 | 571 | n,q = map(int, input().split())
root_list = [i for i in range(n)]
def root(x):
path_to_root = []
while root_list[x] != x:
path_to_root.append(x):
x = root_list[x]
for node in path_to_root:
root_list[node] = x
return x
def is_same_set(x,y):
return root(x) == root(y)
def un... |
s094141349 | p02343 | u782850731 | 1380895802 | Python | Python | py | Runtime Error | 20 | 4260 | 693 | #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
def main():
n, q = (int(s) for s in stdin.readline().split())
s = [{i} for i in range(n)]
for _ in range(q):
com, x, y = (int(s) for s in stdin.readline().split())
if com:
for si in s:
... |
s366719856 | p02343 | u633068244 | 1396115446 | Python | Python | py | Runtime Error | 10 | 4236 | 329 | n,q = map(int, raw_input().split())
S = [set([i]) for i in range(n)]
ref = [0]*n
for i in range(q):
com,x,y = map(int, raw_input().split())
if x > y: x,y = y,x
if com == 0: # unite
x += ref[x]; y += ref[y]
S[x] = S[x]|S[y]
S.pop(y)
for j in range(y,n):
ref[j] -= 1
else: # same
print 1 if y in S[x+ref[x... |
s732972364 | p02344 | u241923784 | 1555850653 | Python | Python3 | py | Runtime Error | 20 | 5696 | 917 | MAX = 10003
N, Q = (int(x) for x in input().split())
ws = [0 for i in range(MAX)]
par = [-1 for i in range(N)]
def weight(x):
root(x)
return ws[x]
def root(x):
if par[x] < 0: return x
p = root(par[x])
ws[x] = ws[x] + ws[par[x]]
par[x] = p
return par[x]
return y
def unite(y, x, z)... |
s053347677 | p02344 | u167493070 | 1523952227 | Python | Python3 | py | Runtime Error | 260 | 10884 | 1179 | import sys
def simplefindset(x,element,resultPos=0):
if(x != element[x]):
resultPos = simplefindset(element[x],element,resultPos)
else:
resultPos = x
return resultPos
def findset(x,element,weight,resultPos=0,sumW=0):
if(x != element[x]):
resultPos,sumW = findset(element[x],elem... |
s991516420 | p02344 | u167493070 | 1523962037 | Python | Python3 | py | Runtime Error | 900 | 10780 | 909 | import sys
sys.setrecursionlimit(10000)
def findset(x,element,weight):
if(x != element[x]):
element[x],s = findset(element[x],element,weight)
weight[x] += s
return element[x],weight[x]
def union(x,y,element,weight,w):
x,wx = findset(x,element,weight)
y,wy = findset(y,element,weight)
... |
s915408549 | p02345 | u938878704 | 1531659243 | Python | Python3 | py | Runtime Error | 20 | 5604 | 935 | n, q = map(int, input().split())
answer = []
# create segtree
size = 2
while size < n :
size *= 2
size = size * 2 - 1
segtree = [2**31 - 1 for x in range(size)]
# update query
def update(i, x) :
ind = size // 2 + i
segtree[ind] = x
while ind :
ind = (ind - 1) // 2 # parent
c... |
s751199885 | p02345 | u776402923 | 1534791029 | Python | Python3 | py | Runtime Error | 20 | 5600 | 1138 | #単体変更, 区間取得
class RMQ:
#INF = int(1e18)
INF = int((1<<31)-1)
n = 0
n_ = 0
val = []
def __init__(self, n_):
n = 1
while n < n_:
n = n * 2
self.n = n
self.n_ = n_
self.val = [self.INF] * (2 * n - 1)
@staticmethod
def merge(a, b):
... |
s164516146 | p02345 | u240830039 | 1546392504 | Python | Python3 | py | Runtime Error | 0 | 0 | 2531 | import sys
#stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip... |
s916957434 | p02345 | u464454066 | 1555918280 | Python | Python3 | py | Runtime Error | 20 | 5692 | 1349 | import sys
import time
import math
sys.setrecursionlimit(20000)
def update(tree,x,y,N):
# happa no offset
x += N
tree[x] = y
# segment tree no update suru
while x>0:
x = int((x - 1)/2)
left = x*2+1
right = x*2+2
if(right > N):
right = right - 1
tre... |
s942369292 | p02345 | u464454066 | 1555934460 | Python | Python3 | py | Runtime Error | 0 | 0 | 1368 | import sys
import time
import math
sys.setrecursionlimit(20000)
def update(tree,x,y,N):
# offset
#x += int(N/2)
x += N - 1
tree[x] = y
# segment tree no update suru
while x>0:
x = math.floor((x - 1)/2)
left = x*2+1
right = x*2+2
tree[x] = min(tree[left],tree[right... |
s254097659 | p02345 | u241923784 | 1556442638 | Python | Python3 | py | Runtime Error | 0 | 0 | 970 | import math
INT_MAX = 2147483647
MAX = 100003
n,q=(int(x) for x in input().split())
b= math.sqrt(n)
def judge_max(x,y):
if x > y :return x
else:return y
def judge_min(x,y):
if x > y :return y
else :return x
def update(x):
for i in range(int(x*b),int(judge_min(n-1,(x+1)*b))):a[i]=l[int... |
s558450725 | p02345 | u241923784 | 1556443488 | Python | Python3 | py | Runtime Error | 30 | 6472 | 691 | M = 2147483647
a = [M for i in range(100000)]
def j_min(x,y):
if x < y:return x
else: return y
def find(x,y,i,l,r):
if r<=x or y<=l:return M
if x<=l and r<=y: return a[i]
return min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))
if __name__=='__main__':
n, m = (int(x) for x in input().spl... |
s513857185 | p02345 | u241923784 | 1556443526 | Python | Python3 | py | Runtime Error | 2760 | 8824 | 693 | M = 2147483647
a = [M for i in range(100000*2)]
def j_min(x,y):
if x < y:return x
else: return y
def find(x,y,i,l,r):
if r<=x or y<=l:return M
if x<=l and r<=y: return a[i]
return min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))
if __name__=='__main__':
n, m = (int(x) for x in input().s... |
s776470666 | p02345 | u241923784 | 1556443656 | Python | Python3 | py | Runtime Error | 2680 | 8820 | 695 | M = 2147483647
a = [M for i in range(100000*2)]
def j_min(x,y):
if x < y:return x
else: return y
def find(x,y,i,l,r):
if r<=x or y<=l:return M
if x<=l and r<=y: return a[i]
return j_min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))
if __name__=='__main__':
n, m = (int(x) for x in input()... |
s883554599 | p02345 | u567380442 | 1427595412 | Python | Python3 | py | Runtime Error | 0 | 0 | 1318 | import math
class segment_tree:
# self.table is 1-indexed
def __init__(self, dat, query, default=0):
self.offset = 2 ** math.ceil(math.log2(len(dat)))
self.table = [default] * self.offset + dat + [default] * (self.offset - len(dat))
self.query = query
for i in reversed(range... |
s940845273 | p02345 | u879226672 | 1429963199 | Python | Python | py | Runtime Error | 1180 | 8980 | 542 | n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1]*317
for i in range(q):
comi,xi,yi = map(int,raw_input().split())
if comi and yi<316:
print min(A[xi:yi+1])
elif comi and yi >= 316 and xi/316+1 != yi/316:
print min(min(A[xi:(xi/316 + 1)*316]),min(B[xi/316+1:yi/... |
s938695728 | p02345 | u879226672 | 1429963512 | Python | Python | py | Runtime Error | 1170 | 8988 | 560 | n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1 for i in range(318)]
for i in range(q):
comi,xi,yi = map(int,raw_input().split())
if comi and yi<316:
print min(A[xi:yi+1])
elif comi and yi >= 316 and xi/316+1 != yi/316:
print min(min(A[xi:(xi/316 + 1)*316]),mi... |
s290602934 | p02345 | u879226672 | 1430061537 | Python | Python | py | Runtime Error | 10 | 4240 | 455 | # -*- coding: utf-8 -*-
# Range Minimum Query
n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1]*101
for i in range(q):
comi,xi,yi = map(int,raw_input().split())
if comi and abs(yi-xi)<=199:
print min(A[xi:yi+1])
elif comi and 200<= abs(yi-xi):
print min(min(A[... |
s872344157 | p02345 | u633068244 | 1432619414 | Python | Python | py | Runtime Error | 0 | 0 | 927 | class RangeMinQuery:
inf = 2 ** 31 - 1
def __init__(self, N):
self.n = 1
while self.n < N: self.n *= 2
self.dat = [self.inf] (2 * self.n - 1)
def update(self, k, x):
k += self.n - 1
self.dat[k] = x
while (k > 0):
k = (k - 1) / 2
self.d... |
s067231637 | p02345 | u491071312 | 1437905745 | Python | Python | py | Runtime Error | 0 | 0 | 1054 | import time
N, Q = map(int, input().split())
SegTree = [0 for i in range(4*N)]
def modify(i, left, right, value, pos=-1):
global SegTree
if left==right:
if pos != -1:
SegTree[i] = value
else:
SegTree[i] = 2147483647
return
mid = int((left+right)/2)
if p... |
s083314191 | p02345 | u669284080 | 1455779570 | Python | Python3 | py | Runtime Error | 0 | 0 | 1091 | #!/usr/bin/python3
import math
# main
n, q = map(int, input().split())
b_size = math.ceil(math.sqrt(n))
b_len = math.ceil(n/b_size)
a = [2 ** 31 - 1 for i in range(n)]
b = [min(a[b_size * i:b_size * (i + 1)]) for i in range(b_len)]
for i in range(q):
com, x, y = map(int, input().split())
if com == 0:
#... |
s245406491 | p02345 | u669284080 | 1455779601 | Python | Python3 | py | Runtime Error | 0 | 0 | 1091 | #!/usr/bin/python3
import math
# main
n, q = map(int, input().split())
b_size = math.ceil(math.sqrt(n))
b_len = math.ceil(n/b_size)
a = [2 ** 31 - 1 for i in range(n)]
b = [min(a[b_size * i:b_size * (i + 1)]) for i in range(b_len)]
for i in range(q):
com, x, y = map(int, input().split())
if com == 0:
#... |
s405007249 | p02345 | u669284080 | 1455780104 | Python | Python3 | py | Runtime Error | 30 | 7872 | 1110 | #!/usr/bin/python3
import math
# main
n, q = map(int, input().split())
b_size = math.ceil(math.sqrt(n))
b_len = math.ceil(n/b_size)
a = [2 ** 31 - 1 for i in range(n)]
b = [min(a[b_size * i:b_size * (i + 1)]) for i in range(b_len)]
for i in range(q):
com, x, y = map(int, input().split())
if com == 0:
#... |
s665973232 | p02345 | u342628608 | 1472287189 | Python | Python | py | Runtime Error | 600 | 11292 | 335 | l = raw_input().split()
#l=input[0].split()
n = int(l[0])
a = [2147483647]*50000
change = 1
for i in range(0,int(l[1])):
l = raw_input().split()
# l=input[i+1].split()
if int(l[0])==0:
a[int(l[1])]=int(l[2])
change = 1
elif change==l[1]+l[2]:
print m
else:
change = l[1]+l[2]
m = min(a[int(l[1]):int(l[2]... |
s098311645 | p02345 | u342628608 | 1472289177 | Python | Python | py | Runtime Error | 0 | 0 | 816 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
def main(init=int(2**31-1), readline=stdin.readline):
n, q = (int(s) for s in readline().split())
a = [init] * n
b = [init] * ((n /... |
s506281983 | p02345 | u798803522 | 1474277658 | Python | Python3 | py | Runtime Error | 0 | 0 | 1474 | import math
num,query = (int(n) for n in input().split(' '))
table = [2**31 - 1 for n in range(num)]
sqrttable = []
sqrtnum = math.floor(math.sqrt(num))
tempmin = float("inf")
for t in range(num):
if t % sqrtnum == sqrtnum - 1:
tempmin = min(table[t],tempmin)
sqrttable.append(tempmin)
elif t == ... |
s780791712 | p02345 | u798803522 | 1474385157 | Python | Python3 | py | Runtime Error | 0 | 0 | 989 | import math
def update(index,n):
targ[index] = n
index = (index - 1) // 2
while True:
targ[index] = min(targ[index * 2],targ[index * 2 + 1])
if index <= 0:
break
index = (index - 1) // 2
def find(i,e,node,inode,enode):
#print(i,e,node,inode,enode)
if inode > e o... |
s788320393 | p02345 | u647529925 | 1484046922 | Python | Python | py | Runtime Error | 0 | 0 | 601 | def update(i, x):
i += base
while i>0:
st[i] = min(st[i], x)
i//=2
def find(a, b):
return _find(a, b+1, 0, 0, n)
def _find(a, b, k, l, r):
if b <= l or r <= a:
return 2**31-1
if a <= l and r <= b:
return st[k]
rl = _find(a, b, 2*k+1, l, (l+r)/2)
rr = _fi... |
s960716415 | p02345 | u728992264 | 1490387165 | Python | Python3 | py | Runtime Error | 0 | 0 | 724 | import pdb;
dat = []
def init(n):
global dat
k = 1
while (k < n):
k = k * 2
dat = [2**31 - 1 for i in range(2 * k - 1)]
def update(k, y):
global dat
k += n
dat[k] = y;
while (k > 0):
k = int((k - 1) / 2)
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2])
def query(a, b, k, l, r):
if (r ... |
s708778523 | p02345 | u728992264 | 1490387180 | Python | Python3 | py | Runtime Error | 0 | 0 | 711 |
dat = []
def init(n):
global dat
k = 1
while (k < n):
k = k * 2
dat = [2**31 - 1 for i in range(2 * k - 1)]
def update(k, y):
global dat
k += n
dat[k] = y;
while (k > 0):
k = int((k - 1) / 2)
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2])
def query(a, b, k, l, r):
if (r <= a or b <= ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.