input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import math
INF = float("inf")
V, E = list(map(int, input().split()))
es = []
for _ in range(E):
a, b, c = list(map(int, input().split()))
es.append([a-1, b-1, -c])
d = [INF] * V
d[0] = 0
for _ in range(V - 1):
updated = False
for e in es:
if math.isinf(d[e[0]]):
... | import math
INF = float("inf")
V, E = list(map(int, input().split()))
es = []
for _ in range(E):
a, b, c = list(map(int, input().split()))
es.append([a-1, b-1, -c])
d = [INF] * V
d[0] = 0
cnt = [0] * V
for _ in range(V):
updated = False
for e in es:
if math.isinf(d[e[0]]):... | p03722 |
#Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
#頂点1から頂点Nに移動して、移動スコアを最大にする
#->移動スコアを正負反転させれば最短経路問題
#->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N,M = list(map(int,input().split()))
#辺を登録
Sides = []
for i in range (M):
Side = list(map(int,input().split()))
Sides.append(Side)
#コストを反転
Sides[... | #Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
#頂点1から頂点Nに移動して、移動スコアを最大にする
#->移動スコアを正負反転させれば最短経路問題
#->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N,M = list(map(int,input().split()))
#辺を登録
Sides = []
for i in range (M):
Side = list(map(int,input().split()))
Sides.append(Side)
#コストを反転
Sides[... | p03722 |
import sys
N,M=list(map(int, input().split()))
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=list(map(int, input().split() ))
a+=[A]
b+=[B]
c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
... | import sys
N,M=list(map(int, input().split()))
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=list(map(int, input().split() ))
a+=[A]
b+=[B]
c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
... | p03722 |
class BellmanFord:#Union-Find
def __init__(self, n, init_val = float('inf')):
self.d = [init_val] * n #根にサイズを負の値で格納する。
self.init_val = init_val
def shortest_path(self, s, edges):
self.d[s] = 0
for _ in range(n):
updated = False
for a, b, w in edg... | def bellman_ford(n, s, edges, init_val):
d = [init_val] * n
d[0] = 0
for _ in range(n):
updated = False
for vf, vt, w in edges:
if d[vf] != init_val and d[vt] > d[vf] + w:
d[vt] = d[vf] + w
updated = True
if not updated:
... | p03722 |
from collections import deque
def moores_d(n, s, graph, init_val):
d = [init_val] * n
d[s] = 0
q = deque([s])
for _ in range(n):
m = len(q)
for _ in range(m):
vf = q.popleft()
for vt, w in graph[vf]:
if d[vt] > d[vf] + w:
... | def bellman_ford(n, s, edges, init_val = float('inf')):
d = [init_val] * n
d[s] = 0
for _ in range(n):
updated = False
for vf, vt, w in edges:
if d[vf] != init_val and d[vt] > d[vf] + w:
d[vt] = d[vf] + w
updated = True
if not upd... | p03722 |
class PreallocatedQueue:
def __init__(self, n, init_val):
self.queue = [init_val] * n #根にサイズを負の値で格納する。
self.l = 0
self.r = 0
self.n = n
self.init_val = init_val
self.count = 0
def append(self, val):
if self.count == self.n:
if self.... | class PreallocatedQueue:
def __init__(self, n, init_val):
self.queue = [init_val] * n #根にサイズを負の値で格納する。
self.l = 0
self.r = 0
self.n = n
self.init_val = init_val
self.count = 0
def append(self, val):
if self.count == self.n:
if self.... | p03722 |
from collections import deque
def fast_bellman_ford(n, s, graph, edge_n, init_val): #どう?
d = [init_val] * n
d[s] = 0
q = deque([s])
checker = [-1] * n
for i in range(n):
m = len(q)
for _ in range(m):
vf = q.popleft()
for vt, w in graph[vf]:
... | def bellman_ford(n, s, edges, init_val = float('inf')):
d = [init_val] * n
d[s] = 0
for _ in range(n):
updated = False
for vf, vt, w in edges:
if d[vf] != init_val and d[vt] > d[vf] + w:
d[vt] = d[vf] + w
updated = True
if not upd... | p03722 |
def bellman_ford(n, edges, s, distance=None):
if distance != None:
d = distance.copy()
else :
d = [float('inf')] * n
d[s] = 0
loop_cnt = 0
while True:
loop_cnt += 1
update = False
for i in range(len(edges)):
e = edges[i]
... | def bellman_ford(n, edges, s, distance=None):
if distance != None:
d = distance[:]
else :
d = [float('inf')] * n
d[s] = 0
loop_cnt = 0
while True:
loop_cnt += 1
update = False
for i in range(len(edges)):
e = edges[i]
... | p03722 |
class BellmanFord():
def __init__(self, N):
self.N = N
self.edges = []
def add(self, u, v, d, directed=False):
"""
u = from, v = to, d = cost
directed = Trueのとき、有向グラフである。
"""
if directed is False:
self.edges.append([u, v, d])
... | class BellmanFord():
def __init__(self, N):
self.N = N
self.edges = []
def add(self, u, v, d, directed=False):
"""
u = from, v = to, d = cost
directed = Trueのとき、有向グラフである。
"""
if directed is False:
self.edges.append([u, v, d])
... | p03722 |
n,m=list(map(int,input().split()))
inf=float("inf")
l=[tuple(map(int,input().split())) for i in range(m)]
d=[inf]*n
d[0]=0
for i in range(n):
for a,b,c in l:
a,b,c=a-1,b-1,-c
if d[a]!=inf and d[b]>d[a]+c:
d[b]=d[a]+c
if i==n-1 and b==n-1:
print("inf")
exit()
print... | n,m=list(map(int,input().split()))
es=[list(map(int,input().split())) for _ in range(m)]
inf=float("inf")
d=[-inf]*(n+1)
d[1]=0
def bellman_ford():
for i in range(n):
isUpdated=False
for e_from,e_to,cost in es:
if d[e_to]<d[e_from]+cost:
d[e_to]=d[e_from]+cost
isUpdated=True... | p03722 |
"""
検討
- 閉路が存在する場合、スコアをいくらでも大きくできる可能性がある
- 閉路を1周することで得られるスコア合計の符合によってinfにできるかどうかが判定可能
- 符合が正: inf
- 符合が0以下: 最短でNに到達したときのスコアが解
- 閉路が複数ある場合はどうするか
- 1周したときに得られるスコア合計の符合が正かどうかで判断
必要な処理
- 最短経路探索: ダイクストラ法? -> ベルマンフォード法(コストに正負があるため)
- 閉路を見つけ出す
- 閉路を1周したときのスコア合計
"""
n, m = list(map(int, input().split()))... | """
問題:
N 頂点 M 辺の重み付き有向グラフがあります。
i(1≦i≦M) 番目の辺は 頂点 ai から 頂点 bi を重み ciで結びます。
このグラフと駒を利用して、次の1人ゲームを行います。
最初、駒を頂点 1に置いて、プレイヤーのスコアを 0とします。
プレイヤーは、次の条件で駒を繰り返し移動させることができます。
- 頂点 aiに駒があるとき、i 番目の辺を利用して頂点 bi に移動する。移動後にプレイヤーのスコアが ci加算される。
頂点 Nに駒があるときのみ、ゲームを終了できます。
なお、与えられる有向グラフの上で頂点 1 から頂点 Nに移動できることは保障されています。
プレイヤーがゲ... | p03722 |
n,m=list(map(int,input().split()))
#g=[[]for _ in range(n)]
abc=[list(map(int,input().split())) for _ in range(m)]
abc=[[a-1,b-1,-c] for a,b,c in abc]
# BellmanFord
# ベルマンフォード法
def BellmanFord(edges,num_v,source):
#グラフの初期化
inf=float("inf")
dist=[inf for i in range(num_v)]
dist[source]=0
#辺の緩和
... | n,m=list(map(int,input().split()))
g=[[] for _ in range(n)]
abc=[list(map(int,input().split())) for _ in range(m)]
abc=[[a-1,b-1,-c] for a,b,c in abc]
# https://img.atcoder.jp/abc061/editorial.pdf
# 上のD問題
# BellmanFord
# ベルマンフォード法
# edges:エッジ、有向エッジ[a,b,c]a->bのエッジでコストc
# num_v:頂点の数
# source:始点
def Bellman... | p03722 |
INF = float('inf')
N, M = list(map(int, input().split()))
dist = [0] + [INF] * (N-1)
abc = []
for i in range(M):
a, b, c = list(map(int, input().split()))
abc.append((a, b, -c))
for i in range(N-1):
for a, b, c in abc:
dist[b-1] = min(dist[b-1], dist[a-1]+c)
ans = dist[-1... | def main():
INF = float('inf')
N, M = list(map(int, input().split()))
dist = [0] + [INF] * (N-1)
abc = []
for i in range(M):
a, b, c = list(map(int, input().split()))
abc.append((a, b, -c))
for i in range(N-1):
for a, b, c in abc:
if ... | p03722 |
def main():
INF = float('inf')
N, M = list(map(int, input().split()))
dist = [0] + [INF] * (N-1)
abc = []
for i in range(M):
a, b, c = list(map(int, input().split()))
abc.append((a, b, -c))
for i in range(N-1):
for a, b, c in abc:
if ... | def main():
INF = float('inf')
N, M = list(map(int, input().split()))
dist = [0] + [INF] * (N-1)
abc = []
for i in range(M):
a, b, c = list(map(int, input().split()))
abc.append((a-1, b-1, -c))
for a, b, c in abc:
dist[b] = min(dist[b], dist[a... | p03722 |
N, M = list(map(int, input().split()))
edges = []
for i in range(M):
a, b, c = list(map(int, input().split()))
edges.append([a,b,c])
dist = [float('inf')] * (N + 1)
dist[1] = 0
for _ in range(N - 1):
for a, b, c in edges:
dist[b] = min(dist[b], dist[a] - c)
ans = dist[N]
for a... | def main():
N, M = list(map(int, input().split()))
edges = []
for _ in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
edges.append([a,b,c])
d = [float('inf')] * N
d[0] = 0
for i in range(N-1):
for edge in edges:
... | p03722 |
n,m = list(map(int , input().split()))
e = []
for i in range(m):
a,b,c = list(map(int , input().split()))
e.append((a-1,b-1,c))
maxdis = [-float('inf') for i in range(n)]
maxdis[0] = 0
mugen = False
for i in range(2*n):
for j in e:
st,gl,cost = j
if (maxdis[gl] < maxdis... | n,m = list(map(int , input().split()))
e = []
for i in range(m):
a,b,c = list(map(int , input().split()))
e.append((a-1,b-1,c))
maxdis = [-float('inf') for i in range(n)]
maxdis[0] = 0
mugen = False
for i in range(n):
for j in e:
st,gl,cost = j
if (maxdis[gl] < maxdis[s... | p03722 |
n, m = list(map(int, input().split()))
graph = {}
visited = {}
# 0: not visited, 1: visited
scores = {}
for i in range(n):
if i == 0:
scores[i+1] = 0
else:
scores[i+1] = float("inf")
graph[i+1] = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
graph[a][... | n, m = list(map(int, input().split()))
graph = {}
visited = {}
# 0: not visited, 1: visited
scores = {}
for i in range(n):
if i == 0:
scores[i+1] = 0
else:
scores[i+1] = float("inf")
graph[i+1] = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
graph[a][... | p03722 |
import sys
n,m=list(map(int,input().split()))
abc=[list(map(int,input().split())) for i in range(m)]
data=[[] for i in range(n+1)]
for u in abc:
a,b,c=u
data[a].append([b,c])
inf=float("inf")
lst=[-inf]*(n+1)
lst[1]=0
que=[1]
count=0
z=0
a,b,c,d=-inf,-inf,-inf,-inf
while que:
h=[]
for u ... | n,m=list(map(int,input().split()))
abc=[list(map(int,input().split())) for i in range(m)]
inf=float("inf")
data=[-inf]*(n+1)
data[1]=0
for i in range(n):
for a,b,c in abc:
if data[a]!=inf:
data[b]=max(data[b],data[a]+c)
lst=data[:]
for i in range(n):
for a,b,c in abc:
... | p03722 |
#負の経路の検出
def find_negative_loop(n, es, d):
#始点はどこでもよい
check = [0 for _ in range(n)]
for _ in range(n):
for p, q, r in es:
#e: 辺iについて
if d[p] != float("inf") and d[q] > d[p] + r:
d[q] = d[p] + r
check[q] = True
if check[p]:... | n, m = list(map(int, input().split()))
edge = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
edge.append([a-1, b-1, -c])
d = [float("inf") for _ in range(n)]
d[0] = 0
check = [0 for _ in range(n)]
for i in range(n):
for now, next, weight in edge:
if d[next] > d[now... | p03722 |
def bellman_ford(V, E, s, std):
dist = [float('inf') for _ in range(V)]
dist[s] = 0
for i in range(V):
for s, t, d in std:
s -=1
t -= 1
d = -d
if dist[t] > dist[s] + d:
dist[t] = dist[s] + d
if i == V-1 and t+1 == V:
return -1
return dist
de... |
n, m = list(map(int, input().split()))
abc = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
c *= -1
abc += [[a,b,c]]
def bellman_ford(s):
# std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]]
# (si, ti, di): si, ti間に重さdiの辺がある
dist = [float('inf')]*n
d... | p03722 |
n, m = list(map(int, input().split()))
abc = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
c *= -1
abc += [[a,b,c]]
def bellman_ford(s):
# std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]]
# (si, ti, di): si, ti間に重さdiの辺がある
dist = [float('inf')]*n
d... | n, m = list(map(int, input().split()))
std = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
std += [[a, b, -c]]
def bellman_ford(s):
# std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]]
# (si, ti, di): si, ti間に重さdiの辺がある
dist = [float('inf')]*n
dist[s] = 0... | p03722 |
import sys
N, M = list(map(int, input().split()))
edge = [list(map(int, input().split())) for _ in range(M)]
INF = 1 << 60
cost = [- INF] * (N + 1)
cost[1] = 0
for i in range(N):
for n, nn, c in edge:
if cost[nn] < cost[n] + c:
# ワーシャルフロイド法の性質より、N回目に更新があるならinf
if i == N... | # ABC061 D - Score Attack
import sys
N, M = list(map(int, input().split()))
edge = [list(map(int, input().split())) for _ in range(M)]
INF = 1 << 60
cost = [- INF] * (N + 1)
cost[1] = 0
for i in range(N):
for n, nn, c in edge:
if cost[nn] < cost[n] + c:
# ベルマンフォード法の性質より、N回目に更新があるなら... | p03722 |
# coding: utf-8
# Your code here!
def Bellman_Ford(g,start):
n = len(g)
dist = [float("inf")]*n
dist[start] = 0
a0 = float("inf")
negative = [False]*n
for i in range((2*n)):
updated = False
for v in range(n):
for to, cost in g[v]:
if ... | # coding: utf-8
# Your code here!
def Bellman_Ford(g,start):
n = len(g)
dist = [float("inf")]*n
dist[start] = 0
a0 = float("inf")
for i in range(n<<1):
updated = False
for v in range(n):
for to, cost in g[v]:
if dist[to] <= dist[v] +... | p03722 |
n, m = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
dist = [float("inf")] * n
dist[s] = 0
negative = [False] * n
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[a] == float("inf"):
contin... | n, m = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
dist = [float("inf")] * n
dist[s] = 0
negative = [False] * n
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[b] > dist[a] + c:
dist[b] ... | p03722 |
# coding: utf-8
n,m=list(map(int,input().split()))
edge=[]
for i in range(m):
a,b,c=list(map(int,input().split()))
edge.append((a-1,b-1,-c))
inf=99999999999999999999
d=[inf for i in range(n)]
d[0]=0
count=0
while True:
count+=1
if count==n:
tmp=d[n-1]
update=False
for i in... | # coding: utf-8
n,m=list(map(int,input().split()))
edge=[]
for i in range(m):
a,b,c=list(map(int,input().split()))
edge.append((a-1,b-1,-c))
inf=99999999999999999999
d=[inf for i in range(n)]
d[0]=0
count=0
while count<n+1:
count+=1
if count==n:
tmp=d[n-1]
update=False
for... | p03722 |
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = 10 ** 13
def bfs(graph, N, M):
que = []
que.append([0, 0])
visited = [-INF for x in range(MAX_N)]
update_cnt = [0 for x in range(MAX_N)]
result = -INF
while (len(que) > 0):
now = que[0]
que.pop(0)
pos ... |
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = 10 ** 13
def bfs(graph, N, M):
que = []
que.append([0, 0])
visited = [-INF for x in range(MAX_N)]
update_cnt = [0 for x in range(MAX_N)]
result = -INF
while (len(que) > 0):
now = que[0]
que.pop(0)
pos ... | p03722 |
inf = float('inf')
N, M = list(map(int,input().split()))
edges = []
for _ in range(M):
a, b, c = list(map(int,input().split()))
a -= 1; b-= 1
edges.append((a, b, -c))
dist = [inf] * N
dist[0] = 0
for _ in range(N-1):
for v, nv, w in edges:
if dist[nv] > dist[v] + w:
d... | inf = float('inf')
# ベルマンフォード法
# 計算量O(VE) V:頂点数, E:辺の数
# [引数] n:頂点数, edges:辺集合, start:始点, end:終点
# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか
def bellmanford(n : int, edges : list, start : int, goal : int) -> (list, bool):
dist = [inf] * n
dist[start] = 0
exist_negative_cycle = T... | p03722 |
class SegmentTree:
def __init__(self, n, sentinel=0):
n2 = 1 << (n - 1).bit_length()
self.n = n2
self.data = [sentinel] * ((n2 << 1) - 1)
self.offset = n2 - 1
def update(self, k, x):
i = k + self.offset
self.data[i] = x
while i:
p... | from itertools import accumulate
from operator import itemgetter
n, d = list(map(int, input().split()))
aaa = list(map(int, input().split()))
costs_l = [(-i * d + a, i) for i, a in enumerate(aaa)]
costs_r = [(i * d + a, i) for i, a in enumerate(aaa)]
costs_l = list(accumulate(costs_l, min))
costs_r = list(ac... | p03153 |
import heapq
import sys
def input(): return sys.stdin.readline()
from collections import defaultdict
class UnionFind():
def __init__(self, num):
self.par = [-1 for _ in range(num)]
def find(self, x):
if self.par[x] < 0:
return x
else:
x = self.par... | from operator import itemgetter
import itertools
def inpl(): return list(map(int, input().split()))
def cost(x, y):
if x == y:
return float('inf')
return D * abs(x - y) + A[x] + A[y]
N, D = inpl()
A = inpl()
Right = [(v - i*D, i) for i, v in enumerate(A)]
Left = [(v + i*D, i) for i, v in enume... | p03153 |
def judT(x, y):
xR = x
while T[xR][0] != xR:
T[T[xR][0]][1] = T[xR][1] + 1
xR = T[xR][0]
yR = y
while T[yR][0] != yR:
T[T[yR][0]][1] = T[yR][1] + 1
yR = T[yR][0]
if xR != yR:
if T[xR][1] < T[yR][1]:
T[xR][0] = yR
if T[yR][1] < T[xR][1] + 1:
T[yR][1] = T[xR]... | def judT(x, y):
xR = x
xC = 0
while T[xR] != xR:
xC += 1
xR = T[xR]
yR = y
yC = 0
while T[yR] != yR:
yC += 1
yR = T[yR]
if xR != yR:
if xC < yC:
T[xR] = yR
else:
T[yR] = xR
return xR != yR
N, D = tuple(map(int,input().split()))
A = tuple(map(int, i... | p03153 |
def main():
import sys
from collections import defaultdict
input = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find_root(self, x):
if self.roo... | def main():
import sys
from collections import defaultdict
input = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find_root(self, x):
if self.roo... | p03153 |
s = input()[:-1]
for i in range(len(s)):
x = s[:i]
n = len(s[:i])
if n%2==0 and x[:i//2]==x[i//2:]:
ans = n
print(ans) | s = input()[:-1]
while s[:len(s)//2]*2 != s:
s = s[:-1]
print((len(s))) | p03672 |
s = list(input().rstrip())
while len(s)>0:
s.pop()
n = len(s)//2
if s[:n] == s[n:] and len(s) % 2 == 0:
print((len(s)))
break | s = input()[:-1]
while s[:len(s)//2] != s[len(s)//2:]:
s = s[:-1]
print((len(s))) | p03672 |
import sys
stdin = sys.stdin
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.re... | p03672 |
S = input().strip()
N = len(S)
for i in range(2,N,2):
x = S[:-i]
y = x[:(N-i)//2]
z = x[(N-i)//2:]
if y==z:
print((N-i))
break | S = input().strip()
N = len(S)
for i in range(N//2-1,0,-1):
if S[:i]==S[i:2*i]:
ans = i
break
print((ans*2)) | p03672 |
import re;print((len(re.match(r"(.+)\1",input()[:-1]).group()))) | s=input()[:-1];print((max(i*2for i in range(99)if s[:i]==s[i:i*2]))) | p03672 |
print((len(__import__("re").search(r"(.+)\1", input()[:-1]).group(0)))) | def f(a):
return a[:len(a) // 2] == a[len(a) // 2:]
a = input()[:-1]
while a:
if f(a):
print((len(a)))
exit()
else:
a = a[:-1]
print((0))
| p03672 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def is_even(S):
if len(S) % 2 != 0:
return False
if S[: len(S) // 2] == S[len(S) // 2 :]:
return True
else:
... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
N = len(S)
for w in range(N // 2 - 1, 0, -1):
ok = True
for i in range(w):
... | p03672 |
from collections import defaultdict, deque
N, M = list(map(int, input().split()))
D = {}
Edges = []
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.rank = [0] * n
# 検索
def find(self, x):
if self.par[x] == x:
return x
... | from collections import defaultdict, deque
N, M = list(map(int, input().split()))
D = {}
Edges = []
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.rank = [0] * n
# 検索
def find(self, x):
if self.par[x] == x:
return x
... | p04003 |
import sys
input = sys.stdin.readline
from collections import defaultdict
"""
(駅、会社)を頂点にグラフを持つ。頂点数O(M)。
そのまま辺を貼ると辺が多くなりすぎる。
(駅、会社) -> (駅、無属性) -> (駅、会社)
"""
N,M = list(map(int,input().split()))
graph = defaultdict(list)
for _ in range(M):
p,q,c = list(map(int,input().split()))
graph[(p,0)].append... | import sys
input = sys.stdin.readline
from collections import defaultdict
"""
(駅、会社)を頂点にグラフを持つ。頂点数O(M)。
そのまま辺を貼ると辺が多くなりすぎる。
(駅、会社) -> (駅、無属性) -> (駅、会社)
"""
L = 32
mask = (1 << L) - 1
N,M = list(map(int,input().split()))
graph = defaultdict(list)
for _ in range(M):
p,q,c = list(map(int,input().split... | p04003 |
import sys, heapq
from collections import defaultdict
def input():
return sys.stdin.readline()[:-1]
class DijkstraList():
#隣接リスト版
#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
def __init__(self, adj, start):
self.list = adj
self.start = start
self.size = len(adj)
def solve(self):
#self.dist = [float("in... | import sys, heapq
from collections import defaultdict
def input():
return sys.stdin.readline()[:-1]
class DijkstraList():
#隣接リスト版
#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
def __init__(self, adj, start):
self.list = adj
self.start = start
self.size = len(adj)
def solve(self):
#self.dist = [float("in... | p04003 |
import sys, heapq
from collections import defaultdict
def input():
return sys.stdin.readline()[:-1]
class DijkstraList():
#隣接リスト版
#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
def __init__(self, adj, start):
self.list = adj
self.start = start
self.size = len(adj)
def solve(self):
#self.dist = [float("in... | import sys, heapq
from collections import defaultdict
def input():
return sys.stdin.buffer.readline()[:-1]
class DijkstraList():
#隣接リスト版
#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
def __init__(self, adj, start):
self.list = adj
self.start = start
self.size = len(adj)
def solve(self):
#self.dist = [fl... | p04003 |
N, M = list(map(int, input().split()))
ES = []
D = {}
*parent, = list(range(M))
def root(x):
if x == parent[x]:
return x
parent[x] = y = root(parent[x])
return y
def unite(x, y):
px = root(x); py = root(y)
if px < py:
parent[py] = px
else:
parent[px] = py
... | N, M = list(map(int, input().split()))
ES = []
D = {}
*parent, = list(range(M))
def root(x):
if x == parent[x]:
return x
parent[x] = y = root(parent[x])
return y
def unite(x, y):
px = root(x); py = root(y)
if px < py:
parent[py] = px
else:
parent[px] = py
... | p04003 |
from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=list(map(int,input().split()))
G=defaultdict(set)
Comps=[[] for i in range(N)]
for i in range(M):
a,b,c=list(map(int,input().split()))
G[(a-1,c-1)].add((b-1,c-1,0))
G[(b-1,c-1)].add((a-1,c-1,0))
Comps[a-1].append(c-1)
... | from collections import defaultdict,deque
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N,M=list(map(int,input().split()))
if M==0:
print((-1))
exit()
G=defaultdict(set)
for i in range(M):
a,b,c=list(map(int,input().split()))
G[a+(c<<30)].add(b+(c<<30))
G[b+(c<<30)].add(a+(c<<30... | p04003 |
from collections import deque, defaultdict
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)
def main():
N, M = list(map(int, input().split()))
INF = 10 ** 18
Tree = defaultdict(lambda: [])
for _ in range(M):
p, q, c = list(map(int, input().split()))
... | from collections import deque, defaultdict
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)
def main():
N, M = list(map(int, input().split()))
INF = 10 ** 9
Tree = defaultdict(lambda: [])
for _ in range(M):
p, q, c = list(map(int, input().split()))
... | p04003 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, produc... | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, produc... | p04003 |
import sys
from collections import deque
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
costs = [10 ** 9] * n
corporations = [set() for _ in range(n)]
while q:
d, v, e = q.popleft()
if v == t:
return d
if costs[v] < d or e... | import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | p04003 |
import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | p04003 |
import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | p04003 |
import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visite... | p04003 |
from collections import defaultdict
from heapq import *
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(... | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_numb... | p04003 |
import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop,heappushpop,heapify
n,m = list(map(int, input().split()))
link = defaultdict(list)
chg=10**8
for _ in range(m):
p,q,c=list(map(int, input().split()))
link[p].append([p+chg*c,1])
link[p+chg*c... | import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop,heappushpop,heapify
n,m = list(map(int, input().split()))
link = defaultdict(list)
chg=10**8
for _ in range(m):
p,q,c=list(map(int, input().split()))
link[p].append([p+chg*c,1])
link[p+chg*c... | p04003 |
import sys
from collections import deque
N, M = list(map(int, input().split()))
Edge = [[] for _ in range(N+1)]
comp = set()
mod = 10**9+7
for _ in range(M):
p, q, c = list(map(int, input().split()))
Edge[p].append(mod*q+c)
Edge[q].append(mod*p+c)
comp.add(c)
dist = {mod: 0}
Q = deque()
Q.a... | import sys
readline = sys.stdin.readline
from heapq import heappop as hpp, heappush as hp
inf = 10**9+7
def dijkstra(N, s, Edge):
dist = [inf] * N
dist[s] = 0
Q = [(0, s)]
while Q:
dn, vn = hpp(Q)
if dn > dist[vn]:
continue
for df, vf in Edge[vn]:
... | p04003 |
from heapq import heappush, heappop
from collections import defaultdict
N, M = list(map(int, input().split()))
INF = 10**18
edges = defaultdict(set)
C = set()
for _ in range(M):
fr, to, c = list(map(int, input().split()))
edges[(fr, c)].add((to, c, 0))
edges[(to, c)].add((fr, c, 0))
edge... | from heapq import heappush, heappop, heapify
import sys
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
C = set()
edges = [[] for _ in range(N)]
for _ in range(M):
fr, to, c = list(map(int, input().split()))
fr -= 1
to -= 1
edges[fr].append((to, c))
edges[to].... | p04003 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.re... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.re... | p04003 |
from collections import*
from heapq import*
inf=10**18
n,m,*t=list(map(int,open(0).read().split()))
e=defaultdict(list)
s=[]
l=[]
f=g=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if a<2:f=True
if b==n:g=True
x,y=a+n*c,b+n*c
if b==n:l.append(y)
e[a].append((1,x))
e[b].appen... | def main():
from collections import defaultdict
from heapq import heappush,heappop
inf=10**18
n,m,*t=list(map(int,open(0).read().split()))
e=defaultdict(list)
s=[]
l=[]
f=g=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if a<2:f=True
if b==n:g=True
x,y=a+n*... | p04003 |
def main():
from collections import defaultdict
from heapq import heappush,heappop,heapify
from bisect import bisect_left
B=bisect_left
inf=2**31-1
n,m,*t=list(map(int,open(0).read().split()))
if not t:
print((-1))
exit()
z=[]
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
z.extend(... | def main():
from heapq import heappush,heappop,heapify
inf=2**31-1
n,m,*t=list(map(int,open(0).read().split()))
z=[]
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
z.extend([a,b,a+n*c,b+n*c])
z={i:v for v,i in enumerate(sorted(set(z)))}
try:
z[1]
except:
print((-1))
exit()
edge... | p04003 |
def resolve():
def Dijkstra(s, g):
import heapq
d = {}
d[s] = 0
queue = []
for q in edge[s]:
heapq.heappush(queue, q)
while queue:
dist, point = heapq.heappop(queue)
if point in d:
continue
d[... | def resolve():
def Dijkstra(s, g):
import heapq
d = {}
d[s] = 0
queue = []
for q in edge[s]:
heapq.heappush(queue, q)
while queue:
dist, point = heapq.heappop(queue)
q = [point]
while q:
point... | p04003 |
def resolve():
def Dijkstra(s, g):
import heapq
d = {s}
queue = []
for q in edge[s]:
heapq.heappush(queue, q)
while queue:
dist, point = heapq.heappop(queue)
q = [point]
while q:
point = q.pop()
... | def resolve():
def Dijkstra(s, g):
from collections import deque
d = {s}
queue = deque()
for q in edge[s]:
queue.append(q)
while queue:
dist, point = queue.popleft()
if point in d:
continue
d.add(point... | p04003 |
from collections import deque
n, m = list(map(int, input().split()))
edges = [[] for i in range(n)]
for i in range(m):
p, q, c = list(map(int, input().split()))
p, q, c = p-1, q-1, c-1
edges[p].append((q, c))
edges[q].append((p, c))
que = deque()
cost = [float("inf")]*n
colr = [-1]*n
# no... | # https://juppy.hatenablog.com/entry/2019/04/10/ARC061_-_E_%E3%81%99%E3%81%AC%E3%81%91%E5%90%9B%E3%81%AE%E5%9C%B0%E4%B8%8B%E9%89%84%E6%97%85%E8%A1%8C_-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder
# 参考にさせていただきました。
from collections import deque, defaultdict
chg ... | p04003 |
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m,*pqc = list(map(int, read().split()))
g = {}
M = iter(pqc)
for p,q,c in zip(M,M,M):
pc = ((p-1)<<20)+c
qc = ((q-1)<<20)+c
pp = (p-1)<<20
qq = (q-1)<<20
if pc not in g: g[pc] ... | # coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m,*pqc = list(map(int, read().split()))
g = {}
M = iter(pqc)
for p,q,c in zip(M,M,M):
pc = ((p-1)<<20)+c
qc = ((q-1)<<20)+c
pp = (p-1)<<20
qq = (q-1)<<20
if pc not in g: g[pc] ... | p04003 |
from collections import deque, defaultdict
import sys
input = sys.stdin.readline
def main():
N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
p, q, c = map(int, input().split())
adj[p].append((q, c))
adj[q].append((p, c))
deq = de... | def main():
import sys
from collections import deque
input = sys.stdin.readline
N, M = list(map(int, input().split()))
adj = [[] for _ in range(N+1)]
c2v = {}
v = N+1
for _ in range(M):
p, q, c = list(map(int, input().split()))
P = p*(10**7) + c
Q = q... | p04003 |
import bisect
N, T = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
"""
a_x = 1 and b_x is t_i = 2*(t_i +2)
n 店舗回るのに 2^nはかかる
30店舗以上は回れない
"""
a0 = []
nab = []
for a, b in AB:
if a == 0:
a0.append(b)
else:
nab.append(((b + 1) / a, a, b... | import bisect
N, T = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
"""
a_x = 1 and b_x is t_i = 2*(t_i +2)
n 店舗回るのに 2^nはかかる
30店舗以上は回れない
"""
a0 = []
nab = []
for a, b in AB:
if a == 0:
a0.append(b)
else:
nab.append(((b + 1) / a, a, b... | p02750 |
def main():
# input
N, T = list(map(int, input().split()))
a, b = [], []
a0_b = []
for i in range(N):
a_in, b_in = list(map(int, input().split()))
if a_in == 0:
a0_b.append(b_in)
else:
a.append(a_in)
b.append(b_in)
L = len(a... | import sys
input = sys.stdin.readline
def main():
# input
N, T = list(map(int, input().split()))
a, b = [], []
a0_b = []
for i in range(N):
a_in, b_in = list(map(int, input().split()))
if a_in == 0:
a0_b.append(b_in)
else:
a.append(a_in... | p02750 |
#!/usr/bin/env pypy3
import sys
import math
import itertools
import bisect
INF = int(1e18)
T_MAX = int(1e9)
def main():
N, T = list(map(int, sys.stdin.readline().split()))
shops = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
nzshops = [(a, b) for a, b in shops if a > 0... | #!/usr/bin/env pypy3
import sys
import math
import itertools
import bisect
INF = int(1e18)
def main():
n, t = list(map(int, sys.stdin.readline().split()))
nzshops = []
zshops = []
for _ in range(n):
a, b = list(map(int, sys.stdin.readline().split()))
(zshops if a == 0... | p02750 |
#!/usr/bin/env pypy3
import sys
import math
import itertools
import bisect
INF = int(1e18)
def main():
n, t = list(map(int, sys.stdin.readline().split()))
nzshops = []
zshops = []
for _ in range(n):
a, b = list(map(int, sys.stdin.readline().split()))
(zshops if a == 0... | #!/usr/bin/env pypy3
import sys
import math
import itertools
import bisect
INF = int(1e18)
n, t = list(map(int, sys.stdin.readline().split()))
nzshops = []
zshops = []
for _ in range(n):
a, b = list(map(int, sys.stdin.readline().split()))
(zshops if a == 0 else nzshops).append((a, b))
nzsh... | p02750 |
# https://atcoder.jp/contests/hitachi2020/submissions/10704509
def main():
import sys
input = sys.stdin.readline
inf = 1 << 30
L = 30
N, T = list(map(int, input().split()))
ps = []
coef_0 = []
for _ in range(N):
a, b = list(map(int, input().split()))
if... | # https://atcoder.jp/contests/hitachi2020/submissions/10704509
# PyPyなら通る
def main():
import sys
input = sys.stdin.readline
inf = 1 << 30
L = 30
N, T = list(map(int, input().split()))
ps = []
coef_0 = []
for _ in range(N):
a, b = list(map(int, input().split()))... | p02750 |
# https://atcoder.jp/contests/hitachi2020/submissions/10704509
# PyPyなら通る
def main():
import sys
input = sys.stdin.readline
inf = 1 << 30
L = 30
N, T = list(map(int, input().split()))
ps = []
coef_0 = []
for _ in range(N):
a, b = list(map(int, input().split()))... | # https://atcoder.jp/contests/hitachi2020/submissions/10704509
# PyPyなら通る
def main():
import sys
input = sys.stdin.readline
inf = 1 << 30
L = 30
N, T = list(map(int, input().split()))
ps = []
coef_0 = []
for _ in range(N):
a, b = list(map(int, input().split()))... | p02750 |
import sys
input = sys.stdin.readline
N,T=list(map(int,input().split()))
M=[list(map(int,input().split())) for i in range(N)]
def compare(x,y):
if x==0:
return (1<<31)+y
else:
return (y+1)/x
M.sort(key=lambda x:compare(x[0],x[1]))
k=N
for i in range(N):
if M[i][0]==0:
... | import sys
input = sys.stdin.readline
N,T=list(map(int,input().split()))
M=[list(map(int,input().split())) for i in range(N)]
def compare(x,y):
if x==0:
return (1<<31)+y
else:
return (y+1)/x
M.sort(key=lambda x:compare(x[0],x[1]))
k=N
for i in range(N):
if M[i][0]==0:
... | p02750 |
import sys
from bisect import bisect_right
N,T = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(N)]
#%%
b0 = []
ab1 = []
for a,b in ab:
if a==0:
b0.append(b+1)
else:
ab1.append([a/(b+1), a, b+1])
N0 = len(b0)
N1 = len(ab1)
b0.sort()
if N0>... | import sys
from bisect import bisect_right
N,T = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(N)]
#%%
b0 = []
ab1 = []
for a,b in ab:
if a==0:
b0.append(b+1)
else:
ab1.append([(b+1)/a, a, b])
N0 = len(b0)
N1 = len(ab1)
b0.sort()
if N0>0:... | p02750 |
from bisect import bisect_right
n, t = list(map(int, input().split()))
shop = []
shop_a0 = []
for i in range(n):
a, b = list(map(int, input().split()))
if a != 0:
shop.append([a, b, a/(b+1)])
else:
shop_a0.append(b)
shop = sorted(shop, key=lambda x: -x[2])
shop_a0 = sorted... | from bisect import bisect_right
n, t = list(map(int, input().split()))
shop = []
shop_a0 = []
for i in range(n):
a, b = list(map(int, input().split()))
if a != 0:
shop.append([a, b, a/(b+1)])
else:
shop_a0.append(b)
shop = sorted(shop, key=lambda x: -x[2])
shop_a0 = sorted... | p02750 |
N,K=list(map(int,input().split()))
p=[int(i)-1 for i in input().split()]
q=[int(i)-1 for i in input().split()]
def inv(seq):
res=[0 for i in range(N)]
for i in range(N):
res[seq[i]]=i
return res
def times(seq1,seq2):
res=[0 for i in range(N)]
for i in range(N):
res[i]=seq1... | N,K=list(map(int,input().split()))
p=[int(i)-1 for i in input().split()]
q=[int(i)-1 for i in input().split()]
def inv(seq):
res=[0 for i in range(N)]
for i in range(N):
res[seq[i]]=i
return res
def times(seq1,seq2):
res=[0 for i in range(N)]
for i in range(N):
res[i]=seq1... | p03098 |
N,K=list(map(int,input().split()))
p=[int(i)-1 for i in input().split()]
q=[int(i)-1 for i in input().split()]
def inv(seq):
res=[0 for i in range(N)]
for i in range(N):
res[seq[i]]=i
return res
def times(seq1,seq2):
res=[0 for i in range(N)]
for i in range(N):
res[i]=seq1... | N,K=list(map(int,input().split()));p=[int(i)-1 for i in input().split()];q=[int(i)-1 for i in input().split()]
def I(s):
r=[0 for i in range(N)]
for i in range(N):r[s[i]]=i
return r
def T(s,t):
r=[0 for i in range(N)]
for i in range(N):r[i]=s[t[i]]
return r
m=[[0 for i in range(N)] for i in range(6)];A=T... | p03098 |
N,K=list(map(int,input().split()));p=[int(i)-1 for i in input().split()];q=[int(i)-1 for i in input().split()]
def I(s):
r=[0 for i in range(N)]
for i in range(N):r[s[i]]=i
return r
def T(s,t):
r=[0 for i in range(N)]
for i in range(N):r[i]=s[t[i]]
return r
m=[[0 for i in range(N)] for i in range(6)];A=T... | N,K=list(map(int,input().split()));p=[int(i)-1 for i in input().split()];q=[int(i)-1 for i in input().split()]
def I(s):
r=[0]*N
for i in range(N):r[s[i]]=i
return r
def T(s,t):return [s[t[i]] for i in range(N)]
m=[[0 for i in [0]*N] for i in [0]*6]
for i in range(N):m[0][i]=p[i];m[1][i]=q[i]
for i in range(... | p03098 |
n = int(input())
a = list(map(int, input().split()))
print(" ".join(map(str, a)))
for j in range(1,n):
key = a[j]
i = j-1
while i >= 0 and a[i] > key:
a[i+1] = a[i]
i = i - 1
a[i+1] = key
print(" ".join(map(str, a))) | def isort(n,a):
print(" ".join(map(str, a)))
for j in range(1,n):
key = a[j]
i = j-1
while i >= 0 and a[i] > key:
a[i+1] = a[i]
i = i - 1
a[i+1] = key
print(" ".join(map(str, a)))
n = int(input())
a = list(map(int, input().split()))
i... | p02255 |
n = int(input())
lst = list(map(int,input().split()))
def pri(lst):
for i in range(len(lst)-1):
print(lst[i],end=" ")
print(lst[-1])
pri(lst)
for i in range(1,n):
v = lst[i]
j = i-1
while True:
if j < 0:
lst[0] = v
break
if lst[j] > v... | def insertsort(array):
for i in range(1,len(array)):
print((" ".join(list(map(str,array)))))
temp = array[i]
j = i-1
while j >= 0 and temp < array[j]:
array[j+1] = array[j]
j -= 1
array[j+1] = temp
return array
eval(input())
a = insert... | p02255 |
def show_list(num_list):
for i in range(len(num_list)):
print(str(num_list[i]), end="")
if i < len(num_list)-1:
print(" ", end="")
else:
print()
input_num = int(input())
num_list = [int(i) for i in input().split()]
show_list(num_list)
for i in range(1, len... | # -*- coding : utf-8 -*-
def insertion_sort(list):
for i in range(1, len(list)):
key = list[i]
j = i - 1
show_list(list)
while(j >= 0 and list[j] > key):
list[j+1] = list[j]
j = j - 1
list[j+1] = key
show_list(list)
return list
... | p02255 |
list_len = int(input().rstrip())
num_list = list(map(int, input().rstrip().split()))
for i in range(list_len):
v = num_list[i]
j = i - 1
while j >= 0 and num_list[j] > v:
num_list[j + 1] = num_list[j]
j -= 1
num_list[j+1] = v
output_str = ' '.join(map(str, num_list... | def insertion_sort(A, N):
for i in range(N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
print((' '.join(map(str, A))))
def main():
N = int(input().rstrip())
A = list(map(int, input(... | p02255 |
def insertion_sort(array, element_number):
for i in range(element_number):
v = array[i]
j = i - 1
while(j>=0 and array[j] > v):
array[j+1] = array[j]
j = j - 1
array[j+1] = v
for k in range(element_number):
if k < element_num... | def insertion_sort(array):
'''?????????????´?????????????????????¨??????????????????????????¨???????????????????????§?????\?????????????????°????????????
1. ??????????????¨??????????????????????´?????????????????????? v ????¨?????????????
2. ????????????????????¨??????????????????v ????????§??????????´??... | p02255 |
l = []
for i in range(1,151):
for j in range(1,151):
if i==j or i>j: continue
l += [[i**2+j**2,i,j]]
l = sorted(l)
while True:
h,w = map(int,input().split())
if w==h==0: break
i = l.index([w**2+h**2,h,w])+1
print(*l[i][1:],sep=' ')
| l = [[i**2+j**2,i,j] for j in range(1,151) for i in range(1,151) if i!=j and i<j]
l = sorted(l)
while True:
h,w = map(int,input().split())
if w==h==0: break
i = l.index([w**2+h**2,h,w])+1
print(*l[i][1:],sep=' ')
| p00767 |
a,b,c = list(map(int, input().split()))
if (a+b) >= c:
print("Yes")
else:
print("No") | a,b,c = list(map(int, input().split()))
print(("Yes" if a+b >= c else "No")) | p03407 |
a, b, c = list(map(int, input().split(' ')))
print(("Yes" if a + b >= c else "No" )) | coin_1, coin_2, value = list(map(int, input().split(' ')))
if (coin_1 + coin_2) >= value:
print("Yes")
else:
print("No") | p03407 |
(a, b, c) = list(map(int, input().split()))
if a + b >= c:
print("Yes")
else:
print("No") | a, b, x = list(map(int, input().split()))
if a+b >= x:
print("Yes")
else:
print("No") | p03407 |
a,b,c = list(map(int,input().split()))
# print(a,b,c)
if c <= a + b:
print('Yes')
else:
print('No')
| a,b,c = list(map(int,input().split()))
print(('No' if a+b < c else 'Yes'))
| p03407 |
Tmp = []
Tmp = input().rstrip().split(' ')
X = int(Tmp[0])
Y = int(Tmp[1])
C = int(Tmp[2])
Ans = X + Y
if Ans >= C:
print('Yes')
else:
print('No')
| A, B, C=list(map(int,input().split()))
A += B
if A >= C:
print('Yes')
else:
print('No')
| p03407 |
N = int(eval(input()))
P = list(map(int, input().split()))
if N == 1:
print((0))
exit()
Pi = [0] * (N + 1)
for i, n in enumerate(P, 1):
Pi[n] = i
T = [0] * N
f = [0] * N
if Pi[N] > Pi[N - 1]:
T[N - 1] = 0
f[N - 1] = N - 1
else:
T[N - 1] = 1
f[N - 1] = N
for i in ran... | N = int(eval(input()))
P = list(map(int, input().split()))
Pi = [0] * (N + 1)
for i, n in enumerate(P, 1):
Pi[n] = i
i = N - 1
T = 0
f = 0
while i:
i_f = Pi[f]
i_i = Pi[i]
i_ii = Pi[i + 1]
if i_f < i_ii < i_i or i_i < i_f < i_ii or i_ii < i_i < i_f:
T += 1
f = i +... | p03728 |
from math import ceil
def main():
x = int(eval(input()))
answer = ceil(x / 11)
if 1 <= x % 11 <= 6:
answer = answer * 2 - 1
else:
answer *= 2
print(answer)
if __name__ == '__main__':
main()
| def main():
x = int(eval(input()))
answer = (x // 11) * 2
if 1 <= x % 11 <= 6:
answer += 1
elif 7 <= x % 11:
answer += 2
print(answer)
if __name__ == '__main__':
main()
| p03817 |
import sys
x = int(sys.stdin.readline().strip())
"""
1
5423
6
"""
r = x // 11
res = x - 11*r
if res == 0:
print((2*r))
elif res > 6:
print((2*r + 2))
else:
print((2*r + 1)) | import sys
x = int(sys.stdin.readline())
n = x // 11
r = x % 11
if r == 0:
print((2*n))
elif r <= 6:
print((2*n + 1))
else:
print((2 * (n+1))) | p03817 |
import sys
x = int(sys.stdin.readline())
n = x // 11
r = x % 11
if r == 0:
print((2*n))
elif r <= 6:
print((2*n + 1))
else:
print((2 * (n+1))) | import sys
x = int(sys.stdin.readline())
n = x // 11
r = x % 11
if r == 0:
print((2*n))
elif r <= 6:
print((2*n+1))
else:
print((2*n+2)) | p03817 |
import math
x = int(eval(input()))
if 1 <= x%11 <= 6:
print((math.ceil(x/11)*2 - 1))
else:
print((math.ceil(x/11)*2)) | n = int(eval(input()))
ans = n//11*2
if 0 < n%11 <= 6:
ans += 1
elif 6 < n%11 <= 10:
ans += 2
print(ans) | p03817 |
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def ... | import sys
def I(): return int(sys.stdin.readline().rstrip())
x = I()-1
print((x//11*2+1+(x%11)//6))
| p03817 |
def main():
x = int(eval(input()))
ans = x//11
x -= ans*11
ans *= 2
if 0 < x <= 6:
ans += 1
elif 6 < x:
ans += 2
print(ans)
if __name__ == '__main__':
main()
| def main():
x = int(eval(input()))
ans = x // 11
x -= ans * 11
ans *= 2
if x <= 0:
print(ans)
elif x <= 6:
print((ans + 1))
else:
print((ans + 2))
if __name__ == '__main__':
main()
| p03817 |
x = int(eval(input()))
if 1 <=x%11 <= 6:
print((x//11*2+1))
elif 7 <= x%11 <= 10:
print((x//11*2+2))
else:
print((x//11*2)) | N = int(eval(input()))
if N%11 == 0:
print((N//11*2))
elif 0 < N%11 <=6 :
print((N//11*2+1))
else:
print((N//11*2+2)) | p03817 |
def main():
x = int(eval(input()))
s = 0
f = 0
ans = 0
while ans < x:
s += 1
ans += 6
if ans >= x:
print((s+f))
exit()
f += 1
ans += 5
if ans >= x:
print((s+f))
exit()
if __name__ == "__... | def main():
x = int(eval(input()))
ans = x//11
chk = x%11
if chk == 0:
print((2*ans))
elif chk <=6:
print((2*ans+1))
else:
print((2*ans+2))
if __name__ == "__main__":
main() | p03817 |
x = int(eval(input()))
n = x//11
k = x%11
if k==0:
print((2*n))
elif 0<k<=6:
print((2*n+1))
else:
print((2*n+2)) | x = int(eval(input()))
n = x//11
a = x%11
if a==0:
ans = 2*n
elif 1<=a<=6:
ans = 2*n+1
else:
ans = 2*n+2
print(ans) | p03817 |
import sys
import math
input = sys.stdin.readline
n = int(eval(input()))
ans = math.ceil(n / 11 * 2)
if (n - 6) % 11 == 0:
ans -= 1
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
ans = n // 11 * 2
if 1 <= n % 11 <= 6:
ans += 1
elif 7 <= n % 11 <= 10:
ans += 2
print(ans)
| p03817 |
def slove():
import sys
input = sys.stdin.readline
x = int(input().rstrip('\n'))
cnt = (x + 10) // 11 * 2
if x % 11 <= 6 and x % 11 != 0:
print((cnt-1))
else:
print(cnt)
if __name__ == '__main__':
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
x = int(readline())
cnt = x // 11 * 2
x %= 11
if x == 0:
print(cnt)
elif 1 <= x <= 6:
print((cnt + 1))
elif 7 <= x <= 10:
print((cnt + 2))
if __name__ == '__main__'... | p03817 |
x = int(eval(input()))
nums = [i for i in range(6, 0, -1)]
if x % 11 == 0:
ans = (x // 11) * 2
else:
if x % 11 <= 6:
ans = (x // 11) * 2 + 1
else:
ans = (x // 11 + 1) * 2
print(ans)
| x = int(eval(input()))
if x % 11 == 0:
ans = x // 11 * 2
else:
if x % 11 <= 6:
ans = x // 11 * 2 + 1
else:
ans = (x // 11 + 1) * 2
print(ans)
| p03817 |
a = int(eval(input()))
count = 0
if a % 11 < 7 and a % 11 != 0:
count += 1
elif a % 11 != 0:
count += 2
count += (a // 11) * 2
print(count)
| a = int(eval(input()))
x = (a // 11) * 2
if a % 11 > 6:
x += 2
elif a % 11 > 0:
x += 1
print(x) | p03817 |
x = int(eval(input()))
ans = (x // 11) * 2
ans += 1 if x % 11 > 6 else 0
ans += 1 if x % 11 > 0 else 0
print(ans)
| x=int(eval(input()))
print(((x//11)*2 + (x%11) // 6 + (1 if x%11%6 else 0))) | p03817 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.