input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations #from itertools import accumulate, product, permutations from math import floor, ceil ...
''' 頂点1から全頂点通る一筆書きが何個あるか 頂点数(N)は最大で8なので道順を全列挙して調べてもいける ''' def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations #from itertools import accum...
p03805
''' 頂点1から全頂点通る一筆書きが何個あるか 頂点数(N)は最大で8なので道順を全列挙して調べてもいける ''' def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations #from itertools import accum...
res = 0 def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations #from itertools import accumulate, product, permutations from math import flo...
p03805
import sys input=sys.stdin.readline #グラフの連結成分を調べる def Graph(ab): G=[[] for i in range(n)] for a,b in ab: G[a-1].append(b) G[b-1].append(a) return G from collections import deque def dfs(G,v,p,n): q=deque() q.append((v,p,1,0)) log=[0]*n log[v-1]=1 ans=0 ...
import sys input=sys.stdin.readline #グラフの連結成分を調べる def Graph(ab): G=[[] for i in range(n)] for a,b in ab: G[a-1].append(b) G[b-1].append(a) return G from collections import deque def dfs(G,v,p,n): q=deque() q.append((v,p,1,0)) log=[0]*n log[v-1]=1 ans=0 ...
p03805
from itertools import permutations N,M = list(map(int,input().split())) Matrix = [[False for i in range(N)] for j in range(N)] for i in range(M) : a,b = list(map(int,input().split())) a -= 1 b -= 1 Matrix[a][b] = True Matrix[b][a] = True for i in range(N) : Matrix[i][i] = True ...
from itertools import permutations N,M = list(map(int,input().split())) Matrix = [[False for x in range(N)] for y in range(N)] for i in range(N) : Matrix[i][i] = True for i in range(M) : a,b = list(map(int,input().split())) a -= 1 b -= 1 Matrix[a][b] = True Matrix[b][a] = True a...
p03805
from itertools import permutations N,M = list(map(int,input().split())) L = [[] for i in range(N)] for i in range(M) : a,b = list(map(int,input().split())) a -= 1 b -= 1 L[a].append(b) L[b].append(a) P = permutations([0] + [i for i in range(1,N)]) ans = 0 for perm in P :...
from itertools import permutations N,M = list(map(int,input().split())) L = [[False for j in range(N)] for i in range(N)] for i in range(M) : a,b = list(map(int,input().split())) a -= 1 b -= 1 L[a][b] = True L[b][a] = True P = list(permutations(list(range(1,N)))) ans = 0 ...
p03805
from itertools import permutations from math import factorial n, m = list(map(int, input().split(' '))) edge = [] for i in range(m): ai, bi = list(map(int, input().split(' '))) edge.append([ai,bi]) x = [i for i in range(1,n+1)] ls = list(permutations(x)) ans = 0 for l in range(factorial(n-1)):...
from itertools import permutations from math import factorial n, m = list(map(int, input().split(' '))) edge = [] for i in range(m): ai, bi = list(map(int, input().split(' '))) edge.append([ai, bi]) l = [i for i in range(1, n+1)] ls = list(permutations(l)) ans = 0 for i in range(factorial(n-1)): ...
p03805
import itertools N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(M)] P = N-1 count = 0 for path in itertools.permutations(ab, P): flag = True prev = 1 memo = [0]*N for i in range(P): memo[prev-1] += 1 if flag == True: if path[i][0] == pre...
import itertools N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(M)] count = 0 for path in itertools.permutations([i for i in range(2, N+1)], N-1): flag = True if [1, path[0]] in ab or [path[0], 1] in ab: pass else: flag = False continue for...
p03805
# https://atcoder.jp/contests/abc054/tasks/abc054_c import copy import sys input = sys.stdin.readline # 頂点, 辺の数 N, M = list(map(int, input().split())) # グラフのリスト # 各頂点からどこの頂点に向かう辺があるかどうかという情報 Graph_list = [[] for i in range(N)] # 入力 for i in range(M): a, b = list(map(int, input().split())) a ...
# https://atcoder.jp/contests/abc054/tasks/abc054_c import copy import sys input = sys.stdin.readline # 頂点, 辺の数 N, M = list(map(int, input().split())) # グラフのリスト # 各頂点からどこの頂点に向かう辺があるかどうかという情報 Graph_list = [[] for i in range(N)] # 入力 for i in range(M): a, b = list(map(int, input().split())) a ...
p03805
from itertools import permutations N, M, *ab = list(map(int, open(0).read().split())) g = [[0] * N for _ in range(N)] for a, b in zip(*[iter(ab)] * 2): g[a - 1][b - 1] = 1 g[b - 1][a - 1] = 1 ans = 0 for path in permutations(list(range(1, N))): path = [0] + list(path) if all(g[v][nv] for ...
def dfs(v): if sum(visited) == N: return 1 res = 0 for nv in g[v]: if visited[nv]: continue visited[nv] = 1 res += dfs(nv) visited[nv] = 0 return res N, M, *ab = list(map(int, open(0).read().split())) g = [[] for _ in range(N)] for a, ...
p03805
from copy import deepcopy cnt = 0 depth = 0 def main(): n, m = list(map(int, input().split())) adj = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) def f(u, d): ...
class Graph: def __init__(self, n, adj): self.adj = adj self.cnt = 0 self.depth = 0 self.ds = [-1] * n def solve(self, u): self.ds[u] = self.depth if self.ds.count(-1) == 0: self.cnt += 1 return self.depth += 1 ...
p03805
class Graph: def __init__(self): n, m = list(map(int, input().split())) self.adj = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 self.adj[a].append(b) self.adj[b].append(a)...
from itertools import permutations n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] g = [[0] * n for _ in range(n)] for a, b in ab: a -= 1 b -= 1 g[a][b] = 1 g[b][a] = 1 ans = 0 for pat in permutations(list(range(1, n)), n - 1): is_path...
p03805
def DFS(s): global ans,color color[s]="gray" if "white" not in color: ans +=1 for i in M[s]: if color[i]=="white": DFS(i) color[s]="white" n,m=list(map(int,input().split())) M=[[] for _ in range(n)] for i in range(m): a,b=list(map(int,input().split()...
def DFS(s): global ans,color color[s]="black" if "white" not in color: ans +=1 for i in M[s]: if color[i]=="white": DFS(i) color[s]="white" n,m=list(map(int,input().split())) M=[[] for _ in range(n)] for i in range(m): a,b=list(map(int,input().split(...
p03805
def DFS(s): global ans,color color[s]="black" if "white" not in color: ans +=1 for i in M[s]: if color[i]=="white": DFS(i) color[s]="white" n,m=list(map(int,input().split())) M=[[] for _ in range(n)] for i in range(m): a,b=list(map(int,input().split(...
def DFS(num): global ans,color color[num]="black" if "white" not in color: ans +=1 for i in M[num]: if color[i]=="white": DFS(i) color[num]="white" n,m=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(m)] M=[[] for _ in ran...
p03805
n, m = list(map(int, input().split())) g = [[]for _ in range(n + 1)] for _ in range(m): a, b = list(map(int, input().split())) g[a].append(b) g[b].append(a) ret = 0 def walk(node, visited): global ret tmp = visited + [node] if len(tmp) == n: ret += 1 for nd in g[node]...
N, M = list(map(int, input().split())) g = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, input().split())) g[a].append(b) g[b].append(a) ans = 0 def walk(cur, visited): global ans tmp = visited + [cur] if len(tmp) == N: ans += 1 for nex in g[cur]: ...
p03805
N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 to[a].append(b) to[b].append(a) res = 0 def dfs(v, seen): global res if seen == [1] * N: res += 1 return for nv ...
N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 to[a].append(b) to[b].append(a) def dfs(v, seen): if seen == [1] * N: return 1 res = 0 for nv in to[v]: if ...
p03805
# coding: utf-8 count=0 def check(now,v,n): global count v[now]=1 if sum(v)==n: count+=1 else: for i in range(8): if v[i]==0 and g[now][i]==1: check(i,v[:],n) n,m=list(map(int,input().split())) g=[[0 for i in range(8)]for i in range(8)] for i in...
# coding: utf-8 count=0 def check(now,v,n): global count v[now]=1 if sum(v)==n: count+=1 else: for i in range(n): if v[i]==0 and g[now][i]==1: check(i,v[:],n) n,m=list(map(int,input().split())) g=[[0 for i in range(n)]for i in range(n)] for i in...
p03805
import itertools N, M = list(map(int, input().split())) ab = [0] * M for i in range(M): ab[i] = list(map(int, input().split())) perms = itertools.permutations(list(range(1, N+1))) ans = 0 for perm in perms: if perm[0] != 1: continue is_goal = True for i in range(N-1): a = perm[i] b ...
# https://img.atcoder.jp/abc054/editorial.pdf N, M = list(map(int, input().split())) graph = [[False for _ in range(N)] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) graph[a-1][b-1] = graph[b-1][a-1] = True def dfs(v, visited): all_visited = True for i in range(N): ...
p03805
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) G = [[] for i in range(N)] for i in range(M): a,b = list(map(int,readline().split())) G[a-1].append(b-1) G[b-1].append(a-1) ans = 0 stack = [] stack.append([0,set()]) while stack: v,visited = stack.pop() if v...
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) G = [[] for i in range(N)] for i in range(M): a,b = list(map(int,readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) stack = [] stack.append([0, set()]) ans = 0 while stack: v, visited = stack.pop()...
p03805
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] de...
# https://atcoder.jp/contests/abc054/tasks/abc054_c import math,itertools,fractions,heapq,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline...
p03805
# https://atcoder.jp/contests/abc054/tasks/abc054_c import math,itertools,fractions,heapq,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline...
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] # def LF(): return [float(x) f...
p03805
import itertools N, M = list(map(int, input().split())) graph = [[0] * N for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) graph[a-1][b-1] = 1 graph[b-1][a-1] = 1 p = list(itertools.permutations(list(range(N)))) Sum = 0 for i in range(len(p)): if p[i][0] ...
N, M = list(map(int, input().split())) g = [[] for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) g[a-1].append(b-1) g[b-1].append(a-1) visited = [False for _ in range(N)] def dfs(v, visited): if all(visited): return 1 total = 0 for cv in g[v]: if not vi...
p03805
import itertools N, M = list(map(int, input().split())) E = set([tuple(sorted(map(int, input().split()))) for x in range(M)]) cnt = 0 for i in itertools.permutations(list(range(2,N+1)), N-1): l = [1]+list(i) if sum(1 for x in range(N-1) if tuple(sorted(l[x:x+2])) in E) == N-1: cnt += 1 print(cnt...
import itertools N, M = list(map(int, input().split())) D = {tuple(sorted(map(int, input().split()))) for x in range(M)} cnt = 0 for i in itertools.permutations(list(range(2, N+1)), N-1): l = [1]+list(i) cnt += sum(1 for x in zip(l,l[1:]) if tuple(sorted(x)) in D) == N-1 print(cnt)
p03805
# ABC054 C One-stroke Path N,M = list(map(int, input().split())) G = [[] for _ in range(N)] reached = [False]*N for _ in range(M): a,b = list(map(int, input().split())) G[a-1].append(b-1) G[b-1].append(a-1) cnt = 0 def DFS(x): global cnt global reached reached[x] = True ...
#ABC054 C - One-stroke Path # v:現在の頂点 seen:訪問済みの頂点 def dfs(v,seen): if all(seen): return 1 res = 0 # 頂点vに隣接しているnvを探索していく for nv in G[v]: if seen[nv]: continue seen[nv]=True res += dfs(nv,seen) # 次の隣接頂点nvを探索した時の探索経路で、 # 今回探索した隣接頂点...
p03805
n,m=list(map(int,input().split())) G=[[0]*n for i in range(n)] for i in range(m): a,b=list(map(int,input().split())) G[a-1][b-1]=G[b-1][a-1]=1 from itertools import permutations ans=0 p=list(permutations([x for x in range(1,n)])) for pp in p: ok=True t=[0]+list(pp) for i in range(1,n): if G[...
def dfs(v,visited): if all(visited): return 1 res=0 for nv in G[v]: if visited[nv]: continue visited[nv]=1 res+=dfs(nv,visited) visited[nv]=0 return res n,m=list(map(int, input().split())) G=[[] for _ in range(n)] visited=[0]*n res=0 for i in range(m): a,b=list(...
p03805
import itertools n,m= list(map(int, input().split())) a= [list(map(int, input().split())) for i in range(m)] # 経路全探索 ans=0 for v in itertools.combinations(a, n-1): b=[[] for i in range(n)] for x,y in v: b[x - 1].append(y - 1) b[y - 1].append(x - 1) import collections from ...
N, M = list(map(int, input().split())) es = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) es[a-1].append(b-1) es[b-1].append(a-1) def dfs(v, used, cnt): used[v] = 1 if all(used): cnt.append(1) for nv in es[v]: if used[nv]: ...
p03805
def multival(): return list(map(int,input().split())) def data(N=1): return [list(map(int,input().split())) for _ in range(N)] mod = 10**9 + 7 inf = float("inf") N,M = multival() nemat = [[0]*N for _ in range(N)] ans = 0 for _ in range(M): a,b = multival() a -= 1; b-= 1 nemat[a][b] = 1 nema...
N,M = list(map(int,input().split())) ad = [[0]*N for _ in range(N)] for _ in range(M): a,b = list(map(int,input().split())) a -= 1; b -= 1 ad[a][b] = 1 ad[b][a] = 1 ans = 0 def dfs(v=0,d=0,visited=[1]+[0]*(N-1)): if d == N-1: global ans ans += 1 return fo...
p03805
N,M = list(map(int, input().split())) edge= [[] for i in range(N+1)] for i in range(M): a,b = list(map(int, input().split())) edge[a].append(b) edge[b].append(a) result = [] import copy def dfs(n,used,d): if d == N-1: result.append(1) for e in edge[n]: if used[e] == F...
N,M = list(map(int, input().split())) edge= [[] for i in range(N+1)] for i in range(M): a,b = list(map(int, input().split())) edge[a].append(b) edge[b].append(a) import itertools per = itertools.permutations([i for i in range(1,N+1)]) ans = 0 for item in per: if item[0] != 1: contin...
p03805
N, M = list(map(int, input().split())) graph ={i+1:[] for i in range(N)} for _ in range(M): a, b = list(map(int, input().split())) graph[a].append(b) graph[b].append(a) def dfs(path, n, cnt): if(len(path) == N): return cnt+1 for j in graph[n]: if(j in path): ...
N, M = list(map(int, input().split())) dict = {i+1:[] for i in range(N)} for _ in range(M): a, b = list(map(int, input().split())) dict[a].append(b) dict[b].append(a) def DFS(visited, sight, cnt): if(len(visited) == N): return cnt+1 for num in dict[sight]: if num in v...
p03805
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log ...
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log ...
p02538
import sys sys.setrecursionlimit(10**7) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,Q = MI() mod = 998244353 power = [1] # power[i] = 10**i for i in range(N): power.append((power[-1]*10) % mod) t = pow(9,mod-2,mod) # 9 の逆数 class LazySegTree(): # モノイドに対して適用可能、Nが2冪でなくても...
import sys sys.setrecursionlimit(10**7) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,Q = MI() mod = 998244353 power = [1] # power[i] = 10**i for i in range(N): power.append((power[-1]*10) % mod) t = pow(9,mod-2,mod) # 9 の逆数 class LazySegTree(): # モノイドに対して適用可能、Nが2冪でなくても...
p02538
MOD = 998244353 class LazySegmentTree: # from https://atcoder.jp/contests/practice2/submissions/16598122 __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_op...
MOD = 998244353 class LazySegmentTree: # from https://atcoder.jp/contests/practice2/submissions/16598122 __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_op...
p02538
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 998244353 def set_depth(depth): global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE DEPTH = depth SEGTREE_SIZE = 1 << DEPTH NONLEAF_SIZE = 1 << (DEPTH - 1) def set_width(width): ...
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 998244353 def set_depth(depth): global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE DEPTH = depth SEGTREE_SIZE = 1 << DEPTH NONLEAF_SIZE = 1 << (DEPTH - 1) def set_width(width): ...
p02538
""" Generalized Lazy Segment Tree - Range set, Rande minimum - Range add, Range sum - Rande add, Range minimum - Rande set, Rande sum - Range Affine, Range sum - Range nagate of 0/1 sequence, Range calculation of inversion(TENTOUSUU) """ def set_depth(depth): global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE...
""" Lazy Segment Tree: value_binop takes right node size """ def set_depth(depth): global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE DEPTH = depth SEGTREE_SIZE = 1 << DEPTH NONLEAF_SIZE = 1 << (DEPTH - 1) def set_width(width): set_depth((width - 1).bit_length() + 1) def get_size(pos): ...
p02538
import sys def input(): return sys.stdin.readline().rstrip() # SegmentTree class SegmentTree: def __init__(self, n, p, unit, f, g, h): num = 2**((n-1).bit_length()) seg = [unit]*(num*2) self.lazy = [None]*(num*2) for i in range(n): seg[num+i] = p[i] for i in range(num-1, 0, -1)...
import sys def input(): return sys.stdin.readline().rstrip() # LazySegmentTree class LazySegmentTree: # f(X, X) -> X # g(X, M) -> X # h(M, M) -> M __slots__ = ["n", "num", "seg", "x_unit", "m_unit", "f", "g", "h", "lazy"] def __init__(self, n, p, x_unit, m_unit, f, g, h): self.n = n self...
p02538
import sys def input(): return sys.stdin.readline().rstrip() # LazySegmentTree class LazySegmentTree: # f(X, X) -> X # g(X, M) -> X # h(M, M) -> M __slots__ = ["n", "seg", "x_unit", "m_unit", "f", "g", "h", "lazy"] def __init__(self, n, p, x_unit, m_unit, f, g, h): self.n = n self.seg = ...
import sys def input(): return sys.stdin.readline().rstrip() class LazySegmentTree: __slots__ = ["n", "seg", "x_unit", "m_unit", "f", "g", "h", "lazy"] def __init__(self, n, p, x_unit, m_unit, f, g, h): self.n = n self.seg = p*2 self.x_unit = x_unit self.m_unit = m_unit self.f =...
p02538
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
p02538
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
p02538
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
p02538
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
p02538
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) readline = sys.stdin.buffer.readline # readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(re...
p02538
class LazySegmentTree(): def __init__(self, n, f, g, h, ef, eh): """ :param n: 配列の要素数 :param f: 取得半群の元同士の積を定義 :param g: 更新半群の元 xh が配列上の実際の値にどのように作用するかを定義 :param h: 更新半群の元同士の積を定義 (更新半群の元を xh と表記) :param x: 配列の各要素の値。treeの葉以外は xf(x1,x2,...) """ ...
class LazySegmentTree(): def __init__(self, n, f, g, h, ef, eh): """ :param n: 配列の要素数 :param f: 取得半群の元同士の積を定義 :param g: 更新半群の元 xh が配列上の実際の値にどのように作用するかを定義 :param h: 更新半群の元同士の積を定義 (更新半群の元を xh と表記) :param x: 配列の各要素の値。treeの葉以外は xf(x1,x2,...) """ ...
p02538
class LazySegmentTree(): def __init__(self, n, f, g, h, ef, eh): """ :param n: 配列の要素数 :param f: 取得半群の元同士の積を定義 :param g: 更新半群の元 xh が配列上の実際の値にどのように作用するかを定義 :param h: 更新半群の元同士の積を定義 (更新半群の元を xh と表記) :param x: 配列の各要素の値。treeの葉以外は xf(x1,x2,...) """ ...
class LazySegmentTree(): def __init__(self, n, f, g, h, ef, eh): """ :param n: 配列の要素数 :param f: 取得半群の元同士の積を定義 :param g: 更新半群の元 xh が配列上の実際の値にどのように作用するかを定義 :param h: 更新半群の元同士の積を定義 (更新半群の元を xh と表記) :param x: 配列の各要素の値。treeの葉以外は xf(x1,x2,...) """ ...
p02538
class LazySegmentTree(): def __init__(self, n, f, g, h, ef, eh): """ :param n: 配列の要素数 :param f: 取得半群の元同士の積を定義 :param g: 更新半群の元 xh が配列上の実際の値にどのように作用するかを定義 :param h: 更新半群の元同士の積を定義 (更新半群の元を xh と表記) :param x: 配列の各要素の値。treeの葉以外は xf(x1,x2,...) """ ...
class LazySegmentTree(): def __init__(self, n, f, g, h, ef, eh): """ :param n: 配列の要素数 :param f: 取得半群の元同士の積を定義 :param g: 更新半群の元 xh が配列上の実際の値にどのように作用するかを定義 :param h: 更新半群の元同士の積を定義 (更新半群の元を xh と表記) :param x: 配列の各要素の値。treeの葉以外は xf(x1,x2,...) """ ...
p02538
class LazySegTree: def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n-1).bit_length() self.size = 1 << self.log ...
import sys input = sys.stdin.readline INF = 10**18 class LazySegTree: def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n-1)....
p02538
# 方針 https://betrue12.hateblo.jp/entry/2020/09/27/013719 # ライブラリ https://github.com/not522/ac-library-python/blob/master/atcoder/lazysegtree.py import typing class LazySegTree: def __init__( self, op: typing.Callable[[typing.Any, typing.Any], typing.Any], e: typing.Any...
# 方針 https://betrue12.hateblo.jp/entry/2020/09/27/013719 # ライブラリ https://github.com/not522/ac-library-python/blob/master/atcoder/lazysegtree.py import typing class LazySegTree: def __init__( self, op: typing.Callable[[typing.Any, typing.Any], typing.Any], e: typing.Any...
p02538
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder__bit_code = """ def _ceil_pow2(n: int) -> int: x = 0 while (1 << x) < n: x += 1 return x def _b...
import typing def _ceil_pow2(n: int) -> int: x = 0 while (1 << x) < n: x += 1 return x class LazySegTree: def __init__( self, op: typing.Callable[[typing.Any, typing.Any], typing.Any], e: typing.Any, mapping: typing.Callable[[typin...
p02538
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") ### 遅延評価セグメント木 class LazySegmentTree: def __init__(self, n, a=None): """初期化 num : n以上の最小の2のべき乗 """ num = 1 while num<=...
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") ### 遅延評価セグメント木 class LazySegmentTree: def __init__(self, n, a=None): """初期化 num : n以上の最小の2のべき乗 """ num = 1 while num<=n:...
p02538
class lazy_segtree(): def __init__(self,V,OP,E,MAPPING,COMPOSITION,ID): self.n=len(V) self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] self.lz=[ID for i in range(self.size)] self.e=E self.op=OP self...
class lazy_segtree(): def __init__(self,V,OP,E,MAPPING,COMPOSITION,ID): self.n=len(V) self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] self.lz=[ID for i in range(self.size)] self.e=E self.op=OP self...
p02538
import sys sys.setrecursionlimit(10**7) mod = 998244353 INF = float("inf") class lazySegTree(object): def __init__(self, N): self.N = N self.LV = (N-1).bit_length() self.N0 = 2**self.LV self.data = [0]*(2*self.N0) #桁の値を管理(lazy*size) self.lazy = [0]*(2*self.N0) #桁の文字を管理 self.size = [1]*(2*sel...
import sys sys.setrecursionlimit(10**7) input = sys.stdin.buffer.readline mod = 998244353 INF = float("inf") class lazySegTree(object): def __init__(self, N): self.N = N self.LV = (N-1).bit_length() self.N0 = 2**self.LV self.data = [0]*(2*self.N0) #桁の値を管理(lazy*size) self.lazy = [0]*(2*self.N0)...
p02538
from typing import Callable, List, TypeVar S = TypeVar("S") # 作用付きモノイドの型 F = TypeVar("F") # 写像の型 class LazySegmentTree: """ Lazy Segment Tree from https://atcoder.jp/contests/practice2/submissions/16775176 References: https://tumoiyorozu.github.io/single-file-ac-library/document_ja/la...
from typing import Callable, List, TypeVar S = TypeVar("S") # 作用付きモノイドの型 F = TypeVar("F") # 写像の型 class LazySegmentTree: """ Lazy Segment Tree from https://atcoder.jp/contests/practice2/submissions/16775176 References: https://tumoiyorozu.github.io/single-file-ac-library/document_ja/la...
p02538
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log self.data = [(e,e)] * (2 * self...
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log self.data = [(e,e)] * (2 * self...
p02538
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log self.data = [e] * (2 * self.siz...
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log self.data = [e] * (2 * self.siz...
p02538
import sys input = sys.stdin.readline N,Q=list(map(int,input().split())) mod=998244353 seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 seg_height=1+N.bit_length() # Segment treeの高さ SEG=[0 for i in range(2*seg_el)] # 区間の和 LAZY=[0 for i in range(2*seg_el)] POW10=[pow(10,i,mod) for i in range(N+1)] gyak...
import sys input = sys.stdin.readline N,Q=list(map(int,input().split())) mod=998244353 seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 seg_height=1+N.bit_length() # Segment treeの高さ SEG=[0 for i in range(2*seg_el)] # 区間の和 LAZY=[0 for i in range(2*seg_el)] POW10=[1] for i in range(N+1): POW10.appe...
p02538
import typing def _ceil_pow2(n: int) -> int: x = 0 while (1 << x) < n: x += 1 return x def _bsf(n: int) -> int: x = 0 while n % 2 == 0: x += 1 n //= 2 return x class LazySegTree: def __init__( self, op: typing.Callabl...
import typing def _ceil_pow2(n: int) -> int: x = 0 while (1 << x) < n: x += 1 return x def _bsf(n: int) -> int: x = 0 while n % 2 == 0: x += 1 n //= 2 return x class LazySegTree: def __init__( self, op: typing.Callabl...
p02538
import typing def _ceil_pow2(n: int) -> int: x = 0 while (1 << x) < n: x += 1 return x def _bsf(n: int) -> int: x = 0 while n % 2 == 0: x += 1 n //= 2 return x class LazySegTree: def __init__( self, op: typing.Callabl...
def _ceil_pow2(n: int) -> int: x = 0 while (1 << x) < n: x += 1 return x def _bsf(n: int) -> int: x = 0 while n % 2 == 0: x += 1 n //= 2 return x class LazySegTree: def __init__( self, op, e, ...
p02538
import sys input = sys.stdin.buffer.readline class LazySegmentTree: def __init__(self, n, unitX, unitA, X_f, A_f, XA_map): self.n = n self.unitX = unitX self.unitA = unitA self.X_f = X_f # (X, X) -> X self.A_f = A_f # (A, A) -> A self.XA_map = XA_map #...
import sys input = sys.stdin.buffer.readline class LazySegmentTree: def __init__(self, n, unitX, unitA, X_f, A_f, XA_map): self.n = n self.unitX = unitX self.unitA = unitA self.X_f = X_f # (X, X) -> X self.A_f = A_f # (A, A) -> A self.XA_map = XA_map #...
p02538
N, Q, *LRD = [int(_) for _ in open(0).read().split()] L, R, D = LRD[::3], LRD[1::3], LRD[2::3] mod = 998244353 class LazySegmentTree: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_...
N, Q, *LRD = [int(_) for _ in open(0).read().split()] L, R, D = LRD[::3], LRD[1::3], LRD[2::3] mod = 998244353 class LazySegmentTree: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_...
p02538
N, Q, *LRD = [int(_) for _ in open(0).read().split()] L, R, D = LRD[::3], LRD[1::3], LRD[2::3] mod = 998244353 class LazySegmentTree(): def __init__(self, array, f, g, h, ti, ei): """ Parameters ---------- array : list to construct segment tree from ...
N, Q, *LRD = [int(_) for _ in open(0).read().split()] L, R, D = LRD[::3], LRD[1::3], LRD[2::3] mod = 998244353 class LazySegmentTree(): def __init__(self, array, f, g, h, ti, ei): """ Parameters ---------- array : list to construct segment tree from ...
p02538
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import typing import sys def main(N, Q, LRD): tree = LazySegTree( op=lambda x, y: (x[0] * y[1] + y[0], x[1] * y[1]), e=(Mint(0), Mint(1)), mapping=lambda f, s: s if f == 0 else ((s[1] - 1) // 9 * f, s[1]), composition=lambda f, g...
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import typing import sys MOD = 998244353 def main(N, Q, LRD): inv9 = pow(9, MOD - 2, MOD) tree = LazySegTree( op=lambda x, y: (((x[0] * y[1]) % MOD + y[0]) % MOD, (x[1] * y[1]) % MOD), e=(0, 1), mapping=lambda f, s: s if f == 0 else...
p02538
mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline def op(a, b, seg_len): return (a * pow(10, seg_len, mod) + b)%mod e = 0 inv9 = pow(9, mod - 2, mod) def mapping(a, x, seg_len): return ((x * inv9)%mod * (pow(10, seg_len, mod...
mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline beki10 = [0] * ((1 << 19) + 1) beki10[0] = 1 for i in range(20): beki10[1 << i] = pow(10, (1 << i), mod) def op(a, b, seg_len): return (a * beki10[seg_len] + b)%mod e = ...
p02538
MOD = 998244353 #####ide_ele##### ide_ele = [0, 0] ################# #####segfunc##### def segfunc(x, y): xa, xb = x ya, yb = y return [(xa + ya) % MOD, (xb + yb) % MOD] ################# #####triv_act##### triv_act = 0 ################# #####action##### def action(x, p): if p != ...
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log self.data = [(e,e)] * (2 * self...
p02538
import sys input = sys.stdin.readline class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length...
import sys input = sys.stdin.readline class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length...
p02538
def main(): k = eval(input()) n = [ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 ] print((n[int(k) - 1])) main()
def main(): X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = int(eval(input())) return X[K - 1] print((main()))
p02741
def mi():return list(map(int,input().split())) l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k=int(eval(input())) print((l[k-1]))
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print((l[int(eval(input()))-1]))
p02741
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = int(eval(input())) print((A[k - 1]))
print(([1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51][int(eval(input()))-1]))
p02741
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print((l[int(eval(input()))-1]))
#!/usr/bin/env python3 print(([0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(eval(input()))]))
p02741
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = int(eval(input())) print((A[k-1]))
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = int(eval(input())) print((A[K-1]))
p02741
print((ord(' 3   '[int(eval(input()))%14])))
print((b' 3   '[int(eval(input()))%14]))
p02741
print((b' 3   '[int(eval(input()))%14]))
print(ord(' 3   '[eval(input())%14]))
p02741
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = int(eval(input())) print((A[K-1]))
K = int(eval(input())) a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print((a[K-1]))
p02741
def main(): A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = int(eval(input())) print((A[K-1])) if __name__ == "__main__": main()
def main(): num = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = int(eval(input())) print((num[K-1])) if __name__ == "__main__": main()
p02741
n = int(eval(input())) x = [] y = [] h = [] for i in range(n): xi,yi,hi = list(map(int, input().split())) x.append(xi) y.append(yi) h.append(hi) cxyl = [] for i in range(101): for j in range(101): cxyl.append((i,j)) cxy = set(cxyl) hd = {} hzero = [] for i in range(n): ...
n = int(eval(input())) x = [] y = [] h = [] for i in range(n): xi,yi,hi = list(map(int, input().split())) x.append(xi) y.append(yi) h.append(hi) cxyl = [] for i in range(101): for j in range(101): cxyl.append((i,j)) cxy = set(cxyl) hd = {} hzero = set([]) for i in range(n...
p03240
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float ...
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float ...
p03240
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float ...
import sys n, *xyh = map(int, sys.stdin.read().split()) xyh = list(zip(*[iter(xyh)] * 3)) def conflict(cx, cy, ch, x, y, h): return h != max(ch - abs(x - cx) - abs(y - cy), 0) def main(): for x, y, h in xyh: if h >= 1: xt, yt, ht = x, y, h break for cx i...
p03240
def main(): N = int(input()) xyh = [[int(i) for i in input().split()] for _ in range(N)] sx, sy, sh = [(x, y, h) for x, y, h in xyh if h != 0][0] for cx in range(101): for cy in range(101): H = sh + abs(sx - cx) + abs(sy - cy) if all(max(H-abs(x - cx)-abs(y - cy), ...
def main(): import sys input = sys.stdin.buffer.readline N = int(input()) XYH = [[int(i) for i in input().split()] for j in range(N)] XYH.sort(reverse=True, key=lambda p: p[2]) for cy in range(101): for cx in range(101): ch = XYH[0][2] + abs(XYH[0][0] - cx) + abs(XY...
p03240
ri = lambda: int(input()) rl = lambda: list(map(int,input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print('YES') if b else print('NO') INF = 10**18 N=ri() xyh=[] for i in range(N): xyh += [rl()] xyh.sort(reverse=True, key=lambda x:x[2]) ans=[-1]*3 for x in range(101): if...
ri = lambda: int(input()) rl = lambda: list(map(int,input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print('YES') if b else print('NO') INF = 10**18 N=ri() X=[0]*N Y=[0]*N H=[0]*N for i in range(N): X[i],Y[i],H[i]=rl() xyh=list(zip(X,Y,H)) xyh.sort(reverse=True,key=lambda x:x[2...
p03240
n = int(eval(input())) P = [0] * n for i in range(n): P[i] = list(map(int, input().split())) P = sorted(P, key=lambda x: x[2], reverse=True) max_h = P[0][2] P2 = set() for i in range(101): for j in range(101): P2.add((i, j)) for hh in range(max_h+200, max_h-1, -1): P3 = P2.copy() ...
import sys n = int(eval(input())) P = [0] * n for i in range(n): P[i] = list(map(int, input().split())) P = sorted(P, key=lambda x: x[2], reverse=True) max_h = P[0][2] for hh in range(max_h+200, max_h-1, -1): for cx in range(101): for cy in range(101): for x, y, h in P: ...
p03240
import itertools n = int(input()) x, y, h = [], [], [] for _ in range(n): xi, yi, hi = map(int, input().split()) if hi != 0: x.append(xi) y.append(yi) h.append(hi) candidate_cx = list(range(min(x), max(x) + 1)) candidate_cy = list(range(min(y), max(y) + 1)) candidate_ch = li...
import itertools n = int(input()) x, y, h = [], [], [] for _ in range(n): xi, yi, hi = map(int, input().split()) if hi != 0: x.append(xi) y.append(yi) h.append(hi) candidate_cx = list(range(min(x), max(x) + 1)) candidate_cy = list(range(min(y), max(y) + 1)) for cx, cy in l...
p03240
import itertools n = int(input()) x, y, h = [], [], [] for _ in range(n): xi, yi, hi = map(int, input().split()) if hi != 0: x.append(xi) y.append(yi) h.append(hi) candidate_cx = list(range(min(x), max(x) + 1)) candidate_cy = list(range(min(y), max(y) + 1)) for cx, cy in l...
import itertools n = int(input()) x, y, h = [], [], [] for _ in range(n): xi, yi, hi = map(int, input().split()) if hi != 0: x.append(xi) y.append(yi) h.append(hi) candidate_cx = list(range(min(x), max(x) + 1)) candidate_cy = list(range(min(y), max(y) + 1)) for cx, cy in l...
p03240
N = int(eval(input())) points = [None] * N for i in range(0, N): points[i] = list(map(int, input().split())) h_max = max([h for x, y, h in points]) for H in range(h_max + 100, h_max - 1, -1): for Cx in range(101): for Cy in range(101): ok = True for X, Y, h1 in poi...
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] h_max = max(h for x, y, h in points) for H in range(h_max, h_max + 1000): for Cx in range(101): for Cy in range(101): ok = True for x, y, h in points: h_calc = max(H - abs(...
p03240
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] h_max = max(h for x, y, h in points) for H in range(h_max, h_max + 1000): for Cx in range(101): for Cy in range(101): ok = True for x, y, h in points: h_calc = max(H - abs(...
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] points.sort(key=lambda x: x[2], reverse=True) for Cx in range(101): for Cy in range(101): kouho = set() for xi, yi, hi in points: if len(kouho) > 1: break # 頂点が一意でない ...
p03240
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] points.sort(key=lambda x: x[2], reverse=True) for Cx in range(101): for Cy in range(101): kouho = set() for xi, yi, hi in points: if len(kouho) > 1: break # 頂点が一意でない ...
N = int(eval(input())) points = [[int(s) for s in input().split()] for i in range(N)] points.sort(key=lambda x: x[2], reverse=True) for Cx in range(101): for Cy in range(101): H = None for xi, yi, hi in points: dx = abs(xi - Cx) dy = abs(yi - Cy) if hi ...
p03240
N = int(eval(input())) XYH = [list(map(int, input().split())) for _ in range(N)] H_max = max([XYH[i][2] for i in range(N)]) ans = [] # 高さH,中心座標を(Cx, Cy)として総当たりで試す for H in range(H_max - 200, H_max + 201): for Cx in range(0, 101): for Cy in range(0, 101): count = 0 for X,...
N = int(eval(input())) XYH = [list(map(int, input().split())) for _ in range(N)] H_list= [XYH[i][2] for i in range(N)] H_max = max(H_list) H_min = min(H_list) H_diff = H_max - H_min ans = [] # 高さH,中心座標を(Cx, Cy)として総当たりで試す for H in range(H_max - (200 - H_diff), H_max + (201 - H_diff)): for Cx in range(0, 1...
p03240
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) def solve(): for x in range(101): for y in range(101): for h in range(h_min, h_min + 201): for i in range(N): if D[i][0] != max(h - abs(D[i][1] - x) - abs(D[...
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) def solve(): for cx in range(101): for cy in range(101): ch = D[0][0] + abs(D[0][1] - cx) + abs(D[0][2] - cy) for h, x, y in D: if h != max(ch - (abs(x - cx) + abs(y...
p03240
from math import * from itertools import * import sys N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx, cy in product(list(range(101)), list(range(101))): flag = 1 H = h + a...
from math import * import sys N = int(eval(input())) all_input_list = [[int(j) for j in input().split()] for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx in range(101): for cy in range(101): flag = 1 H = h + abs(cx - x) + abs(cy - y) ...
p03240
from math import * import sys N = int(eval(input())) all_input_list = [[int(j) for j in input().split()] for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx in range(101): for cy in range(101): flag = 1 H = h + abs(cx - x) + abs(cy - y) ...
from math import * import sys N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_l...
p03240
from math import * N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_list in all_i...
from math import * import sys N = int(eval(input())) all_input_list = [list(map(int, input().split())) for i in range(N)] x, y, h = sorted(all_input_list, key=lambda x: x[2])[-1] for cx in range(101): for cy in range(101): H = h + abs(cx - x) + abs(cy - y) for input_list in all_input_list:...
p03240
import sys n = int(eval(input())) xyh = [] for i in range(n): xyh.append(list(map(int, input().split()))) for cx in range(0, 101): for cy in range(0, 101): for H in range(max(1, xyh[0][2] - 201), max(2, xyh[0][2] + 201)): is_valid = True for...
import sys n = int(eval(input())) xyh = [] for i in range(n): xyh.append(list(map(int, input().split()))) if xyh[-1][2] >= 1: G = xyh[-1] for cx in range(0, 101): for cy in range(0, 101): hs = [] x, y, h = G H = h + abs(x - cx) + abs(y - cy) H = max(...
p03240
N = int(eval(input())) Xs = [list(map(int, input().split(" "))) for _ in range(N)] """ input = ["2 3 5","2 1 5","1 2 5","3 2 5"] input = ["0 0 100", "1 1 98"] input = ["99 1 191", "100 1 192", "99 0 192"] Xs = [list(map(int, x.split(" "))) for x in input] """ Xs.sort(key=lambda x:x[2], reverse=True) def ...
N = int(eval(input())) Xs = [list(map(int, input().split(" "))) for _ in range(N)] """ input = ["2 3 5","2 1 5","1 2 5","3 2 5"] input = ["0 0 100", "1 1 98"] input = ["99 1 191", "100 1 192", "99 0 192"] Xs = [list(map(int, x.split(" "))) for x in input] """ Xs.sort(key=lambda x:x[2], reverse=True) def ...
p03240
N=int(eval(input())) xyh=[list(map(int, input().split())) for _ in range(N)] maxh = max([h for _,_,h in xyh]) def find(cx, cy, H): for x,y,h in xyh: if h != max(H-abs(x-cx)-abs(y-cy), 0): return False return True def all(): for cx in range(101): for cy in range(101): for H in range(min(1, ma...
N=int(eval(input())) xyh=sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2], reverse=True) def find(cx, cy, H): for x,y,h in xyh: if h != max(H-abs(x-cx)-abs(y-cy), 0): return False return True def solve(): for cx in range(101): for cy in range(101): x,y,h = xyh[0]...
p03240
def c_pyramid(N, Pos): from itertools import product # 中心座標を全探索 for cx, cy in product(list(range(101)), repeat=2): # ピラミッドの高さを求める for x, y, h in Pos: if h > 0: height = h + abs(cx - x) + abs(cy - y) # ピラミッドの高さが得られた情報に適合するか調べる for x, y, h i...
def c_pyramid(): N = int(eval(input())) Pos = [[int(i) for i in input().split()] for j in range(N)] # 与えられた情報から頂点座標を一意に得られるので、h=0にならない x, y, h = sorted(Pos, key=lambda x: x[2])[-1] # 中心座標を全探索 for cx in range(101): for cy in range(101): # 頂点の高さ height を決めたとき、すべての座標の情報と...
p03240
# -*- 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 import resource 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_re...
p02852
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): _, m = list(map(int, input().split())) traps = [v == '1' for v in input().strip()] values = [None] * len(traps) values[0] = -1 for i in range(len(values) - 1): if values[i] is None: continue for j in range(i + m, i, -1):...
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): _, m = list(map(int, input().split())) traps = [v == '1' for v in input().strip()] values = [None] * len(traps) values[0] = -1 for i in range(len(values) - 1): if values[i] is None: continue for j in range(min(i + m, len...
p02852
import sys sys.setrecursionlimit(1000000000) from itertools import count from functools import lru_cache from collections import defaultdict ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) INF = float('inf') def meg(f, ok, ng): while abs(ok-ng)>1: mid ...
import sys sys.setrecursionlimit(1000000000) from itertools import count from functools import lru_cache from collections import defaultdict ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) INF = float('inf') def meg(f, ok, ng): while abs(ok-ng)>1: mid ...
p02852
# -*- coding: utf-8 -*- import sys N,M=list(map(int, sys.stdin.readline().split())) S=sys.stdin.readline().strip() L=[] #答えの集合 for _ in range(N): for m in range(M,0,-1): if 0<=N-m and S[N-m]=="0": L.append(m) N-=m break else: break ...
# -*- coding: utf-8 -*- import sys N,M=list(map(int, sys.stdin.readline().split())) S=sys.stdin.readline().strip() L=[] #答えの配列の逆順 for _ in range(N): for m in range(M,0,-1): if 0<=N-m and S[N-m]=="0": L.append(m) N-=m break else: break ...
p02852
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time #import random def I(): return int(input()) def MI(): return map(int,input().s...
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time #import random def I(): return int(input()) def MI(): return map(int,input().s...
p02852
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_():return input() de...
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_():return input() de...
p02852
from collections import deque INF = 10**18 def append_dq(i, x, dq, dp1): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > dp1[lxi]: dq.append(i) break dq.pop() return dq dq = deque() N,M = list(map(...
from collections import deque INF = 10**18 def append_dq(i, x, dq, dp1): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > dp1[lxi]: dq.append(i) break dq.pop() return dq dq = deque() N,M = list(map(...
p02852
from collections import deque INF = 10**18 def append_dq(i, x, dq, dp1): while True: if not len(dq): dq.append(i) break lxi = dq[-1] if x > dp1[lxi]: dq.append(i) break dq.pop() return dq dq = deque() N,M = list(map(...
N,M=map(int,input().split()) S,r,s=input(),[],N for _ in range(2*N): if S[s]=='1': s += 1 else: r.append(str(N-s)) N,s=s,max(0,s-M) if N == 0: break print(*[-1] if s else r[1:][::-1])
p02852
#!/usr/bin/env python3 import sys INF = float("inf") def solve(N: int, M: int, S: str): # 最短手数を求める DP = [INF]*(N+1) DP[0] = 0 for i in range(1, N+1): if S[i] == "1": continue for j in range(1, M+1): if i-j < 0: break ...
#!/usr/bin/env python3 import sys INF = float("inf") def solve(N: int, M: int, S: str): S = S[::-1] data = [0]*(N+1) past = 0 for i in range(N+1): if S[i] == "1": data[i] = past else: past = i ans = [] curr = 0 while True: ...
p02852