output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s683975820 | Runtime Error | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | from copy import deepcopy
N, M = [int(a) for a in input().split()]
all_list = [[], []] * N
for i in range(N + M - 1):
a, b = [int(a) for a in input().split()]
all_list[b - 1][0].append(a)
all_list[b - 1][1].append(a)
if len(all_list[b - 1][0]) > 1:
dummy_parent = deepcopy(all_list[b - 1][0])
for parent in dummy_parent:
for other_parent in all_list[b - 1][0]:
if other_parent in all_list[b - 1][1]:
all_list[b - 1][0].remove(other_parent)
for dup in all_list:
if a in dup[0] and b in dup[0]:
dup[0].remove(a)
for i in range(N):
print(str(all_list[i][0][0]))
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s522879482 | Wrong Answer | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
def comb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def bisearch(L, target):
low = 0
high = len(L) - 1
while low <= high:
mid = (low + high) // 2
guess = L[mid]
if guess == target:
return True
elif guess < target:
low = mid + 1
elif guess > target:
high = mid - 1
if guess != target:
return False
# --------------------------------------------
dp = None
def sigma_(a, b, n):
return (a + b) * n // 2
def main():
N, M = li_input()
V = [li_input() for _ in range(N + M - 1)]
# print("N,M", N, M)
# print("V", V)
Link = [[] for _ in range(N + 1)]
iLink = [[] for _ in range(N + 1)]
for v in V:
sv, se = v
Link[sv].append(se)
iLink[se].append(sv)
# 根を求める
distV = []
for v in V:
distV.append(v[1])
distV = list(set(distV))
root = sigma_(1, N, N) - sum(distV)
# print("root", root)
A = [0] * N
Layer = [[root]]
parent_nodes = [root]
i = 1
while len(Layer[i - 1]) != 0:
Layer.append([])
new_parent_nodes = []
for parent_node in parent_nodes:
for l in Link[parent_node]:
Layer[i].append(l)
parent_nodes = Layer[i]
i += 1
Layer = Layer[:-1]
for i in range(len(Layer)):
Layer[i] = list(set(Layer[i]))
# print("Layer", Layer)
X = [[False] * (N + 1) for _ in range(len(Layer))]
for i, L in enumerate(Layer):
for l in L:
X[i][l] = True
print(1)
# i = len(Layer) - 1
# while i >= 0:
# # print(Layer)
# L = Layer[i]
# for l in L:
# maybe_parents = iLink[l]
# for maybe_parent in maybe_parents:
# if X[i-1][maybe_parent]:
# A[l-1] = maybe_parent
# j = i - 1
# while j >= 0:
# Layer[j] = list(filter(lambda a:a != l, Layer[j]))
# j -= 1
# break
# i -= 1
# for a in A:
# print(a)
main()
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s152454538 | Wrong Answer | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | class Graph:
def __init__(self, n_vertices, edges, directed=True):
self.n_vertices = n_vertices
self.edges = edges
self.directed = directed
@property
def adj(self):
try:
return self._adj
except AttributeError:
adj = [[] for _ in range(self.n_vertices)]
if self.directed:
for u, v in self.edges:
adj[u].append(v)
else:
for u, v in self.edges:
adj[u].append(v)
adj[v].append(u)
self._adj = adj
return adj
max2 = lambda x, y: x if x > y else y
min2 = lambda x, y: x if x < y else y
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
def solve(N, edges):
adj = Graph(N, edges, directed=True).adj
parent = [-1] * N
# find root
candidates = [True] * N
for a, b in edges:
candidates[b] = False
root = next(v for v, f in enumerate(candidates) if f)
q = [root]
while q:
nq = []
for v in q:
for u in adj[v]:
if parent[u] != v:
parent[u] = v
nq.append(u)
q = nq
return (p + 1 for p in parent)
if __name__ == "__main__":
N, M = map(int, readline().split())
m = map(lambda x: int(x) - 1, read().split())
edges = list(zip(m, m))
print(*solve(N, edges), sep="\n")
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s227821105 | Runtime Error | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | from bisect import bisect_left
from collections import deque
N, M = map(int, input().split())
AB = []
for _ in range(N - 1 + M):
a, b = map(int, input().split())
AB.append((a, b))
AB.sort(key=lambda x: x[0])
BA = sorted(AB, key=lambda x: x[1])
AB_A = [a for a, b in AB]
BA_B = [b for a, b in BA]
# find root
root = 1
while True:
i = bisect_left(BA_B, root)
if BA_B[i] != root:
break
root = BA[i][0]
t_nl = [0] * (N + 1)
# t_ln = [0] * (N + M + 1)
t_ln = [0] * (100010)
isdup_n = [True] * (N + 1)
par_n = [0] * (N + 1)
q = deque()
q.append((root, 0))
l = 1
while len(q):
n, p = q.popleft()
t_nl[n] = l
t_ln[l] = n
if par_n[n] == 0:
par_n[n] = p
else:
par_n[n] = par_n[n] if t_nl[par_n[n]] > t_nl[p] else p
l += 1
# continue
i = bisect_left(AB_A, n)
while i < len(AB_A) and AB_A[i] == n:
q.append((AB[i][1], n))
i += 1
l += 1
for v in par_n[1:]:
print(v)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s933769374 | Runtime Error | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | #!/usr/bin/env python3
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
A, B = (int(x) - 1 for x in input().split())
g[A].append(B)
rg[B].append(A)
def dfs(s):
global ts
global used
used[s] = True
for t in g[s]:
if not used[t]:
dfs(t)
ts.append(s)
def tsort():
global ts
for i in range(N):
dfs(i)
ts = ts[::-1]
used = [False] * N
ts = []
tsort()
mp = [None] * N
for i, x in enumerate(ts):
mp[x] = i
ans = [0] * N
for t in ts[1:]:
if rg[t]:
ans[t] = ts[max(mp[s] for s in rg[t])] + 1
for x in ans:
print(x)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s509679695 | Wrong Answer | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n + m - 1):
a, b = map(int, input().split())
g[a - 1].append(b)
for i in range(n):
if len(g[i]) == 0:
r = i
ans = [0] * n
q = [i]
while len(q) > 0:
u = q.pop()
for v in g[u]:
ans[v - 1] = u + 1
q.append(v - 1)
for i in ans:
print(i)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s355235252 | Wrong Answer | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | n, m = map(int, input().split())
G = []
C = [[] for i in range(n)]
B = [[] for i in range(n)]
for s in range(n + m - 1):
a, b = map(int, input().split())
C[b - 1].append(a)
B[a - 1].append(b)
root = C.index([]) + 1
S = [None for i in range(n)]
A = []
S[root - 1] = 0
now = root
N = [now]
NextN = []
while N != []:
for r in range(len(N)):
# print("N:",N)
now = N.pop(0)
if len(B[now - 1]) > 0:
for q in B[now - 1]:
S[q - 1] = now
NextN.extend(B[now - 1])
B[now - 1] = []
# print("S:",S)
N.extend(NextN)
NextN = []
"""
now=N.pop(0)
A.append(now)
for e in B[now-1]:
C[e-1].remove(now)
if C[e-1] == []:
N.append(e)
"""
for ans in S:
print(ans)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s941831819 | Accepted | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | import sys
def I():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LMI():
return list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
INF = float("inf")
# トポロジカルソート
# deg[i] := 頂点iの入次数
# returns := トポロジカルソートされた頂点番号のリスト
def tsort(deg, nl):
tsorted = list()
stack = [i for i, x in enumerate(deg) if x == 0]
while len(stack) > 0:
v = stack.pop()
tsorted.append(v)
for next_v in nl[v]:
deg[next_v] -= 1
if deg[next_v] == 0:
stack.append(next_v)
return tsorted
N, M = MI()
nl = [list() for _ in range(N)]
deg = [0 for _ in range(N)]
for _ in range(N - 1 + M):
A, B = MI()
A, B = A - 1, B - 1
nl[A].append(B)
deg[B] += 1
tsorted = tsort(deg, nl)
ans = [0] * N
p = {tsorted[0]: -1}
for v in tsorted:
ans[v] = p[v]
for next_v in nl[v]:
p[next_v] = v
for a in ans:
print(a + 1)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s812967210 | Accepted | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | n, m = (int(i) for i in input().split())
x, y = [[] for i in range(n + 1)], [0] * (n + 1)
y[0] = 1
for i in range(n + m - 1):
a, b = (int(i) for i in input().split())
x[a].append(b)
y[b] += 1
ans, q = [0] * (n + 1), [y.index(0)]
while q:
p = q.pop()
for i in x[p]:
y[i] -= 1
if not y[i]:
q.append(i)
ans[i] = p
for i in ans[1:]:
print(i)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s548864753 | Wrong Answer | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | n, m = map(int, input().split())
s = [[] for i in range(n + 1)]
l = [list(map(int, input().split())) for i in range(n + m - 1)]
for i in range(n + m - 1):
s[l[i][1]].append(l[i][0])
lis = [0 for _ in range(n)]
for i in range(1, n + 1):
lis[i - 1] = len(s[i])
# print(s,lis)
for i in range(1, n + 1):
if lis[i - 1] == 0:
print("0")
elif lis[i - 1] == 1:
print(s[i][0])
else:
ans = 0
cnt = 0
for j in range(lis[i - 1]):
a = lis[s[i][j] - 1]
# print(j,a)
if cnt < a:
ans = s[i][j]
cnt = a
print(ans)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print N lines. In the i-th line, print `0` if Vertex i is the root of the
original tree, and otherwise print the integer representing the parent of
Vertex i in the original tree.
Note that it can be shown that the original tree is uniquely determined.
* * * | s213018781 | Accepted | p03142 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M} | from collections import deque
class Graph: # directed
def __init__(self, n, edge, indexed=1):
self.n = n
self.graph = [[] for _ in range(n)]
self.rev = [[] for _ in range(n)]
self.deg = [0 for _ in range(n)]
for e in edge:
self.graph[e[0] - indexed].append(e[1] - indexed)
self.rev[e[1] - indexed].append(e[0] - indexed)
self.deg[e[1] - indexed] += 1
def topological_sort(self):
deg = self.deg[:]
res = [i for i in range(self.n) if deg[i] == 0]
queue = deque(res)
used = [False for _ in range(self.n)]
while queue:
node = queue.popleft()
for adj in self.graph[node]:
deg[adj] -= 1
if deg[adj] == 0:
queue.append(adj)
res.append(adj)
return res
N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(N + M - 1)]
g = Graph(N, E)
ts = g.topological_sort()
node_to_ts = [0 for _ in range(N)]
for i in range(N):
node_to_ts[ts[i]] = i
for i in range(N):
tmp = -1
res = -1
for j in g.rev[i]:
if tmp < node_to_ts[j]:
tmp = node_to_ts[j]
res = j
print(res + 1)
| Statement
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex 1.
Takahashi has added M new directed edges to this graph. Each of these M edges,
u \rightarrow v, extends from some vertex u to its descendant v.
You are given the directed graph with N vertices and N-1+M edges after
Takahashi added edges. More specifically, you are given N-1+M pairs of
integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
i-th edge extends from Vertex A_i to Vertex B_i.
Restore the original rooted tree. | [{"input": "3 1\n 1 2\n 1 3\n 2 3", "output": "0\n 1\n 2\n \n\nThe graph in this input is shown below:\n\n\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n 2 1\n 2 3\n 4 1\n 4 2\n 6 1\n 2 6\n 4 6\n 6 5", "output": "6\n 4\n 2\n 0\n 6\n 2"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s424759517 | Runtime Error | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
A = list(map(int, input().split()))
a = 0
if N % 2 == 1:
a = max(A)
A.remove(a)
b = max(A)
A.remove(b)
c = 0
ans = [[A[0], b]]
com = A[0] - b
c += com
for i in range(1, (N // 2) * 2 - 2):
ans.append(c, [A[i]])
com = c - A[i]
c += com
print(a - c)
print(ans[0][0], ans[0][1])
for j in range((N // 2) * 2 - 2):
print(ans[j][0], ans[j][1])
if N % 2 == 1:
print(a, c)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s332019816 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | n = int(input())
a = [int(x) for x in input().split()]
s = min(a)
a.remove(s)
X, Y = [], []
while len(a) > 1:
ai = a.pop()
X.append(s), Y.append(ai)
s -= ai
ai = a.pop()
X.append(ai), Y.append(s)
print(ai - s)
for x, y in zip(X, Y):
print(x, y)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s855017457 | Accepted | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
pos, neg, zero = [], [], []
for Ai in A:
if Ai > 0:
pos.append(Ai)
elif Ai < 0:
neg.append(Ai)
else:
zero.append(0)
if len(neg) == 0:
neg += zero
else:
pos += zero
ope = []
if len(pos) > 0 and len(neg) > 0:
now1 = pos[0]
for i in range(1, len(neg)):
ope.append((now1, neg[i]))
now1 -= neg[i]
now2 = neg[0]
for i in range(1, len(pos)):
ope.append((now2, pos[i]))
now2 -= pos[i]
ope.append((now1, now2))
M = now1 - now2
elif len(pos) == 0:
neg.sort(reverse=True)
now = neg[0]
for i in range(1, len(neg)):
ope.append((now, neg[i]))
now -= neg[i]
M = now
else:
pos.sort()
now = pos[0]
for i in range(1, len(pos) - 1):
ope.append((now, pos[i]))
now -= pos[i]
ope.append((pos[-1], now))
M = pos[-1] - now
print(M)
for x, y in ope:
print(x, y)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s178069981 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | # 12:17
n = int(input())
a = list(map(int, input().split()))
plus = []
minus = []
for i in range(n):
if a[i] >= 0:
plus.append(a[i])
else:
minus.append(a[i])
plus.sort()
minus.sort(reverse=True)
lp = len(plus)
lm = len(minus)
if lp >= 1 and lm >= 1:
ans = sum(plus) - sum(minus)
print(ans)
x = minus[0]
lp = len(plus)
for i in range(1, lp):
print(x, plus[i])
x = x - plus[i]
minus[0] = x
x = plus[0]
for j in range(lm):
print(x, minus[j])
x = x - minus[j]
elif lp == 0:
ans = -sum(minus) + 2 * max(minus)
print(ans)
x = minus[1]
for j in range(2, lm):
print(x, minus[j])
x = x - minus[j]
print(minus[0], x)
elif lm == 0:
ans = sum(plus) - 2 * min(plus)
print(ans)
x = plus[0]
for i in range(2, lp):
print(x, plus[i])
x = x - plus[i]
print(plus[1], x)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s196032153 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | input()
y = list(map(int, input().split()))
s = min(y)
y.remove(s)
print(sum(y) - s)
x = y.pop()
for i in y:
print(str(s) + " " + str(i))
s = s - i
print(str(x) + " " + str(s))
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s209641920 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | # -*- coding: utf-8 -*-
# input
s = input()
t = input()
ls = len(s)
lt = len(t)
ans = 0
# calc
for i in range(ls, lt - 1, -1):
temp = s[i - lt : i]
# print(temp)
counter = 0
for j in range(lt - 1, -1, -1):
if t[j] == temp[j] or temp[j] == "?":
counter += 1
# print(j)
# print(temp[j])
if counter == lt:
ans = i
break
# output
if ans == 0:
print("UNRESTORABLE")
else:
print((s[: ans - lt] + t + s[ans:]).replace("?", "a"))
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s865178984 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | m = int(input())
a = sorted(list(map(int, input().split())))
s, p = a[: len(a) // 2], a[len(a) // 2 :]
print(sum(p) - sum(s))
if len(p) > len(s):
c = p.pop(0)
s, p = p, s
else:
c = s.pop(0)
while len(p) > 0:
b = p.pop(0)
print(b, c)
c = b - c
s, p = p, s
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s730462417 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | import heapq
from collections import defaultdict
N = int(input())
nums = list(map(int, input().split(" ")))
Xs = []
Ys = []
S = defaultdict(lambda: 0)
途中式 = []
for num in nums:
heapq.heappush(Xs, -num)
heapq.heappush(Ys, num)
S[num] += 1
for _ in range(N - 2):
while True:
X = heapq.heappop(Xs)
X = -X
if S[X] > 0:
S[X] -= 1
break
while True:
Y = heapq.heappop(Ys)
if S[Y] > 0:
S[Y] -= 1
break
途中式.append((Y, X))
temp = Y - X
S[temp] += 1
heapq.heappush(Xs, -temp)
heapq.heappush(Ys, temp)
anss = []
for k, v in S.items():
if v > 0:
anss.append(k)
Y = max(anss)
X = min(anss)
ans1 = Y - X
途中式.append((Y, X))
Xs = []
Ys = []
S = defaultdict(lambda: 0)
途中式2 = []
for num in nums:
heapq.heappush(Xs, -num)
heapq.heappush(Ys, num)
S[num] += 1
for _ in range(N - 2):
while True:
X = heapq.heappop(Xs)
X = -X
if S[X] > 0:
S[X] -= 1
break
while True:
Y = heapq.heappop(Ys)
if S[Y] > 0:
S[Y] -= 1
break
途中式2.append((X, Y))
temp = X - Y
S[temp] += 1
heapq.heappush(Xs, -temp)
heapq.heappush(Ys, temp)
anss = []
for k, v in S.items():
if v > 0:
anss.append(k)
Y = min(anss)
X = max(anss)
ans2 = X - Y
途中式2.append((X, Y))
if ans1 < ans2:
途中式 = 途中式2
ans1 = ans2
print(ans1)
for temp in 途中式:
Y, X = temp
print(Y, X)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s213053604 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | n = int(input())
a = list(map(int, input().split()))
plus = 0
for i in range(n):
plus += 2 * int(a[i] > 0) - 1
score = 0
for i in range(n):
score += abs(a[i])
if plus != n:
print(score)
else:
print(score - 2 * abs(a[0]))
a.sort()
if plus >= 0:
for k in range(plus):
print(a[0], a[-1])
a[0] -= a[-1]
del a[-1]
half = (n - plus) // 2
if half != 0:
for k in range(half - 1):
print(a[k], a[-1])
a[k] -= a[-1]
del a[-1]
for k in range(half):
print(a[-1], a[0])
a[-1] -= a[0]
del a[0]
else:
plus *= -1
for k in range(plus):
print(a[-1], a[0])
a[-1] -= a[0]
del a[0]
half = (n - plus) // 2
if half != 0:
for k in range(half - 1):
print(a[k], a[-1])
a[k] -= a[-1]
del a[-1]
for k in range(half):
print(a[-1], a[0])
a[-1] -= a[0]
del a[0]
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s904074499 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | a = int(input())
b = list(map(int, input().split()))
d = []
for i in range(a - 1):
if i < a - 3:
p, q = min(b), max(b)
b.remove(p)
b.remove(q)
d.append([p, q])
c = p - q
b.append(c)
else:
p, q = max(b), min(b)
d.append([p, q])
c = p - q
b.append(c)
print(max(b))
for j in range(len(d)):
print(d[j][0], d[j][1])
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s826582586 | Runtime Error | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
a = list(map(int, input().split()))
p = [t for t in a if t >= 0]
m = [t for t in a if t < 0]
p.sort(reverse=True)
m.sort()
l = []
# print(a)
if len(p) == 0:
u = m.pop()
v = m.pop()
l.append((u, v))
p.append(u - v)
if len(m) == 0 and len(p) >= 2:
u = p.pop()
v = p.pop()
l.append((u, v))
m.append(u - v)
while len(p) >= 2:
u = m.pop()
v = p.pop()
l.append((u, v))
m.append(u - v)
while len(m):
t = p[0]
u = m.pop()
l.append((t, u))
p[0] = t - u
print(p[0])
for res in l:
print(*res)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s211399849 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | n = int(input())
a = [int(i) for i in input().split()]
a, x = sorted(a), []
print(sum(a[n // 2 :]) - sum(a[: n // 2]))
if n % 2:
for i in range(n // 2):
print(a[i], a[i + n // 2])
x.append(a[i] - a[i + n // 2])
num = a[-1]
for i in range(len(x)):
print(num, x[i])
num -= x[i]
else:
for i in range(n // 2 - 1):
print(a[i], a[i + n // 2])
x.append(a[i] - a[i + n // 2])
print(a[-1], a[n // 2 - 1])
num = a[-1] - a[n // 2 - 1]
for i in range(len(x)):
print(num, x[i])
num -= x[i]
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s087839351 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | # -*- coding: utf-8 -*-
# input
n = int(input())
a = list(map(int, input().split()))
# calc
ap = [i for i in a if i > 0]
am = [i for i in a if i < 0]
a0 = [i for i in a if i == 0]
ans = 0
t = 0
t2 = 0
lap = len(ap)
lam = len(am)
la0 = len(a0)
if lap > 0 and lam > 0:
ans = sum(ap) + abs(sum(am))
print(ans)
for i in range(la0):
print(am[0], 0)
if lam == 1 and lap > 1:
print(am[0], ap[0])
t = am[0] - ap[0]
for i in range(1, lap - 1):
print(t, ap[i])
t -= ap[i]
print(ap[lap - 1], t)
elif lam > 1 and lap == 1:
print(ap[0], am[0])
t = ap[0] - am[0]
for i in range(1, lam):
print(t, am[i])
t -= am[i]
elif lam == 1 and lap == 1:
print(ap[0], am[0])
else:
t = am[0]
t2 = ap[0]
for i in range(1, lap):
print(t, ap[i])
t -= ap[i]
for i in range(1, lam):
print(t2, am[i])
t2 -= am[i]
print(t2, t)
elif lap == 0 and lam > 1:
am.sort()
for i in range(lam - 1):
t += am[i]
ans = t * (-1) + am[lam - 1]
print(ans)
for i in range(la0):
print(am[0], 0)
t2 = am[lam - 1]
for i in range(lam - 1):
print(t2, am[i])
t2 -= am[i]
elif lap > 1 and lam == 0:
ap.sort()
for i in range(1, lap):
t += ap[i]
ans = t - ap[0]
print(ans)
for i in range(la0):
print(ap[0], 0)
t2 = ap[0]
for i in range(1, lap - 1):
print(t2, ap[i])
t2 -= ap[i]
print(ap[lap - 1], t2)
elif lap == 1 and lam == 0:
print(ap[0])
for i in range(la0):
print(ap[0], 0)
elif lap == 0 and lam == 1:
print(abs(am[0]))
for i in range(la0 - 1):
print(0, 0)
print(0, am[0])
elif lap == 0 and lam == 0:
print(0)
for i in range(la0 - 1):
print(0, 0)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s791586349 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | n = int(input())
v = list(map(int, input().split()))
v.sort()
h = n // 2
print(sum(v[h:]) - sum(v[:h]))
s = 0
for i in range(n):
if i % 2 == n % 2:
x = v[i // 2]
else:
x = v[i // 2 + h]
if i:
print(x, s)
s = x - s
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s830299233 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | n = int(input())
a = list(map(int, input().split()))
a.sort()
s = [0 for i in range(n)]
ans = -1e9
pos = 0
flag = True
s[0] = a[0]
for i in range(n):
s[i] = s[i - 1] + a[i]
for i in range(n):
if i == 0:
if ans < s[n - 1] - s[i] - a[i]:
pos = i
flag = False
ans = s[n - 1] - s[i] - a[i]
if ans < -(s[n - 1] - s[i]) + a[i]:
pos = i
flag = True
ans = -(s[n - 1] - s[i]) + a[i]
else:
if ans < s[i - 1] + s[n - 1] - s[i] - a[i]:
pos = i
flag = False
ans = s[i - 1] + s[n - 1] - s[i] - a[i]
if ans < -s[i - 1] - (s[n - 1] - s[i]) + a[i]:
pos = i
flag = True
ans = -s[i - 1] - (s[n - 1] - s[i]) + a[i]
print(ans)
cur = a[pos]
a.remove(cur)
if flag:
for i in range(n - 1):
print(cur, a[i])
cur = cur - a[i]
else:
for i in range(n - 2):
print(cur, a[i])
cur = cur - a[i]
print(a[n - 2], cur)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s155520235 | Accepted | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | import numpy as np
N = int(input())
poss, negs = [], []
npos, nneg = 0, 0
for a in input().split():
ia = int(a)
if ia < 0:
negs.append(ia)
nneg += 1
else:
poss.append(ia)
npos += 1
# import random
# N = 100000
# npos, nneg = 40000, 60000
# poss = [random.randint(1, 1000) for _ in range(npos)]
# negs = [random.randint(-1000, -1) for _ in range(nneg)]
#
# poss = []
# negs = [-1, -1, -1]
# npos, nneg = len(poss), len(negs)
# N = npos + nneg
if N == 2:
a1, a2 = poss + negs
if a1 < a2:
print(a2 - a1)
print(a2, a1)
else:
print(a1 - a2)
print(a1, a2)
exit(0)
if nneg == 0:
print(sum(poss) - min(poss) * 2)
argmin = np.array(poss).argmin()
minpos = poss.pop(argmin)
pos = poss.pop()
print(minpos, pos)
negs.append(minpos - pos)
npos -= 2
nneg += 1
elif npos == 0:
print(-sum(negs) + max(negs) * 2)
argmax = np.array(negs).argmax()
maxneg = negs.pop(argmax) # -1とか
neg = negs.pop() # -5とか
print(maxneg, neg)
poss.append(maxneg - neg)
nneg -= 2
npos += 1
else:
print(sum(poss) - sum(negs))
if npos > nneg:
for _ in range(npos - nneg):
pos, neg = poss.pop(), negs.pop()
print(neg, pos)
negs.append(neg - pos)
elif npos < nneg:
for _ in range(nneg - npos):
pos, neg = poss.pop(), negs.pop()
print(pos, neg)
poss.append(pos - neg)
for i in range(min(nneg, npos) - 1):
pos, neg = poss.pop(), negs.pop()
print(neg, pos)
negs.append(neg - pos)
pos, neg = poss.pop(), negs.pop()
print(pos, neg)
poss.append(pos - neg)
pos, neg = poss.pop(), negs.pop()
print(pos, neg)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s002988188 | Accepted | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | def getN():
return int(input())
def getMN():
return list(map(int, input().split()))
def getlist():
return list(map(int, input().split()))
import sys
n = getN()
nums = getlist()
nums.sort()
from bisect import bisect_left
insert = bisect_left(nums, 0)
if insert == 0:
print(sum(nums) - 2 * nums[0])
tmp = nums[0]
for num in nums[1:-1]:
print(tmp, num)
tmp = tmp - num
print(nums[-1], tmp)
sys.exit()
if insert == len(nums):
nums.sort(reverse=True)
print(abs(sum(nums)) + 2 * nums[0])
tmp = nums[0]
for num in nums[1:]:
print(tmp, num)
tmp = tmp - num
sys.exit()
neg = nums[:insert]
pos = nums[insert:]
neg_end = neg[0]
pos_end = pos[-1]
print(abs(sum(neg)) + sum(pos))
for ne in neg[1:]:
print(pos_end, ne)
pos_end -= ne
for po in pos[:-1]:
print(neg_end, po)
neg_end -= po
print(pos_end, neg_end)
"""
5
8 9 -2 -3 10
"""
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s304281198 | Accepted | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
AA = list(map(int, input().split())) # 0を含む可能性あり
A = []
count = 0
for i in range(N):
if AA[i] != 0:
A.append(AA[i])
else:
count += 1
NN = N - count
B = [abs(A[i]) for i in range(NN)]
if count == 0:
det = 1
s = A[0] // B[0] # 最初のやつの符号
for i in range(1, NN):
if s * A[i] < 0:
det = -1
break
if det == 1: # 全て同符号
m = min(B)
M = sum(B) - 2 * m
print(M)
for i in range(NN):
if m == B[i]:
p = i
break
C = [A[i] // B[i] for i in range(NN)]
C[p] *= -1
else: # 異符号が含まれる
M = sum(B)
print(M)
C = [A[i] // B[i] for i in range(NN)]
fp = -1 # firstplus
fm = -1 # firstminus
for i in range(NN):
if fp == -1 and C[i] == 1:
fp = i
elif fm == -1 and C[i] == -1:
fm = i
elif fp != -1 and fm != -1:
break
X = []
Y = []
for i in range(NN):
if i == fp or i == fm:
continue
if C[i] == -1:
X.append(i)
else:
Y.append(i)
x = A[fp]
for i in X:
print(x, A[i])
x -= A[i]
y = A[fm]
for i in Y:
print(y, A[i])
y -= A[i]
print(x, y)
elif A == []:
print(0)
for i in range(count - 1):
print(0, 0)
else:
det = 1
s = A[0] // B[0] # 最初のやつの符号
for i in range(1, NN):
if s * A[i] < 0:
det = -1
break
M = sum(B)
print(M)
if det == 1: # 全て同符号
# これがまずい
if s < 0:
for i in range(count - 1):
print(0, 0)
x = 0
for i in range(NN):
print(x, A[i])
x -= A[i]
else:
for i in range(count - 1):
print(0, 0)
x = 0
for i in range(NN - 1):
print(x, A[i])
x -= A[i]
print(A[NN - 1], x)
else: # 異符号が含まれる
# こちらは今まで通り処理して最後に0を引きまくれば良い
C = [A[i] // B[i] for i in range(NN)]
fp = -1 # firstplus
fm = -1 # firstminus
for i in range(NN):
if fp == -1 and C[i] == 1:
fp = i
elif fm == -1 and C[i] == -1:
fm = i
elif fp != -1 and fm != -1:
break
X = []
Y = []
for i in range(NN):
if i == fp or i == fm:
continue
if C[i] == -1:
X.append(i)
else:
Y.append(i)
x = A[fp]
for i in X:
print(x, A[i])
x -= A[i]
y = A[fm]
for i in Y:
print(y, A[i])
y -= A[i]
print(x, y)
for i in range(count):
print(x - y, 0)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s180322497 | Accepted | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | ###template###
import sys
def input():
return sys.stdin.readline().rstrip()
def mi():
return map(int, input().split())
###template###
N = int(input())
As = list(mi())
TL = [[], [], []]
# [0] : zeroList
# [1] : minusList
# [2] : plusList
for a in As:
if a == 0:
TL[0].append(a)
elif a < 0:
TL[1].append(a)
else:
TL[2].append(a)
# print(TL)
ans = 0
printlist = []
# 全てxxの場合(3パターン)
if len(TL[0]) == N: # 全てゼロの場合
print(0)
for i in range(N - 1):
print(0, 0)
exit()
elif len(TL[1]) == N: # 全てminusの場合
TL[1] = sorted(TL[1], reverse=True) # 降順に並べる(-値の低いものから)
printlist.append((TL[1][0], TL[1][1])) # 痛みを最小に
hand = TL[1][0] - TL[1][1] # これでプラスになった
idx = 2
while idx < N:
printlist.append((hand, TL[1][idx]))
hand -= TL[1][idx]
idx += 1
ans = hand
# 答えを出力する
print(ans)
for x, y in printlist:
print(x, y)
exit()
elif len(TL[2]) == N: # 全てplusの場合
TL[2] = sorted(TL[2]) # 昇順に並べる
printlist.append((TL[2][0], TL[2][1])) # 痛みを最小に
hand = TL[2][0] - TL[2][1] # これで-になった
idx = 2
while idx < N - 1:
printlist.append((hand, TL[2][idx]))
hand -= TL[2][idx]
idx += 1
# idx==N-1
printlist.append((TL[2][idx], hand))
hand = TL[2][idx] - hand
ans = hand
# 答えを出力する
print(ans)
for x, y in printlist:
print(x, y)
exit()
# ここから先は、0,-,+のうちどれか2つはあるので、全て集合させられる
# ただし、0と-が1つずつ、0と+が1つずつというパターンは別途処理する必要がある
# 以下、そのパターンを処理
if len(TL[0]) == 1 and len(TL[1]) == 1:
# 0と-が1つずつ。0から-を引いて終わり
left, right = TL[0].pop(), TL[1].pop()
print(left - right)
print(left, right)
exit()
elif len(TL[0]) == 1 and len(TL[2]) == 1:
# 0と+が1つずつ。+から0を引いて終わり
left, right = TL[2].pop(), TL[0].pop()
print(left - right)
print(left, right)
exit()
# ここから先は、0,-,+のうちどれか2つはあり、前述のパターンも無いので、全て集合させられるし、最後に-と+が1つずつという最終処理パターンに持っていける
# よって一律のループ処理でOK
# 0が0個、+が1つ、-が1つになったら処理を抜け、最終手順に向かう
# 最初からそうなら、while文は実行されないのでOK
# また、全てを集合させられる=取り出す順番はどうでもいいので、高速化のため全てpop()で取り出していく
while not (len(TL[0]) == 0 and len(TL[1]) == 1 and len(TL[2]) == 1):
left = 0
right = 0
if len(TL[0]) >= 1:
# 0があれば、まず0を消化する
if len(TL[1]) == 0: # -がなければ、0を使って-を作る
left, right = TL[0].pop(), TL[2].pop()
printlist.append((left, right))
TL[1].append(left - right)
elif len(TL[2]) == 0: # +がなければ、0を使って+を作る
left, right = TL[0].pop(), TL[1].pop()
printlist.append((left, right))
TL[2].append(left - right)
else: # -も+もあるなら消化するだけなので、どっちでもいいが、-で消化する
left, right = TL[1].pop(), TL[0].pop()
printlist.append((left, right))
TL[1].append(left - right)
continue
# ここからは、0がなくなったパターン
# 0がなくなったということは、+と-は必ず両方あることになる
# またwhile文の条件から、「どちらも1つしかない」ということはありえない
if len(TL[1]) >= len(TL[2]): # -のが多い、もしくは同じ(もちろん2:2以上)
left, right = TL[2].pop(), TL[1].pop()
printlist.append((left, right))
TL[2].append(left - right)
else: # +のが多いパターン
left, right = TL[1].pop(), TL[2].pop()
printlist.append((left, right))
TL[1].append(left - right)
# 最後に、プラス-マイナスでプラス数字を作って終わり
left, right = TL[2].pop(), TL[1].pop()
printlist.append((left, right))
ans = left - right
# 答えを出力する
print(ans)
for x, y in printlist:
print(x, y)
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s201630876 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
posA, negA = [], []
for a in list(map(int, input().split())):
if a > 0:
posA.append(a)
else:
negA.append(a)
posA.sort(reverse=True)
negA.sort()
if len(posA) > 0:
posi, negi = 1, 0
pros = []
nums = []
ans = 0
while posi < len(posA) and negi < len(negA):
ans += posA[posi] - negA[negi]
pros.append([negA[negi], posA[posi]])
nums.append(negA[negi] - posA[posi])
posi += 1
negi += 1
ans = posA[0]
prv_val = posA[0]
for num in nums:
ans -= num
pros.append([prv_val, num])
prv_val -= num
if posi < len(posA):
pos_nums = []
si = posi
ei = len(posA) - 1
while si < ei:
pos_nums.append(posA[ei] - posA[si])
pros.append([posA[ei], posA[si]])
si += 1
ei -= 1
if ei - si == 2:
ans -= posA[si + 1]
pros.append(prv_val, posA[si + 1])
prv_val -= posA[si + 1]
for pos_num in pos_nums:
ans -= pos_num
pros.append([prv_val, pos_num])
prv_val -= pos_num
else:
for a in negA[negi:]:
ans -= a
pros.append([prv_val, a])
prv_val -= a
else:
ans = negA[-1]
pros = []
prv_val = negA[-1]
for a in negA[:-1]:
ans -= a
pros.append([prv_val, a])
prv_val -= a
print(ans)
[print(*pro) for pro in pros]
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
Print the maximum possible value M of the final integer on the blackboard, and
a sequence of operations x_i, y_i that maximizes the final integer, in the
format below.
Here x_i and y_i represent the integers x and y chosen in the i-th operation,
respectively.
If there are multiple sequences of operations that maximize the final integer,
any of them will be accepted.
M
x_1 y_1
:
x_{N-1} y_{N-1}
* * * | s235957244 | Wrong Answer | p03007 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
L = list(map(int, input().split()))
L.sort()
L2 = [i * -1 for i in L[1:-1]]
L2.sort()
print(L[-1] - (L[0] + sum(L2)))
n = 0
while n <= N - 2:
s = 0
if n == 0:
print(L[0], end=" ")
print(L[1])
n = n + 1
s = L[0] - L[1]
else:
print(L[n + 1], end=" ")
print(s - L[n + 1])
s = s - L[n + 1]
n = n + 1
| Statement
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one
integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the final integer on the blackboard and a
sequence of operations that maximizes the final integer. | [{"input": "3\n 1 -1 2", "output": "4\n -1 1\n 2 -2\n \n\nIf we choose x = -1 and y = 1 in the first operation, the set of integers\nwritten on the blackboard becomes (-2, 2).\n\nThen, if we choose x = 2 and y = -2 in the second operation, the set of\nintegers written on the blackboard becomes (4).\n\nIn this case, we have 4 as the final integer. We cannot end with a greater\ninteger, so the answer is 4.\n\n* * *"}, {"input": "3\n 1 1 1", "output": "1\n 1 1\n 1 0"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s999654117 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N=int(input())
flag='Yes'
p,q,r=0,0,0
for _ in range(N):
t,x,y=map(int,input().split())
a=x+y-p-q
e=t-r
if a<=e:
if (e-a)%2!=0:
flag='No'
break
else:
flag='No'
break
p=x
q=y
r=t
print(flag)N=int(input())
flag='Yes'
p,q,r=0,0,0
for _ in range(N):
t,x,y=map(int,input().split())
a=x+y-p-q
e=t-r
if a<=e:
if (e-a)%2!=0:
flag='No'
break
else:
flag='No'
break
p=x
q=y
r=t
print(flag) | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s844505665 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
cnt = 0
sum = 0
flag = 0
T = X = Y = 0
for i in range(N):
cnt = x[i][0] - T
sum = abs(x[i][1]- X) + abs(x[i][2]- Y)
T = x[i][0]
X = x[i][1]
Y = x[i][2]
if cnt < sum or cnt % 2 != sum % 2:
flag = 1
break
if flag == 0:
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s971038302 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N, A, B = map(int, input().split())
print(sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B))
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s413634907 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n=int(input())
for i in range(n):
x_start=0
y_start=0
t_start=0
t,x,y=map(int,input().split())
dist=abs(t-t_start)
dt=abs(x-x_start)+abs(y-y_start)
if dist>dt or dt%2!=dist%2:
print("No")
exit()
print("Yes") | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s064910767 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | t = [0]
x = [0]
y = [0]
N = int(input())
for i in range(N):
ti,xi,yi = map(int,input(),split())
t.append(ti)
x.append(xi)
y.append(yi)
flg = True
for i in range(1,N+1):
if t[i]-t[i-1] < x[i]-x[i-1] + y[i]-y[i-1]:
flg = False
elif (t[i]-t[i-1])%2 != (x[i]-x[i-1]+y[i]-y[i-1])%2:
flg = False
if(flg):
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s134492418 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | #13 C - Traveling
N = int(input())
plan = []
for _ in range(N):
ti,xi,yi = map(int,input().split())
plan.append((ti,xi,yi))
#今いる場所の座標と時間
spot = (0,0,0)#始点
result = 'Yes'
for t,x,y in plan:
tdiff = t-spot[0]
xdiff = abs(x-spot[1])
ydiff = abs(y-spot[2])
#(x,y)の変化量の和の偶奇と時間の差の偶奇が一致している
#時間の変化量より(x,y)の変化量の方が小さい
if (tdiff%2 == (xdiff+ydiff)%2) and ((xdiff + ydiff)<=tdiff):
'''
xdiff<=tdiff and ydiff<=t だと(3,3,2)などの範囲外に対応できない
if (tdiff%2 == (xdiff+ydiff)%2) and (xdiff<=tdiff) and (ydiff<=tdiff):
'''
spot = (t,x,y)
else:
result = 'No'
break
print(result) | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s794553958 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | count = int(input())
lis = [input() for i in range(count)]
n = [-1] * count
x = [-1] * count
y = [-1] * count
for i in range(len(lis)):
n[i],x[i],y[i] = map(int,lis[i].split())
i = 0
n0 = 0
x0 = 0
y0 = 0
res = 1
for i in range(len(n)):
nt = n[i] - n0
xt = x[i] - x0
yt = y[i] - y0
if xt == 0 and yt == 0:
res= -1
break:
elif xt + yt <= nt:
if nt%2 == 0 and (xt+yt)%2 == 0:
nt = n[i]
xt = x[i]
yt = y[i]
elif nt%2 == 1 and (xt+yt)%2 == 1:
nt = n[i]
xt = x[i]
yt = y[i]
else:
res = -1
break
else:
res = -1
break
if res > 0:
print("Yes")
else:
print("No") | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s711727778 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
res = [0 for i in range(n)]
pos = [0, 0]
def serch_travel (des, pos, k, i, res):
if k == 0:
if des == pos:
res[i] = 1
else:
pos1 = [pos[0]+1, pos[1]]
pos2 = [pos[0]-1, pos[1]]
pos3 = [pos[0], pos[1]+1]
pos4 = [pos[0], pos[1]-1]
serch_travel (des, pos1, k-1, i, res)
serch_travel (des, pos2, k-1, i, res)
serch_travel (des, pos3, k-1, i, res)
serch_travel (des, pos4, k-1, i, res)
for i in range(n):
pos1 = [pos[0]+1, pos[1]]
pos2 = [pos[0]-1, pos[1]]
pos3 = [pos[0], pos[1]+1]
pos4 = [pos[0], pos[1]-1]
serch_travel (list[i][1:3], pos1, list[i][0], i, res)
serch_travel (list[i][1:3], pos2, list[i][0], i, res)
serch_travel (list[i][1:3], pos3, list[i][0], i, res)
serch_travel (list[i][1:3], pos4, list[i][0], i, res)
for i in range(n):
if(res[i] == 0):
print("No")
flag = False
break
if(flag):
print("Yes")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s482301536 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
t_state, x_state, y_state = 0, 0, 0
for i in range(n):
t, x, y = map(int, input().split())
d = abs(x - x_state) + abs(y - y_state)
td = t - t_state
if td < d or td%2 != d%2
print("No")
exit()
t_state, x_state, y_state = t, x, y
print("Yes") | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s940536065 | Accepted | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i]) * n**i for i in range(len(str(X))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
nx = ny = 0
nt = 0
for _ in range(N):
t, x, y = IL()
if abs(nx - x) + abs(ny - y) > t - nt:
NE()
if (abs(nx - x) + abs(ny - y)) % 2 != (t - nt) % 2:
NE()
nx = x
ny = y
nt = t
Y()
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s141626030 | Wrong Answer | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | import numpy as np
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s090314132 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | t = [0]
x = [0]
y = [0]
N = int(input())
for i in range(1,N+1):
ti,xi,yi = map(int,input(),split())
t.append(ti)
x.append(xi)
y.append(yi)
flg = True
for i in range(0,N):
if t[i+1]-t[i] < x[i+1]-x[i] + y[i+1]-y[i]:
flg = False
else (t[i+1]-t[i])%2 - (x[i+1]-x[i] + y[i+1]-y[i])%2==0:
flg = False
if (flg):
print('Yes')
else:
print('No') | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s452908743 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | # C
n = int(input())
preX = [0,0,0]
ans = True
for i in range(n):
curX = list(map(int, input().split()))
time =
if not curX[0] - preX[0] >= (abs(curX[1] - preX[1]) + abs(curX[2] - preX[2])) and curX[0] - preX[0] % 2 == (abs(curX[1] - preX[1]) + abs(curX[2] - preX[2])) % 2:
ans = False
if ans:
print('Yes')
else:
print('No')
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s763768402 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n=int(input())
import array from numpy
i=0
o=array([0 0 0])
while i<n
t,x,y=map(int,input().split())
z=array([t x y])
w=z-o
a,b=map(str,bin(w[1]),bin(w[2]+w[3]))
if w[1]<w[2]+w[3]:
print("No")
break
else:
if a==b:
o=o+w
i=i+1
else:
print("No")
break
else:
print("Yes")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s003970316 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | 2
5 1 1
100 1 1 | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s047754894 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n=int(input())
t=0
x=0
y=0
for i in range(n):
g,h,j=map(int,input().split())
if (g-t)%2==(abs(h-x)+abs(j-y)%2:
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s530013360 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N = int(input())
T, X, Y = 0, 0, 0
count = 0
for i in range(N):
t, x, y = map(int, input().split())
dt = t - T
dist = abs(x - X) + abs(y - Y)
if dist <= dt and t%2 == (x+y)%:
count += 1
T, X, Y = t, x, y
print('Yes' if count == N else 'No')
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s045149952 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n=int(input())
from numpy import array
i=0
o=array([0,0,0])
while i<n:
c=list(map(int,input().split()))
z=array(c)
w=z-o
a,b=map(int,[w[0],abs(w[1])+abs(w[2])])
if a<b:
print("No")
break
else:
if (a+b)%2==0:
o=z
i=i+1
else:
print("No")
break
else:
print("Yes")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s121805638 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N = int(input())
t_old, x_old, y_old = 0
for i in range(N):
t, x, y = map(int, input().split())
dt = t - t_old
dx = x - x_old
dy = y - y_old
t_old = t
x_old = x
y_old = y
if abs(dx) + abs(dy) =< dt and (dt - (abs(dx) + abs(dy))) % 2 == 0:
if i == N - 1:
print('Yes')
else:
print('No')
break
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s271248797 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N = int(input())
t_old, x_old, y_old = 0, 0, 0
for i in range(N):
t, x, y = map(int, input().split())
dt = t - t_old
dx = x - x_old
dy = y - y_old
t_old = t
x_old = x
y_old = y
if abs(dx) + abs(dy) =< dt and (dt - (abs(dx) + abs(dy))) % 2 == 0:
if i == N - 1:
print('Yes')
pass
else:
print('No')
break
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s366786365 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
m = {}
for i in range(n):
a = list(map(int, input().split()))
m[a[0]] = [a[1], a[2]]
t = 0
cood = [0,0]
fail = False
for k,v in m.items():
diff = abs(cood[0] - v[0]) + abs(cood[1] - v[1])
if (t >= diff) & ((t-diff) % 2 == 0):
cood = v
else:
fail = True
break
if fail:
print(No)
else:
print(Yes)
) | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s661354044 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
li = [list(map(int,list(input().split()))) for i in range(n)]
for i in range(len(li)):
if li[i][0] >= li[i][1] + li[i][2]:
if (li[i][0] - (li[i][1] + li[i][2]))%2 == 0:
flag = True
else:
flag = False
break
if flag == True:
print("Yes")
elif flag == False:
print("No") | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s634148109 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N = int(input())
for i in range(N+1):
t(i),x(i),y(i) = map(int,input(),split())
t(0),x(0),y(0) = 0,0,0
for i in range(0,N):
if t(i+1)-t(i) >= x(i+1)-x(i) + y(i+1)-y(i) and \
((t(i+1)-t(i))%2 - (x(i+1)-x(i) + y(i+1)-y(i))%2)==0:
continue
else:
print('No')
break
print('Yes') | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s060264868 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
res = [0 for i in range(n)]
pos = [0, 0]
flag = True
def serch_travel (des, pos, k, i, res):
if k == 0:
if des == pos:
res[i] = 1
else:
pos1 = [pos[0]+1, pos[1]]
pos2 = [pos[0]-1, pos[1]]
pos3 = [pos[0], pos[1]+1]
pos4 = [pos[0], pos[1]-1]
serch_travel (des, pos1, k-1, i, res)
serch_travel (des, pos2, k-1, i, res)
serch_travel (des, pos3, k-1, i, res)
serch_travel (des, pos4, k-1, i, res)
for i in range(n):
pos1 = [pos[0]+1, pos[1]]
pos2 = [pos[0]-1, pos[1]]
pos3 = [pos[0], pos[1]+1]
pos4 = [pos[0], pos[1]-1]
serch_travel (list[i][1:3], pos1, list[i][0], i, res)
serch_travel (list[i][1:3], pos2, list[i][0], i, res)
serch_travel (list[i][1:3], pos3, list[i][0], i, res)
serch_travel (list[i][1:3], pos4, list[i][0], i, res)
if(flag):
print("Yes")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s135154333 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | /// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
use std::fs::File;
use std::io::Read;
let mut s = String::new();
match option_env!("LOCAL") {
Some(_) => File::open("src/_in.txt")
.expect("File not found")
.read_to_string(&mut s)
.unwrap(),
None => std::io::stdin().read_to_string(&mut s).unwrap(),
};
s
}
fn main() {
let s = read_input();
let mut ws = s.split_whitespace();
let in_n: i32 = ws.next().unwrap().parse().unwrap();
let mut txy: Vec<(i32, i32, i32)> = (0..in_n)
.map(|_| {
let t: i32 = ws.next().unwrap().parse().unwrap();
let x: i32 = ws.next().unwrap().parse().unwrap();
let y: i32 = ws.next().unwrap().parse().unwrap();
(t, x, y)
})
.collect();
txy.insert(0, (0, 0, 0));
let mut ok = true;
for window in txy.windows(2) {
let ((t1, x1, y1), (t2, x2, y2)) = (window[0], window[1]);
let dt = t2 - t1;
let d = (x1 - x2).abs() + (y1 - y2).abs();
ok &= dt >= d && (dt - d) % 2 == 0
}
println!("{}", if ok { "Yes" } else { "No" });
}
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s709456478 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
res = [0 for i in range(n)]
pos = [0, 0]
def serch_travel (des, pos, k, i):
if k == 0:
if des == pos:
res[i] = 1
else:
pos1 = [pos[0]+1, pos[1]]
pos2 = [pos[0]-1, pos[1]]
pos3 = [pos[0], pos[1]+1]
pos4 = [pos[0], pos[1]-1]
serch_travel (list[i][1:3], pos1, list[i][0]-1, i)
serch_travel (list[i][1:3], pos2, list[i][0]-1, i)
serch_travel (list[i][1:3], pos3, list[i][0]-1, i)
serch_travel (list[i][1:3], pos4, list[i][0]-1, i)
for i in range(n):
pos1 = [pos[0]+1, pos[1]]
pos2 = [pos[0]-1, pos[1]]
pos3 = [pos[0], pos[1]+1]
pos4 = [pos[0], pos[1]-1]
serch_travel (list[i][1:3], pos1, list[i][0], i)
serch_travel (list[i][1:3], pos2, list[i][0], i)
serch_travel (list[i][1:3], pos3, list[i][0], i)
serch_travel (list[i][1:3], pos4, list[i][0], i)
for i in range(n):
if(res[i] == 1):
print("No")
flag = False
break
if(flag):
print("Yes")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s417449337 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | time = int(input())
jorney = [list(map(int,input().split())) for i in range(time)]
flg = True
x_before = 0
y_bfefore =0
t_before = 0
for point in jorney:
time = point[0]
x = point[1]
y = point[2]
distance = x- x_before + y - y_bfefore
interval = time - time_before
if time %2 == (x+y)%2 and interval = distance:
time_before=time
x_before=x
y_bfefore=y
continue
else:
flg=False
break
if flg:
print("YES")
else:
print("NO") | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s712740384 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | N=int(input())
T=[]
X=[]
Y=[]
for i in range(N):
t,x,y=map(int, input().split())
T.append(t)
X.append(x)
Y.append(y)
flag=0
for i in range(N):
if i==0:
if T[i]<X[i]+Y[i] or (X[i]!=0 and Y[i]!=0 and T[i]%(X[i]+Y[i])!=0):
flag=1
break
if (X[i]==Y[i]==0 and T[i]%2!=0) or (((X[i]==1 and Y[i]==0) or (X[i]==0 and Y[i]==1)) and T[i]%2!=1):
flag=1
break
else:
if T[i]-T[i-1]<(X[i]-X[i-1])+(Y[i]-Y[i-1]) or (X[i]-X[i-1]!=0 and Y[i]-Y[i-1]!=0 and T[i]-T[i-1]%((X[i]-X[i-1])+(Y[i]-Y[i-1]))!=0):
flag=1
break
if (X[i]-X[i-1]==Y[i]-Y[i-1]==0 and T[i]%2!=0) or (((X[i]-X[i-1]==1 and Y[i]-Y[i-1]==0) or (X[i]-X[i-1]==0 and Y[i]-Y[i-1]==1)) and T[i]-T[i-1]%2!=1):
flag=1
break
if flag==0:
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s125677453 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | num = int(input())
if num == 1:
t = 1
x = 0
y = 0
else:
t,x,y = map(int,input().split())
if num == 1:
num = num + 1
for _ in range(num - 1):
t1, x1, y1 = map(int, input().split())
if abs(t - t1) < abs(x - x1):
print('No')
elif abs(t - t1) < abs(y - y1):
print('No')
elif abs(t - t1) % 2 == 1:
if x == x1 and y == y1:
print('No')
t = t1
x = x1
y = y1
print('Yes') | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s710405712 | Runtime Error | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | def main():
size = int(input())
for i in range(size):
array[i] = list(map(int, input().split())
flg = "Yes"
pre_time = 0
pos = [0, 0]
for i in range (size):
time = array[i][0] - pre_time
distance = abs(array[i][1]-pos[0]) + abs(array[i][2]-pos[1])
if time == distance or ((distance<time) and (time-distance)%2 == 0):
pre_time = array[i][0]
pos = array[i][1:]
else:
flg = "No"
print(flg)
main() | Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s975421029 | Wrong Answer | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | num = int(input())
check = 0
step_b = 0
x_b = 0
y_b = 0
for i in range(num):
step, x, y = map(int, input().split())
if ((x - x_b) + (y - y_b) - (step - step_b) > 0) or (
((x - x_b) + (y - y_b) - (step - step_b)) % 2 == 1
):
check = 1
break
print(((x - x_b) + (y - y_b) - (step - step_b)))
x_b = x
y_b = y
step_b = step
if check == 0:
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s389648969 | Accepted | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | def LI():
return [int(x) for x in input().split(" ")]
def LS():
return [str(x) for x in input().split(" ")]
def ItoS(L):
return [str(x) for x in L]
def StoI(L):
return [int(c) for c in L]
def solve():
while 1:
try:
n = int(input())
T, X, Y = [], [], []
for _ in range(n):
tmp1, tmp2, tmp3 = LI()
T.append(tmp1)
X.append(tmp2)
Y.append(tmp3)
T.insert(0, 0)
X.insert(0, 0)
Y.insert(0, 0)
for i in range(n):
if X[i + 1] == X[i] and Y[i + 1] == Y[i]:
raise EndLoop
time = T[i + 1] - T[i]
dis = abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i])
if not ((time == dis) or (time > dis and (time - dis) % 2 == 0)):
raise EndLoop
print("Yes")
break
except:
print("No")
break
solve()
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s978912162 | Accepted | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | n = int(input())
d_inp = [input() for i in range(n)]
can = False
d = []
for i in range(n):
d.append(list(map(int, d_inp[i].split())))
ct = 0
cx = 0
cy = 0
for i in range(n):
dt = d[i][0] - ct
dx = d[i][1] - cx
dy = d[i][2] - cy
if dx + dy > dt:
break
if (dx + dy) % 2 != dt % 2:
break
ct += dt
cx += dx
cy += dy
else:
can = True
if can == True:
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
If AtCoDeer can carry out his plan, print `Yes`; if he cannot, print `No`.
* * * | s216405979 | Wrong Answer | p03457 | Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N | (
lambda ft: print(
ft.reduce(
lambda p, c: (lambda t, d: (d > t or d % 2 != t % 2) and [-1, -1, -1] or c)(
c[0] - p[0], abs(c[1] - p[1]) + abs(c[2] - p[2])
),
[list(map(int, input().split())) for _ in range(int(input()))],
[0, 0, 0],
)[0]
< 0
and "No"
or "Yes"
)
)(__import__("functools"))
| Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan,
he will depart from point (0, 0) at time 0, then for each i between 1 and N
(inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following
points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he
cannot stay at his place**. Determine whether he can carry out his plan. | [{"input": "2\n 3 1 2\n 6 1 1", "output": "Yes\n \n\nFor example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1),\n(1,0), then (1,1).\n\n* * *"}, {"input": "1\n 2 100 100", "output": "No\n \n\nIt is impossible to be at (100,100) two seconds after being at (0,0).\n\n* * *"}, {"input": "2\n 5 1 1\n 100 1 1", "output": "No"}] |
Print the maximum product modulo (10^9+7), using an integer between 0 and
10^9+6 (inclusive).
* * * | s846924905 | Wrong Answer | p02616 | Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N | # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
MOD = 10**9 + 7
def main(N, K, A):
negative = sorted([a for a in A if a < 0])
neg = len(negative)
zero = [a for a in A if a == 0]
positive = sorted([a for a in A if a > 0])
pos = len(positive)
if N - K < len(zero):
return 0
N -= len(zero)
A = sorted([a for a in A if a != 0], key=lambda x: abs(x))
ans = Mint(1)
if ((neg & (~1)) + pos < K) or (neg & 1 and K == N) or (pos == 0 and K & 1):
# マイナスになっちゃう
for i in range(K):
ans *= abs(A[i])
ans = -ans
else:
# プラスにできる
A.reverse()
neg_cnt = 0
last_pos = 0
last_cnt = 0
for i in range(K):
ans *= abs(A[i])
if A[i] < 0:
neg_cnt += 1
if neg_cnt & 1 == 0:
last_pos = ans.value
last_cnt = i + 1
remain = K - last_cnt
if remain == 1:
for i in range(last_cnt, N):
if A[i] > 0:
ans = Mint(last_pos * A[i])
break
elif remain != 0:
pospos = 1
negneg = 1
pos_rem = remain
neg_rem = remain
for i in range(last_cnt, N):
if A[i] > 0 and pos_rem > 0:
pospos *= A[i]
pos_rem -= 1
if A[i] < 0 and neg_rem > 0:
negneg *= abs(A[i])
neg_rem -= 1
if pos_rem == neg_rem == 0:
break
pospos = pospos if pos_rem == 0 else 1
negneg = negneg if neg_rem == 0 else 1
ans = Mint(last_pos * max(pospos, negneg))
return ans
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0:
self.value += MOD
@staticmethod
def get_value(x):
return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0:
u += MOD
return u
def __repr__(self):
return str(self.value)
def __eq__(self, other):
return self.value == other.value
def __neg__(self):
return Mint(-self.value)
def __hash__(self):
return hash(self.value)
def __bool__(self):
return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0:
self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
if __name__ == "__main__":
input = sys.stdin.readline
N, K = map(int, input().split())
(*A,) = map(int, input().split())
print(main(N, K, A))
| Statement
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product
of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0
and 10^9+6 (inclusive). | [{"input": "4 2\n 1 2 -3 -4", "output": "12\n \n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and\n12, so the maximum product is 12.\n\n* * *"}, {"input": "4 3\n -1 -2 -3 -4", "output": "1000000001\n \n\nThe possible products of the three chosen elements are -24, -12, -8, and -6,\nso the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\n* * *"}, {"input": "2 1\n -1 1000000000", "output": "1000000000\n \n\nThe possible products of the one chosen element are -1 and 1000000000, so the\nmaximum product is 1000000000.\n\n* * *"}, {"input": "10 10\n 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1", "output": "999983200\n \n\nBe sure to print the product modulo (10^9+7)."}] |
Print the maximum product modulo (10^9+7), using an integer between 0 and
10^9+6 (inclusive).
* * * | s875132663 | Runtime Error | p02616 | Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N | n, k = map(int, input().split())
ps = []
ns = []
zs = 0
for a in map(int, input().split()):
if a > 0:
ps.append(a)
elif a < 0:
ns.append(a)
else:
zs += 1
def product(l):
t = 1
for li in l:
t *= li
return t
def p(x):
print(x % (10**9 + 7))
if len(ps) + len(ns) == 0:
print(0)
elif len(ps) == 0:
if k % 2 == 0:
ns.sort()
else:
ns.sort(reverse=True)
p(product(ns[:k]))
elif len(ns) == 0:
ps.sort(reverse=True)
p(product(ps[:k]))
else:
ma = 0
l = ps + ns
pn = []
for i in range(len(l)):
pn.append(l[i] > 0)
l[i] = abs(l[i])
tmp = sorted(list(zip(*[l, pn])), key=lambda x: x[0], reverse=True)
l = list(map(lambda x: x[0], tmp))
pn = list(map(lambda x: x[1], tmp))
if len([pni for pni in pn[:k] if not pni]) % 2 == 0:
p(product(l[:k]))
else:
i = len(pn) - 1 - pn[::-1].index(False)
j = pn.index(True, k)
l = l[:k] + l[j]
l.pop(i)
p(product(l[:k]))
| Statement
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product
of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0
and 10^9+6 (inclusive). | [{"input": "4 2\n 1 2 -3 -4", "output": "12\n \n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and\n12, so the maximum product is 12.\n\n* * *"}, {"input": "4 3\n -1 -2 -3 -4", "output": "1000000001\n \n\nThe possible products of the three chosen elements are -24, -12, -8, and -6,\nso the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\n* * *"}, {"input": "2 1\n -1 1000000000", "output": "1000000000\n \n\nThe possible products of the one chosen element are -1 and 1000000000, so the\nmaximum product is 1000000000.\n\n* * *"}, {"input": "10 10\n 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1", "output": "999983200\n \n\nBe sure to print the product modulo (10^9+7)."}] |
Print the maximum product modulo (10^9+7), using an integer between 0 and
10^9+6 (inclusive).
* * * | s563542469 | Runtime Error | p02616 | Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N | # 関数リスト
import sys
input = sys.stdin.readline
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(map(int, input().split()))
n, k = MI()
mylist = LI()
plus = [i for i in mylist if i >= 0]
plus.sort(reverse=True)
minus = [i for i in mylist if i < 0]
minus.sort()
mod = 10e9 + 7
index = k
result = 1
while index > 0:
if index == 1:
if len(plus) != 0:
result *= plus[0]
plus = plus[1:]
index -= 1
else:
result *= minus[-1]
index -= 1
else:
if len(plus) == 0:
if index % 2 == 0:
for i in range(index):
result *= minus[i]
index = 0
else:
index2 = len(minus)
for i in range(index):
result *= minus[index2 - 1 - i]
index = 0
elif len(plus) == 1:
if len(minus) >= 2:
if minus[0] * minus[1] > plus[1]:
result *= minus[0] * minus[1]
index -= 2
minus = minus[2:]
else:
result *= plus[0]
plus = []
index -= 1
else:
result *= plus[0] * minus[0]
index -= 2
else:
if len(minus) <= 1:
result *= plus[0]
plus = plus[1:]
index -= 1
else:
if minus[0] * minus[1] > plus[0] * plus[1]:
result *= minus[0] * minus[1]
index -= 2
minus = minus[2:]
else:
result *= plus[0]
index -= 1
plus = plus[1:]
print(int(result % mod))
| Statement
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product
of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0
and 10^9+6 (inclusive). | [{"input": "4 2\n 1 2 -3 -4", "output": "12\n \n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and\n12, so the maximum product is 12.\n\n* * *"}, {"input": "4 3\n -1 -2 -3 -4", "output": "1000000001\n \n\nThe possible products of the three chosen elements are -24, -12, -8, and -6,\nso the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\n* * *"}, {"input": "2 1\n -1 1000000000", "output": "1000000000\n \n\nThe possible products of the one chosen element are -1 and 1000000000, so the\nmaximum product is 1000000000.\n\n* * *"}, {"input": "10 10\n 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1", "output": "999983200\n \n\nBe sure to print the product modulo (10^9+7)."}] |
Print the maximum product modulo (10^9+7), using an integer between 0 and
10^9+6 (inclusive).
* * * | s160430419 | Wrong Answer | p02616 | Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N | MOD = 10**9 + 7
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
A_pos = [a for a in As if a >= 0]
A_pos.sort()
A_pos.reverse()
A_neg = [a for a in As if a < 0]
A_neg.sort()
ans = 1
pos_used = 0
neg_used = 0
pos_total = len(A_pos)
neg_total = len(A_neg)
# 答えが負になるかチェック
if pos_total < K and (K - pos_total) % 2 == 1:
# 小さい方から取る
A_pos.reverse()
A_neg.reverse()
k = K
# 二つずつペアで見てゆく
while (pos_used + neg_used) < K:
# Kが1
if K == 1:
if N == 1:
if pos_total == 1:
ans = (ans * A_pos[0]) % MOD
else:
ans = (ans * A_neg[0]) % MOD
else:
if pos_total > 0:
ans = (ans * A_pos[0]) % MOD
else:
ans = (ans * A_neg[0]) % MOD
break
# のこり2以上のとき
if K - (pos_used + neg_used) >= 2:
# 正の数,負の数とも二つ以上残っているとき
if (pos_total - pos_used) >= 2 and (neg_total - neg_used) >= 2:
if (
A_neg[neg_used] * A_neg[neg_used + 1]
>= A_pos[pos_used] * A_pos[pos_used + 1]
):
ans = (ans * A_neg[neg_used] * A_neg[neg_used + 1]) % MOD
neg_used += 2
else:
ans = (ans * A_pos[pos_used] * A_pos[pos_used + 1]) % MOD
pos_used += 2
# もう正の数しか残っていない時
elif neg_total == neg_used:
ans = (ans * A_pos[pos_used] * A_pos[pos_used + 1]) % MOD
pos_used += 2
# もう負の数しか残っていない時
elif pos_total == pos_used:
ans = (ans * A_neg[neg_used] * A_neg[neg_used + 1]) % MOD
neg_used += 2
# のこり一つのとき
else:
# もう正の数しか残っていない時
if neg_total == neg_used:
ans = (ans * A_pos[pos_used]) % MOD
pos_used += 1
# もう負の数しか残っていない時
else:
ans = (ans * A_neg[neg_used]) % MOD
neg_used += 1
print(ans)
| Statement
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product
of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0
and 10^9+6 (inclusive). | [{"input": "4 2\n 1 2 -3 -4", "output": "12\n \n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and\n12, so the maximum product is 12.\n\n* * *"}, {"input": "4 3\n -1 -2 -3 -4", "output": "1000000001\n \n\nThe possible products of the three chosen elements are -24, -12, -8, and -6,\nso the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\n* * *"}, {"input": "2 1\n -1 1000000000", "output": "1000000000\n \n\nThe possible products of the one chosen element are -1 and 1000000000, so the\nmaximum product is 1000000000.\n\n* * *"}, {"input": "10 10\n 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1", "output": "999983200\n \n\nBe sure to print the product modulo (10^9+7)."}] |
Print the maximum product modulo (10^9+7), using an integer between 0 and
10^9+6 (inclusive).
* * * | s752599536 | Runtime Error | p02616 | Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N | import bisect
import sys
input = sys.stdin.readline
def main(args):
n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
minus = bisect.bisect_right(A, -1)
zeros = bisect.bisect_right(A, 0) - minus
plus = n - (minus + zeros)
mA = A[:minus]
pA = A[minus + zeros :]
mod = 10**9 + 7
# print("pArev",pA[::-1])
# print("mA",mA)
# 正の値が一個もないとき
if plus == 0:
if k % 2 == 1: # 負の数を奇数個とらなきゃならないとき
if zeros > 0: # ゼロがあれば
print(0)
else: # ゼロがないとき
ans = 1
for i in range(k):
ans = ans * mA[-(i + 1)] % mod
print(ans)
else: # 負の数を偶数個とらなきゃならないとき
ans = 1
for i in range(k):
ans = ans * mA[i] % mod
print(ans)
else: # 正の値が一個でもあれば
pickm = 0 # マイナスからとってきた個数
pickp = 0 # プラスからとってきた個数
indm = 0
indp = 0
pA.sort(reverse=True)
ans = 1
if minus > 0:
if k % 2 == 1: # 正から必ず奇数個とるとき
while pickm + pickp < k:
if pickm + pickp == k - 1 and pickp % 2 == 0:
ans = ans * pA[indp] % mod
break
if abs(pA[indp]) > abs(mA[indm]):
ans = ans * pA[indp] % mod
indp += 1
pickp += 1
else:
ans = ans * mA[indm] % mod
indm += 1
pickm += 1
else: # 正から必ず偶数個(0含む)とるとき
while pickm + pickp < k:
if pickm + pickp == k - 1:
if pickp % 2 == 0:
ans = ans * mA[indm] % mod
break
else:
ans = ans * pA[indp] % mod
break
if abs(pA[indp]) > abs(mA[indm]):
ans = ans * pA[indp] % mod
indp += 1
pickp += 1
else:
ans = ans * mA[indm] % mod
indm += 1
pickm += 1
else:
if plus < k:
print(0)
else:
ans = 1
for i in range(k):
ans = ans * pA[i] % mod
print(ans % mod)
if __name__ == "__main__":
main(sys.argv[1:])
| Statement
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product
of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0
and 10^9+6 (inclusive). | [{"input": "4 2\n 1 2 -3 -4", "output": "12\n \n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and\n12, so the maximum product is 12.\n\n* * *"}, {"input": "4 3\n -1 -2 -3 -4", "output": "1000000001\n \n\nThe possible products of the three chosen elements are -24, -12, -8, and -6,\nso the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\n* * *"}, {"input": "2 1\n -1 1000000000", "output": "1000000000\n \n\nThe possible products of the one chosen element are -1 and 1000000000, so the\nmaximum product is 1000000000.\n\n* * *"}, {"input": "10 10\n 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1", "output": "999983200\n \n\nBe sure to print the product modulo (10^9+7)."}] |
Print the maximum product modulo (10^9+7), using an integer between 0 and
10^9+6 (inclusive).
* * * | s438741449 | Runtime Error | p02616 | Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N | n, k = map(int, input().split())
lst = list(map(int, input().split()))
res = 10**9 + 7
plst = sorted([x for x in lst if x >= 0], reverse=True)
nlst = sorted([abs(x) for x in lst if x < 0], reverse=True)
lenn = len(nlst)
lenp = len(plst)
if lenp == 0 and k % 2 == 1:
sm = 1
for i in range(lenn - 1, lenn - k - 1, -1):
sm *= -nlst[i]
sm %= res
print(sm)
exit()
if lenp == 0 and k % 2 == 0:
sm = 1
for i in range(k):
sm *= nlst[i]
sm %= res
print(sm)
exit()
nlstw = [nlst[2 * i] * nlst[2 * i + 1] for i in range(lenn // 2)]
lennw = len(nlstw)
if lenn == 0:
sm = 1
for i in range(k):
sm *= plst[i]
sm %= res
print(sm)
exit()
ptoken = 0
ntoken = 0
nwtoken = 0
token = 0
sm = 1
while token < k:
if nwtoken == lennw or ptoken + 1 >= lenp:
break
if token == (k - 1) or plst[ptoken] > nlst[ntoken]:
sm *= plst[ptoken]
sm %= res
ptoken += 1
token += 1
else:
if nlstw[nwtoken] > plst[ptoken] * plst[ptoken + 1]:
sm *= nlstw[nwtoken]
sm %= res
ntoken += 2
nwtoken += 1
else:
sm *= plst[ptoken] * plst[ptoken + 1]
sm %= res
ptoken += 2
token += 2
else:
print(sm)
exit()
if ptoken + 1 >= lenp:
if (k - token) % 2 == 1:
sm *= plst[ptoken]
sm %= res
token += 1
while k > token:
sm *= nlstw[nwtoken]
sm %= res
token += 2
nwtoken += 1
else:
while k > token:
if nwtoken == lennw:
break
sm *= nlstw[nwtoken]
sm %= res
token += 2
nwtoken += 1
if k != token:
sm *= plst[ptoken]
sm %= res
print(sm)
exit()
if nwtoken == lennw:
while k > token:
if ptoken == lenp:
sm *= nlst[-1]
token += 1
continue
sm *= plst[ptoken]
sm %= res
ptoken += 1
token += 1
print(sm)
exit()
| Statement
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product
of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0
and 10^9+6 (inclusive). | [{"input": "4 2\n 1 2 -3 -4", "output": "12\n \n\nThe possible products of the two chosen elements are 2, -3, -4, -6, -8, and\n12, so the maximum product is 12.\n\n* * *"}, {"input": "4 3\n -1 -2 -3 -4", "output": "1000000001\n \n\nThe possible products of the three chosen elements are -24, -12, -8, and -6,\nso the maximum product is -6.\n\nWe print this value modulo (10^9+7), that is, 1000000001.\n\n* * *"}, {"input": "2 1\n -1 1000000000", "output": "1000000000\n \n\nThe possible products of the one chosen element are -1 and 1000000000, so the\nmaximum product is 1000000000.\n\n* * *"}, {"input": "10 10\n 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1", "output": "999983200\n \n\nBe sure to print the product modulo (10^9+7)."}] |
Print the fewest steps in a line. | s764038789 | Runtime Error | p02246 | The $4 \times 4$ integers denoting the pieces or space are given. | x = input()
n = int(input())
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
| 15 Puzzle
The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells
where one of the cells is empty space.
In this problem, the space is represented by 0 and pieces are represented by
integers from 1 to 15 as shown below.
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
You can move a piece toward the empty space at one step. Your goal is to make
the pieces the following configuration in the shortest move (fewest steps).
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
Write a program which reads an initial state of the puzzle and prints the
fewest steps to solve the puzzle. | [{"input": "2 3 4\n 6 7 8 0\n 5 10 11 12\n 9 13 14 15", "output": "8"}] |
Print the fewest steps in a line. | s809553952 | Wrong Answer | p02246 | The $4 \times 4$ integers denoting the pieces or space are given. | import copy
def hashnum(state):
num = 0
for i in range(3):
for j in range(3):
num *= 10
num += state[i][j]
return num
answer = 123456780
ini_state = []
for i in range(3):
temp = [int(n) for n in input().split(" ")]
if 0 in temp:
zero_x, zero_y = temp.index(0), i
ini_state.append(temp)
end_state = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
queue = [[ini_state, zero_x, zero_y, 0], [end_state, 2, 2, 1]]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
visited = {}
visited[hashnum(ini_state)] = [0, 0]
visited[answer] = [0, 1]
trial = 0
while answer not in visited:
new_queue = []
trial += 1
for q in queue:
state, zero_x, zero_y, direction = q
for i in range(len(dx)):
new_state = copy.deepcopy(state)
new_x = zero_x + dx[i]
new_y = zero_y + dy[i]
if 0 <= new_x < 3 and 0 <= new_y < 3:
new_state[new_y][new_x], new_state[zero_y][zero_x] = (
new_state[zero_y][zero_x],
new_state[new_y][new_x],
)
perm = hashnum(new_state)
if perm in visited and direction != visited[perm][1]:
print(trial + visited[perm][0])
exit()
if perm not in visited:
visited[perm] = [trial, direction]
new_queue.append([new_state, new_x, new_y, direction])
queue = new_queue
| 15 Puzzle
The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells
where one of the cells is empty space.
In this problem, the space is represented by 0 and pieces are represented by
integers from 1 to 15 as shown below.
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
You can move a piece toward the empty space at one step. Your goal is to make
the pieces the following configuration in the shortest move (fewest steps).
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
Write a program which reads an initial state of the puzzle and prints the
fewest steps to solve the puzzle. | [{"input": "2 3 4\n 6 7 8 0\n 5 10 11 12\n 9 13 14 15", "output": "8"}] |
Print the fewest steps in a line. | s569560417 | Wrong Answer | p02246 | The $4 \times 4$ integers denoting the pieces or space are given. | import heapq
from collections import namedtuple
def get_offset(x, y):
return 16 * y + 4 * x
def get_candidate(pid):
def check(pid, move):
if abs(move) == 1:
return pid // 4 == (pid + move) // 4
else:
return 0 <= pid + move < 16
return tuple(pid + move for move in MOVE_CANDIDATE if check(pid, move))
def get_swap_values(orig):
return {
dest: (1 << OFFSET_MASTER[orig]) - (1 << OFFSET_MASTER[dest])
for dest in SWAP_CANDIDATE[orig]
}
MOVE_CANDIDATE = (-4, -1, 1, 4)
SWAP_CANDIDATE = tuple(get_candidate(pid) for pid in range(16))
OFFSET_MASTER = tuple(get_offset(x, y) for y in range(4) for x in range(4))
SWAP_VALUE_MASTER = tuple(get_swap_values(pid) for pid in range(16))
HEURISTICS = tuple(
tuple(abs(dest // 4 - orig // 4) + abs(dest % 4 - orig % 4) for dest in range(16))
for orig in range(16)
)
def swap(board, orig, dest):
dest_val = (board >> OFFSET_MASTER[dest]) & 0b1111
return board + dest_val * SWAP_VALUE_MASTER[orig][dest]
def get_sum_heuristics(orig_board, is_reverse):
global dest_board_dicts
orig_board_dict = {i: orig_board >> (4 * i) & 0b1111 for i in range(16)}
dest_board_dict = dest_board_dicts[is_reverse]
return sum(
HEURISTICS[pid][dest_board_dict[val]] for pid, val in orig_board_dict.items()
)
def put_next_puzzle(is_reverse):
global puzzles, cache
(heur, puzzle) = heapq.heappop(puzzles[is_reverse])
board, id0, count, prev = puzzle.board, puzzle.id0, puzzle.count, puzzle.prev
for new_id0 in SWAP_CANDIDATE[id0]:
if new_id0 == prev:
continue
new_board = swap(board, id0, new_id0)
if new_board in cache[not is_reverse]:
return cache[not is_reverse][new_board].count + count + 1
new_heur = count + 1 + get_sum_heuristics(new_board, is_reverse)
if new_board in cache[is_reverse]:
closed_puzzle = cache[is_reverse][new_board]
if closed_puzzle.heur <= new_heur:
continue
new_puzzle = Puzzle(
board=new_board,
count=count + 1,
id0=new_id0,
prev=id0,
trace=puzzle.trace * 16 + new_id0,
heur=new_heur,
)
heapq.heappush(puzzles[is_reverse], (new_heur, new_puzzle))
cache[is_reverse][new_board] = new_puzzle
return -1
CORRECT = 0x0FEDCBA987654321
Puzzle = namedtuple("Puzzle", "board count id0 prev trace heur")
puzzles = ([], [])
cache = ({}, {})
board = 0
id0 = -1
for j in range(4):
for i, v in enumerate(map(int, input().strip().split())):
board += v << get_offset(i, j)
if v == 0:
id0 = 4 * j + i
dest_board_dicts = (
{CORRECT >> (4 * i) & 0b1111: i for i in range(16)},
{board >> (4 * i) & 0b1111: i for i in range(16)},
)
s_heur = get_sum_heuristics(board, False)
g_heur = get_sum_heuristics(CORRECT, True)
s_puzzle = Puzzle(
board=board, count=0, id0=id0, prev=-1, trace=0, heur=get_sum_heuristics(board, 0)
)
g_puzzle = Puzzle(
board=CORRECT,
count=0,
id0=15,
prev=-1,
trace=0,
heur=get_sum_heuristics(CORRECT, 1),
)
heapq.heappush(puzzles[0], (s_heur, s_puzzle))
heapq.heappush(puzzles[1], (g_heur, g_puzzle))
cache[0][board] = s_puzzle
cache[1][CORRECT] = g_puzzle
result = None
is_reverse = False
while True:
result = put_next_puzzle(is_reverse)
if result > -1:
break
is_reverse = not is_reverse
print(result)
| 15 Puzzle
The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells
where one of the cells is empty space.
In this problem, the space is represented by 0 and pieces are represented by
integers from 1 to 15 as shown below.
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
You can move a piece toward the empty space at one step. Your goal is to make
the pieces the following configuration in the shortest move (fewest steps).
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
Write a program which reads an initial state of the puzzle and prints the
fewest steps to solve the puzzle. | [{"input": "2 3 4\n 6 7 8 0\n 5 10 11 12\n 9 13 14 15", "output": "8"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s218484052 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | # -*- coding: utf-8 -*-
import logging
import time
class Solver:
def __init__(self):
self.n = 0
self.k = 0
# 入力
def input_value(self):
# self.n = int(input())
# self.A, self.B = map(int, input().split())
# self.A = list(map(int, input().split()))
# self.a, self.b, self.c = map(int, [input() for i in range(4)])
# self.t = [None] * self.n
(
self.n,
self.k,
) = map(int, input().split())
# @staticmethod
# def can_go(t, x, y):
# logging.debug(input_str)
# logging.debug(input_str)
def run(self):
if self.n % self.k == 0:
return 0
return 1
@staticmethod
def test(self):
start_time = time.time()
# assert self.run(3, 1, 2), 'Error.'
elapsed_time = time.time() - start_time
logging.debug("elapsed_time: {0}".format(elapsed_time) + "[sec]")
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
solver = Solver()
# solver.test()
solver.input_value()
ans = solver.run()
# print(str(ans))
print(str(ans))
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s578650376 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | import math
import queue
import bisect
import heapq
import time
import itertools
mod = int(1e9 + 7)
def swap(a, b):
return (b, a)
def my_round(a, dig=0):
p = 10**dig
return (a * p * 2 + 1) // 2 / p
def gcd(a, b): # 最大公約数
if a < b:
a, b = swap(a, b)
if b == 0:
return a
else:
return gcd(b, a % b)
def lcm(a, b): # 最小公倍数
return a / gcd(a, b) * b
def divisors(a): # 約数列挙
divisors = []
for i in range(1, int(a**0.5) + 1):
if a % i == 0:
divisors.append(i)
if i != a // i:
divisors.append(a // i)
return divisors
def is_prime(a): # 素数判定
if a < 2:
return False
elif a == 2:
return True
elif a % 2 == 0:
return False
sqrt_num = int(a**0.5)
for i in range(3, sqrt_num + 1, 2):
if a % i == 0:
return False
return True
def prime_num(a): # 素数列挙
pn = [2]
for i in range(3, int(a**0.5), 2):
prime = True
for j in pn:
if i % j == 0:
prime = False
break
if prime:
pn.append(i)
return pn
def prime_fact(a): # 素因数分解
sqrt = math.sqrt(a)
res = []
i = 2
if is_prime(a):
res.append(a)
else:
while a != 1:
while a % i == 0:
res.append(i)
a //= i
i += 1
return res
def main():
n, k = map(int, input().split())
if n % k == 0:
print(0)
else:
print(1)
return
if __name__ == "__main__":
main()
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s248796273 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
(*a,) = map(int, open(0))
def S_():
return input()
def IS():
return input().split()
def LS():
return [i for i in input().split()]
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def NI(n):
return [int(input()) for i in range(n)]
def NI_(n):
return [int(input()) - 1 for i in range(n)]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def LtoS(ls):
return "".join([chr(i + 97) for i in ls])
def GI(V, E, Directed=False, index=0):
org_inp = []
g = [[] for i in range(n)]
for i in range(E):
inp = LI()
org_inp.append(inp)
if index == 0:
inp[0] -= 1
inp[1] -= 1
if len(inp) == 2:
a, b = inp
g[a].append(b)
if not Directed:
g[b].append(a)
elif len(inp) == 3:
a, b, c = inp
aa = (inp[0], inp[2])
bb = (inp[1], inp[2])
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g, org_inp
def GGI(h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}):
# h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
mp = [1] * (w + 2)
found = {}
for i in range(h):
s = input()
for char in search:
if char in s:
found[char] = (i + 1) * (w + 2) + s.index(char) + 1
mp_def[char] = mp_def[replacement_of_found]
mp += [1] + [mp_def[j] for j in s] + [1]
mp += [1] * (w + 2)
return h + 2, w + 2, mp, found
def bit_combination(k, n=2):
rt = []
for tb in range(n**k):
s = [tb // (n**bt) % n for bt in range(k)]
rt += [s]
return rt
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YN = ["YES", "NO"]
mo = 10**9 + 7
inf = float("inf")
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()
def ran_input():
import random
n = random.randint(4, 16)
rmin, rmax = 1, 10
a = [random.randint(rmin, rmax) for _ in range(n)]
return n, a
show_flg = False
show_flg = True
n, k = LI()
if n % k == 0:
ans = 0
else:
ans = 1
print(ans)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s766860693 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n):
for j in range(n):
if sum(a[i : j + 1]) % m == 0 and sum(a[i : j + 1]) != 0:
count += 1
print(count)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s548057567 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | # import sys
# input = sys.stdin.readline
# template input
import bisect
def IT():
return int(input())
def IL():
return [int(_) for _ in input().split()]
def SL():
return [int(_) for _ in input().split()]
def ILS(n):
return [int(input()) for _ in range(n)]
def SLS(n):
return [input() for _ in range(n)]
def ILSS(n):
return [[int(_) for _ in input().split()] for j in range(n)]
# template technique
def bit_full_search(ss):
n = len(ss)
for i in range(1 << n):
s = ""
for j in range(n + 1):
if (1 & i >> j) == 1:
s += ss[j]
print(s)
def bit_full_search2(A):
# https://blog.rossywhite.com/2018/08/06/bit-search/
value = []
for i in range(1 << len(A)):
output = []
for j in range(len(A)):
if ((i >> j) & 1) == 1:
# output.append(A[j])
output.append(A[j])
# print(output)
value.append([format(i, "b"), sum(output)])
# print(value)
return value
"""ここからメインコード"""
def main():
n = IT()
# それぞれ半分全列挙
list1 = [(-2) ** i for i in range(17)]
list2 = [(-2) ** (i + 17) for i in range(17)]
list1 = bit_full_search2(list1)
list1.sort(key=lambda x: x[1])
list1_bin = [list1[i][0] for i in range(len(list1))]
list1_val = [list1[i][1] for i in range(len(list1))]
list2 = bit_full_search2(list2)
list2.sort(key=lambda x: x[1])
list2_bin = [list2[i][0] for i in range(len(list2))]
list2_val = [list2[i][1] for i in range(len(list2))]
for i in range(len(list1_val)):
j = bisect.bisect_left(list2_val, n - list1_val[i])
if j < len(list2_val):
if list1_val[i] + list2_val[j] == n:
ans = list2_bin[j] + list1_bin[i]
break
print(int(ans))
main()
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s041495541 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | m, n = map(int, input().split())
if m>= n:
print(m % n)
else:
print(1) | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s055021119 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | import numpy as np
n, m = input().split()
n = int(n)
m = int(m)
a = input().split()
a = [int(i) for i in a]
ans = 0
sumlist = list(np.cumsum(a))
for i in range(n):
# print(sumlist)
# for j in range(len(sumlist)):
# if sumlist[j] % m == 0:
# ans += 1
tmp = [x for x in sumlist if x % m == 0]
ans += len(tmp)
sumlist = list(map(lambda x: x - sumlist[0], sumlist))
sumlist.pop(0)
print(ans)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s463903939 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | N,K=map(int,input().split())
if N%K==0:
print(0)
else:
print(1) | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s948934436 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | print(int(list(input.split())[0]) % int(list(input.split())[1]))
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s711787968 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | n,k = map(int,input().split())
if n%k = 0:
print(0)
else:
print(1) | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s948731662 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | N, K = [int(i) for i in input()]
print(0) if N % K == 0 else print(1)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s146189352 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | print(int(bool(eval(input().replace(" ", "%")))))
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s442674218 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | print(int(eval(input().replace(" ", "%")) != 0))
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s572060416 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | N, K = (int(T) for T in input().split())
print([1, 0][N % K == 0])
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s456775257 | Accepted | p03284 | Input is given from Standard Input in the following format:
N K | def getinputdata():
array_result = []
array_result.append(input().split(" "))
flg = True
try:
while flg:
data = input()
if data != "":
array_result.append(data.split(" "))
flg = True
else:
flg = False
finally:
return array_result
arr_data = getinputdata()
n = int(arr_data[0][0])
k = int(arr_data[0][1])
print(0 if n % k == 0 else 1)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s671231267 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | """"
高橋君は N 枚の AtCoder せんべいを K 人の AtCoder 参加者になるべく公平に配ることにしました。
N 枚すべてのせんべいを配るとき、せんべいを最も多くもらった人と最も少なくもらった人のもらったせんべいの枚数の差(の絶対値)の最小値を求めてください。
""""
min_num = n // k
max_num = min_num + amari
amari = n % k
kotae = max_num -min_num | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s535401250 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | import bisect
n = int(input())
ps = [0] * (1 << 16)
for i in range(1 << 16):
temp = 0
x = 1
for j in range(16):
if (i >> j) & 1:
# temp += (-2) ** (2 *j)
temp += x
x *= 4
ps[i] = temp
pattern1 = None
pattern2 = None
for i in range(1 << 16):
temp2 = 0
x = 2
for j in range(16):
if (i >> j) & 1:
# temp2 += (-2) ** (2 *j + 1)
temp2 += x
x *= 4
n2 = n + temp2
pattern1 = bisect.bisect_left(ps, n2)
if pattern1 != (1 << 16) and ps[pattern1] == n2:
pattern2 = bin(i)[2:].zfill(16)
pattern1 = bin(pattern1)[2:].zfill(16)
break
ans = ""
for i in range(16):
ans += pattern2[i]
ans += pattern1[i]
true_ans = ""
flag = False
for i in range(len(ans)):
if ans[i] == "1":
true_ans += "1"
flag = True
elif flag:
true_ans += "0"
if true_ans == "":
true_ans = "0"
print(true_ans)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s602634923 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | #coding:utf-8
n=[int(i) for i in input().split()]
if(n[0]%n[1]=0):
print(0)
else:
print(1) | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s813856294 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | n,k = map(int,input().split())
if n%k ==0:
print(0)
elif n < k:
print((1)
else:
print((n//k) - 1) | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s342777863 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | n = int(input())
a = []
if n > 0:
while n > 0:
a.append(n % 2)
n //= 2
a.append(0)
a.append(0)
for i in range(len(a) - 1):
if i % 2 == 1:
if a[i] == 1:
a[i + 1] += 1
elif a[i] == 2:
a[i + 1] += 1
a[i] = 0
else:
if a[i] == 2:
a[i + 1] += 1
a[i] = 0
a[i] = str(a[i])
for i in range(len(a) - 1, -1, -1):
if a[i] == 0 or a[i] == "0":
a[i] = ""
else:
break
print("".join(reversed(a)))
elif n == 0:
print("0")
else:
n = 0 - n
while n > 0:
a.append(n % 2)
n //= 2
a.append(0)
a.append(0)
for i in range(len(a) - 1):
if i % 2 != 1:
if a[i] == 1:
a[i + 1] += 1
elif a[i] == 2:
a[i + 1] += 1
a[i] = 0
else:
if a[i] == 2:
a[i + 1] += 1
a[i] = 0
a[i] = str(a[i])
for i in range(len(a) - 1, -1, -1):
if a[i] == 0 or a[i] == "0":
a[i] = ""
else:
break
print("".join(reversed(a)))
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s785708141 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | N K = map(int, inpur().split())
if N % K => 1:
print(1)
else:
print(0) | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s424584020 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | n,k=map(int,input().split())
print(n%k==0:
print(0)
else:
print(1)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s457169434 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | N=int(input()) K=int(input))
if N%K==0:
print(0)
else:
print(1)
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s234480846 | Runtime Error | p03284 | Input is given from Standard Input in the following format:
N K | N,K = map(int,input().split())
if N%K==0:
print(0)
else:
print( | Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Print the minimum possible (absolute) difference between the largest number of
crackers received by a user and the smallest number received by a user.
* * * | s758319538 | Wrong Answer | p03284 | Input is given from Standard Input in the following format:
N K | a = sorted(list(map(int, input().split())))
print(a[-1] - a[0])
| Statement
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly
as possible. When all the crackers are distributed, find the minimum possible
(absolute) difference between the largest number of crackers received by a
user and the smallest number received by a user. | [{"input": "7 3", "output": "1\n \n\nWhen the users receive two, two and three crackers, respectively, the\n(absolute) difference between the largest number of crackers received by a\nuser and the smallest number received by a user, is 1.\n\n* * *"}, {"input": "100 10", "output": "0\n \n\nThe crackers can be distributed evenly.\n\n* * *"}, {"input": "1 1", "output": "0"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.