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 the number of ID cards that allow us to pass all the gates alone.
* * * | s031742185 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | n, m = [int(i) for i in input().strip().split()]
a = []
for _ in range(m):
a.append([int(i) for i in input().strip().split()])
a.sort(key=lambda s: s[1])
result = a[0]
for i in range(1, len(a)):
if result[1] >= a[i][0]:
result = [max(result[0], a[i][0]), min(result[1], a[i][1])]
else:
result = []
break
print(len(result))
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s001689238 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]
a = [{j for j in range(lr[i][0], lr[0][1] + 1)} for i in range(nm[1])]
b = set()
for i in range(len(a)):
if b == set():
b = a[i]
b = b & a[i]
print(b)
print(len(b))
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s512332694 | Accepted | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | x = lambda: map(int, input().split())
N, M = x()
l, r = zip(*[tuple(x()) for _ in range(M)])
print(max(0, 1 + min(r) - max(l)))
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s158181565 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | N, Q = map(int, input().split())
l = [list(map(int, input().split())) for i in range(Q)]
s_ids = []
m_ids = []
for i in range(Q):
s_ids.append(l[i][0])
m_ids.append(l[i][1])
max_s_id = max(s_ids)
min_m_id = min(m_ids)
diff = abs(max_s_id - min_m_id)
print(diff + 1)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s050729761 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | n, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
l_max = max(x[0] for x in X)
r_min = min(x[1] for x in X)
print(r_min - l_max + 1)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s958190474 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | n, m = input().split()
LR = [list(map(int, input().split())) for i in range(int(m))]
s = max([i[0] for i in LR])
e = min([i[1] for i in LR])
print(e - s + 1)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s709229967 | Accepted | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | import sys
from itertools import accumulate
# booltable=[0]+booltable
def resolve():
input = sys.stdin.readline
N, M = map(int, input().rstrip().split())
G = [list(map(int, input().rstrip().split())) for _ in range(M)]
l = [0 for _ in range(N)]
for i in range(M):
l[G[i][0] - 1] += 1
if G[i][1] != N:
l[G[i][1]] -= 1
l = [0] + l
cumsum = list(accumulate(l)) # 0~N
ans = cumsum.count(int(M))
print(ans)
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """4 2
1 3
2 4"""
output = """2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """10 3
3 6
5 7
6 9"""
output = """1"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """100000 1
1 100000"""
output = """100000"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s686530391 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | # -*- coding: utf-8 -*-
debug = False
def log(text):
if debug:
print(text)
def parse_input(lines_as_string=None):
global debug
lines = []
if lines_as_string is None:
debug = False
lines.append(input())
token = lines[0].split(" ")
n = int(token[0])
m = int(token[1])
for i in range(m):
lines.append(input())
else:
debug = True
lines = [e for e in lines_as_string.split("\n")][1:-1]
token = lines[0].split(" ")
n = int(token[0])
m = int(token[1])
lr = []
for i in range(1, m + 1):
token = lines[i].split(" ")
l = int(token[0])
r = int(token[1])
lr.append({"l": l, "r": r})
return (n, m, lr)
def solve(n, m, lr):
if len(lr) == 1:
l = lr[0]["l"]
r = lr[0]["r"]
return r - l + 1
l = lr[0]["l"]
r = lr[0]["r"]
c = {"l": l, "r": r}
count = 0
for i in range(1, m):
if lr[i]["l"] <= c["r"] and c["l"] <= lr[i]["r"]:
c["r"] = min(c["r"], lr[i]["r"])
c["l"] = max(c["l"], lr[i]["l"])
count = count + 1
if debug:
log("c=%s" % c)
result = c["r"] - c["l"] + 1
if debug:
log("count=%s" % count)
log("result=%s" % result)
if count == 0:
return 0
return result
def main():
# 出力
print("%s" % solve(*parse_input()))
if __name__ == "__main__":
main()
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s096452864 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | N, M = list(map(int, input().split()))
s = 1
m = N
for i in range(M):
a, b = list(map(int, input().split()))
if s < a:
s = a
if m > b:
m = b
# ans &=tmp
print(m - s + 1)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s994420014 | Accepted | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | n, m, *t = map(int, open(0).read().split())
a, c = [0] * -~n, 0
for l, r in zip(t[::2], t[1::2]):
a[l - 1] += 1
a[r] -= 1
for i in range(n):
a[i + 1] += a[i]
c += a[i] == m
print(c)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s854351128 | Accepted | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | def main():
from sys import stdin, stdout
def read():
return stdin.readline().rstrip("\n")
def read_array(sep=None, maxsplit=-1):
return read().split(sep, maxsplit)
def read_int():
return int(read())
def read_int_array(sep=None, maxsplit=-1):
return [int(a) for a in read_array(sep, maxsplit)]
def write(*args, **kwargs):
sep = kwargs.get("sep", " ")
end = kwargs.get("end", "\n")
stdout.write(sep.join(str(a) for a in args) + end)
def write_array(array, **kwargs):
sep = kwargs.get("sep", " ")
end = kwargs.get("end", "\n")
stdout.write(sep.join(str(a) for a in array) + end)
n, m = read_int_array()
l, r = 1, n
for i in range(m):
l1, r1 = read_int_array()
l = max(l, l1)
r = min(r, r1)
write(max(r + 1 - l, 0))
main()
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s080946352 | Accepted | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | N_ID, M_gate = map(int, input().split())
mini = float("inf")
MAX = 0
for i in range(M_gate):
L, R = map(int, input().split())
MAX = max(MAX, L)
mini = min(mini, R)
answer = max(0, mini - MAX + 1)
print(answer)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s197697742 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | n, m = [int(_) for _ in input().split()]
ld = 1
rd = n
for iii in range(m):
l, r = [int(_) for _ in input().split()]
if ld < l:
ld = l
if rd > r:
rd = r
print(rd - ld + 1)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the number of ID cards that allow us to pass all the gates alone.
* * * | s618562764 | Wrong Answer | p03037 | Input is given from Standard Input in the following format:
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M | N, M = [int(nm) for nm in input().split()]
L, R = [int(lr) for lr in input().split()]
LR = [L, R]
for m in range(M - 1):
L_2, R_2 = [int(lr) for lr in input().split()]
if (L_2 <= LR[0]) and (LR[1] <= R_2):
continue
elif (L_2 <= LR[0]) and (R_2 < LR[1]):
LR = [LR[0], R_2]
elif (LR[0] < L_2) and (LR[1] <= R_2):
LR = [L_2, LR[1]]
else: # (LR[0] < L_2) and (R_2 < LR[1]):
LR = [L_2, R_2]
card = LR[1] - LR[0] + 1
print(card)
| Statement
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-
th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone? | [{"input": "4 2\n 1 3\n 2 4", "output": "2\n \n\nTwo ID cards allow us to pass all the gates alone, as follows:\n\n * The first ID card does not allow us to pass the second gate.\n * The second ID card allows us to pass all the gates.\n * The third ID card allows us to pass all the gates.\n * The fourth ID card does not allow us to pass the first gate.\n\n* * *"}, {"input": "10 3\n 3 6\n 5 7\n 6 9", "output": "1\n \n\n* * *"}, {"input": "100000 1\n 1 100000", "output": "100000"}] |
Print the sorted sequence. Two contiguous elements of the sequence should be
separated by a space character. The element which is selected as the pivot of
the partition should be indicated by [ ]. | s259059629 | Accepted | p02276 | The first line of the input includes an integer _n_ , the number of elements
in the sequence A.
In the second line, _A i_ (_i_ = 1,2,...,_n_), elements of the sequence are
given separated by space characters. | #! python3
# partition.py - 配列を特定の値で、分割するアルゴリズム
def partition(array, p, len_array):
X = array[len_array]
i = 0 - 1
for j in range(p, len_array):
if array[j] <= X:
i += 1
tmp = array[i]
array[i] = array[j]
array[j] = tmp
tmp = array[i + 1]
array[i + 1] = array[len_array]
array[len_array] = tmp
return i + 1, array
len_array = int(input()) - 1
array = [int(i) for i in input().split()]
p = 0 # 配列のスタート位置、今後別の関数で使うことも想定して、変数で渡しておく
index, array = partition(array, p, len_array)
# print(index)
# print(array)
str_array = list(map(str, array))
# print(str_array)
str_array[index] = "[{}]".format(str_array[index])
print(" ".join(str_array))
| Partition
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r),
first, a procedure Partition(A, p, r) divides an array A[p..r] into two
subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less
than or equal to A[q], which is, inturn, less than or equal to each element of
A[q+1..r]. It also computes the index q.
In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted
by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).
Your task is to read a sequence A and perform the Partition based on the
following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 for j = p to r-1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
Note that, in this algorithm, Partition always selects an element A[r] as a
pivot element around which to partition the array A[p..r]. | [{"input": "12\n 13 19 9 5 12 8 7 4 21 2 6 11", "output": "9 5 8 7 4 2 6 [11] 21 13 19 12"}] |
Print the minimum number of stones to move to guarantee Takahashi's win;
otherwise, print `-1` instead.
* * * | s368252384 | Accepted | p02626 | Input is given from Standard Input in the following format:
N
A_1 \ldots A_N | n = int(input())
a = list(map(int, input().split()))
x = 0
for i in a[2:]:
x ^= i
m = (a[0] + a[1] - x) // 2
if a[0] + a[1] != x + m * 2 or m > a[0] or (x & m) != 0:
exit(print(-1))
l = 1 << (max(x.bit_length(), m.bit_length()) + 1)
while l > 0:
if ((x & l) != 0) and ((m | l) <= a[0]):
m |= l
l >>= 1
print(a[0] - m if m != 0 else -1)
| Statement
There are N piles of stones. The i-th pile has A_i stones.
Aoki and Takahashi are about to use them to play the following game:
* Starting with Aoki, the two players alternately do the following operation:
* Operation: Choose one pile of stones, and remove one or more stones from it.
* When a player is unable to do the operation, he loses, and the other player wins.
When the two players play optimally, there are two possibilities in this game:
the player who moves first always wins, or the player who moves second always
wins, only depending on the initial number of stones in each pile.
In such a situation, Takahashi, the second player to act, is trying to
guarantee his win by moving at least zero and at most (A_1 - 1) stones from
the 1-st pile to the 2-nd pile before the game begins.
If this is possible, print the minimum number of stones to move to guarantee
his victory; otherwise, print `-1` instead. | [{"input": "2\n 5 3", "output": "1\n \n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile,\nTakahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game\nbegins so that both piles have 4 stones, Takahashi can always win by properly\nchoosing his actions.\n\n* * *"}, {"input": "2\n 3 5", "output": "-1\n \n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "-1\n \n\nIt is not allowed to move all stones from the 1-st pile.\n\n* * *"}, {"input": "8\n 10 9 8 7 6 5 4 3", "output": "3\n \n\n* * *"}, {"input": "3\n 4294967297 8589934593 12884901890", "output": "1\n \n\nWatch out for overflows."}] |
Print the minimum number of stones to move to guarantee Takahashi's win;
otherwise, print `-1` instead.
* * * | s022051384 | Wrong Answer | p02626 | Input is given from Standard Input in the following format:
N
A_1 \ldots A_N | print(0)
| Statement
There are N piles of stones. The i-th pile has A_i stones.
Aoki and Takahashi are about to use them to play the following game:
* Starting with Aoki, the two players alternately do the following operation:
* Operation: Choose one pile of stones, and remove one or more stones from it.
* When a player is unable to do the operation, he loses, and the other player wins.
When the two players play optimally, there are two possibilities in this game:
the player who moves first always wins, or the player who moves second always
wins, only depending on the initial number of stones in each pile.
In such a situation, Takahashi, the second player to act, is trying to
guarantee his win by moving at least zero and at most (A_1 - 1) stones from
the 1-st pile to the 2-nd pile before the game begins.
If this is possible, print the minimum number of stones to move to guarantee
his victory; otherwise, print `-1` instead. | [{"input": "2\n 5 3", "output": "1\n \n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile,\nTakahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game\nbegins so that both piles have 4 stones, Takahashi can always win by properly\nchoosing his actions.\n\n* * *"}, {"input": "2\n 3 5", "output": "-1\n \n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "-1\n \n\nIt is not allowed to move all stones from the 1-st pile.\n\n* * *"}, {"input": "8\n 10 9 8 7 6 5 4 3", "output": "3\n \n\n* * *"}, {"input": "3\n 4294967297 8589934593 12884901890", "output": "1\n \n\nWatch out for overflows."}] |
Print the minimum number of stones to move to guarantee Takahashi's win;
otherwise, print `-1` instead.
* * * | s327234000 | Wrong Answer | p02626 | Input is given from Standard Input in the following format:
N
A_1 \ldots A_N | print(1)
| Statement
There are N piles of stones. The i-th pile has A_i stones.
Aoki and Takahashi are about to use them to play the following game:
* Starting with Aoki, the two players alternately do the following operation:
* Operation: Choose one pile of stones, and remove one or more stones from it.
* When a player is unable to do the operation, he loses, and the other player wins.
When the two players play optimally, there are two possibilities in this game:
the player who moves first always wins, or the player who moves second always
wins, only depending on the initial number of stones in each pile.
In such a situation, Takahashi, the second player to act, is trying to
guarantee his win by moving at least zero and at most (A_1 - 1) stones from
the 1-st pile to the 2-nd pile before the game begins.
If this is possible, print the minimum number of stones to move to guarantee
his victory; otherwise, print `-1` instead. | [{"input": "2\n 5 3", "output": "1\n \n\nWithout moving stones, if Aoki first removes 2 stones from the 1-st pile,\nTakahashi cannot win in any way.\n\nIf Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game\nbegins so that both piles have 4 stones, Takahashi can always win by properly\nchoosing his actions.\n\n* * *"}, {"input": "2\n 3 5", "output": "-1\n \n\nIt is not allowed to move stones from the 2-nd pile to the 1-st.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "-1\n \n\nIt is not allowed to move all stones from the 1-st pile.\n\n* * *"}, {"input": "8\n 10 9 8 7 6 5 4 3", "output": "3\n \n\n* * *"}, {"input": "3\n 4294967297 8589934593 12884901890", "output": "1\n \n\nWatch out for overflows."}] |
Print the number of ways modulo $10^9+7$ in a line. | s030569048 | Accepted | p02333 | $n$ $k$
The first line will contain two integers $n$ and $k$. | N, K = map(int, input().split())
MOD = 10**9 + 7
if N < K:
print(0)
else:
ans = 0
v = 1
for i in range(K):
if i % 2:
ans -= pow(K - i, N, MOD) * v
else:
ans += pow(K - i, N, MOD) * v
v = v * (K - i) * pow(i + 1, MOD - 2, MOD) % MOD
print(ans % MOD)
| You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
* Each ball is distinguished from the other.
* Each box is distinguished from the other.
* Each ball can go into only one box and no one remains outside of the boxes.
* Each box must contain at least one ball.
Note that you must print this count modulo $10^9+7$. | [{"input": "4 3", "output": "36"}, {"input": "10 3", "output": "55980"}, {"input": "100 100", "output": "437918130"}] |
For each query, print "2", "1" or "0". | s598099036 | Accepted | p02299 | The entire input looks like:
g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counter-clockwise visit of them.
Each query consists of the coordinate of a target point t. The coordinate is
given by two intgers x and y. | def dot(a: complex, b: complex) -> float:
return a.real * b.real + a.imag * b.imag
def cross(a: complex, b: complex) -> float:
return a.real * b.imag - a.imag * b.real
if __name__ == "__main__":
n = int(input())
coordinates = [complex(*map(int, input().split())) for _ in range(n)]
pairs = [
(p0, p1) for p0, p1 in zip(coordinates, coordinates[1:] + [coordinates[0]])
]
q = int(input())
for _ in range(q):
p = complex(*map(int, input().split()))
counter = 0
for p0, p1 in pairs:
a, b = p0 - p, p1 - p
if a.imag > b.imag:
a, b = b, a
crs = cross(a, b)
if a.imag <= 0 and 0 < b.imag and crs < 0:
counter += 1
if crs == 0 and dot(a, b) <= 0:
print(1)
break
else:
print(2 if counter % 2 else 0)
| Polygon-Point-Containment
For a given polygon g and target points t, print "2" if g contains t, "1" if t
is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex. | [{"input": "0 0\n 3 1\n 2 3\n 0 3\n 3\n 2 1\n 0 2\n 3 2", "output": "1\n 0"}] |
For each query, print "2", "1" or "0". | s051002298 | Accepted | p02299 | The entire input looks like:
g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counter-clockwise visit of them.
Each query consists of the coordinate of a target point t. The coordinate is
given by two intgers x and y. | def inside_polygon(p0, qs):
cnt = 0
L = len(qs)
x, y = p0
for i in range(L):
x0, y0 = qs[i - 1]
x1, y1 = qs[i]
x0 -= x
y0 -= y
x1 -= x
y1 -= y
cv = x0 * x1 + y0 * y1
sv = x0 * y1 - x1 * y0
if sv == 0 and cv <= 0:
return 1
if not y0 < y1:
x0, x1 = x1, x0
y0, y1 = y1, y0
if y0 <= 0 < y1 and x0 * (y1 - y0) > y0 * (x1 - x0):
cnt += 1
return 2 if cnt % 2 == 1 else 0
def solve():
N = int(input())
qs = [list(map(int, input().split())) for i in range(N)]
Q = int(input())
for i in range(Q):
(*p0,) = map(int, input().split())
print(inside_polygon(p0, qs))
solve()
| Polygon-Point-Containment
For a given polygon g and target points t, print "2" if g contains t, "1" if t
is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex. | [{"input": "0 0\n 3 1\n 2 3\n 0 3\n 3\n 2 1\n 0 2\n 3 2", "output": "1\n 0"}] |
For each query, print "2", "1" or "0". | s279882423 | Wrong Answer | p02299 | The entire input looks like:
g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counter-clockwise visit of them.
Each query consists of the coordinate of a target point t. The coordinate is
given by two intgers x and y. | # -*- coding: utf-8 -*-
import collections
import math
class Vector2(collections.namedtuple("Vector2", ["x", "y"])):
def __add__(self, other):
return Vector2(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vector2(self.x - other.x, self.y - other.y)
def __mul__(self, scalar):
return Vector2(self.x * scalar, self.y * scalar)
def __neg__(self):
return Vector2(-self.x, -self.y)
def __pos__(self):
return Vector2(+self.x, +self.y)
def __abs__(self): # norm
return math.sqrt(float(self.x * self.x + self.y * self.y))
def __truediv__(self, scalar):
return Vector2(self.x / scalar, self.y / scalar)
def abs2(self):
return float(self.x * self.x + self.y * self.y)
def dot(self, other): # dot product
return self.x * other.x + self.y * other.y
def cross(self, other): # cross product
return self.x * other.y - self.y * other.x
def getDistanceSP(segment, point):
p = point
p1, p2 = segment
if (p2 - p1).dot(p - p1) < 0:
return abs(p - p1)
if (p1 - p2).dot(p - p2) < 0:
return abs(p - p2)
return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)
def getDistance(s1, s2):
a, b = s1
c, d = s2
if intersect(s1, s2): # intersect
return 0
return min(
getDistanceSP(s1, c),
getDistanceSP(s1, d),
getDistanceSP(s2, a),
getDistanceSP(s2, b),
)
def ccw(p0, p1, p2):
a = p1 - p0
b = p2 - p0
if a.cross(b) > 0:
return 1 # COUNTER_CLOCKWISE
elif a.cross(b) < 0:
return -1 # CLOCKWISE
elif a.dot(b) < 0:
return 2 # ONLINE_BACK
elif abs(a) < abs(b):
return -2 # ONLINE_FRONT
else:
return 0 # ON_SEGMENT
def intersect(s1, s2):
a, b = s1
c, d = s2
return ccw(a, b, c) * ccw(a, b, d) <= 0 and ccw(c, d, a) * ccw(c, d, b) <= 0
def project(l, p):
p1, p2 = l
base = p2 - p1
hypo = p - p1
return p1 + base * (hypo.dot(base) / abs(base) ** 2)
class Circle:
def __init__(self, c, r):
self.c = c
self.r = r
def getCrossPoints(c, l):
pr = project(l, c.c)
p1, p2 = l
e = (p2 - p1) / abs(p2 - p1)
base = math.sqrt(c.r * c.r - (pr - c.c).abs2())
return [pr + e * base, pr - e * base]
def polar(r, a):
return Vector2(r * math.cos(a), r * math.sin(a))
def getCrossPointsCircle(c1, c2):
base = c2.c - c1.c
d = abs(base)
a = math.acos((c1.r**2 + d**2 - c2.r**2) / (2 * c1.r * d))
t = math.atan2(base.y, base.x)
return [c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)]
def contains(g, p):
n = len(g)
x = 0
for i in range(n):
a = g[i] - p
b = g[(i + 1) % n] - p
if a.cross(b) == 0 and a.dot(b) < 0:
return 1
if a.y > b.y:
a, b = b, a
if a.y <= 0 and b.y > 0 and a.cross(b) > 0:
x += 1
if x % 2 == 1:
return 2
else:
return 0
if __name__ == "__main__":
n = int(input())
g = []
for _ in range(n):
a, b = map(int, input().split())
g.append(Vector2(a, b))
q = int(input())
for _ in range(q):
c, d = map(int, input().split())
print(contains(g, Vector2(c, d)))
| Polygon-Point-Containment
For a given polygon g and target points t, print "2" if g contains t, "1" if t
is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex. | [{"input": "0 0\n 3 1\n 2 3\n 0 3\n 3\n 2 1\n 0 2\n 3 2", "output": "1\n 0"}] |
For each query, print "2", "1" or "0". | s861812158 | Wrong Answer | p02299 | The entire input looks like:
g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counter-clockwise visit of them.
Each query consists of the coordinate of a target point t. The coordinate is
given by two intgers x and y. | from sys import stdin
readline = stdin.readline
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def eq(a, b):
return abs(a - b) < 1e-10
def on_line(p, s, e):
d = dot(p - s, e - s)
c = cross(p - s, e - s)
if c == 0 and 0 <= d <= abs(e - s) ** 2:
return True
return False
def on_polygon_line(xy, p):
for i in range(len(p)):
j = i - 1
if on_line(xy, p[i], p[j]):
return True
return False
def in_polygon(xy, p):
wn = 0
for i in range(len(p)):
j = i - 1
if 0 == (p[i] - p[j]).imag:
continue
vt = (xy - p[j]).imag / (p[i] - p[j]).imag
tmp = p[i] + vt * (p[i] - p[j])
if xy.real < tmp.real:
wn += (
1
if p[j].imag < xy.imag <= p[i].imag
else -1 if p[i].imag < xy.imag <= p[j].imag else 0
)
return wn
n = int(readline())
p = [map(int, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
q = int(readline())
for _ in range(q):
x, y = map(int, readline().split())
xy = x + y * 1j
print(1 if on_polygon_line(xy, p) else 2 if in_polygon(xy, p) else 0)
| Polygon-Point-Containment
For a given polygon g and target points t, print "2" if g contains t, "1" if t
is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex. | [{"input": "0 0\n 3 1\n 2 3\n 0 3\n 3\n 2 1\n 0 2\n 3 2", "output": "1\n 0"}] |
For each query, print "2", "1" or "0". | s259307227 | Accepted | p02299 | The entire input looks like:
g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query
g is given by coordinates of the points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of a point pi is
given by two integers xi and yi. The coordinates of points are given in the
order of counter-clockwise visit of them.
Each query consists of the coordinate of a target point t. The coordinate is
given by two intgers x and y. | import math
from typing import Union, Tuple
class Point(object):
__slots__ = ["x", "y"]
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other: Union[int, float]):
return Point(self.x * other, self.y * other)
def norm(self):
return pow(self.x, 2) + pow(self.y, 2)
def abs(self):
return math.sqrt(self.norm())
def __repr__(self):
return f"({self.x},{self.y})"
class Vector(Point):
__slots__ = ["x", "y", "pt1", "pt2"]
def __init__(self, pt1: Point, pt2: Point):
super().__init__(pt2.x - pt1.x, pt2.y - pt1.y)
self.pt1 = pt1
self.pt2 = pt2
def dot(self, other):
return self.x * other.x + self.y * other.y
def cross(self, other):
return self.x * other.y - self.y * other.x
def arg(self) -> float:
return math.atan2(self.y, self.x)
@staticmethod
def polar(r, theta) -> Point:
return Point(r * math.cos(theta), r * math.sin(theta))
def __repr__(self):
return f"({self.x},{self.y})"
class Segment(Vector):
__slots__ = ["x", "y", "pt1", "pt2"]
def __init__(self, pt1: Point, pt2: Point):
super().__init__(pt1, pt2)
def projection(self, pt: Point) -> Point:
t = self.dot(Vector(self.pt1, pt)) / self.norm()
return self.pt1 + self * t
def reflection(self, pt: Point) -> Point:
return self.projection(pt) * 2 - pt
def is_intersected_with(self, other) -> bool:
if (
self.point_geometry(other.pt1) * self.point_geometry(other.pt2)
) <= 0 and other.point_geometry(self.pt1) * other.point_geometry(self.pt2) <= 0:
return True
else:
return False
def point_geometry(self, pt: Point) -> int:
"""
[-2:"Online Back", -1:"Counter Clockwise", 0:"On Segment", 1:"Clockwise", 2:"Online Front"]
"""
vec_pt1_to_pt = Vector(self.pt1, pt)
cross = self.cross(vec_pt1_to_pt)
if cross > 0:
return -1 # counter clockwise
elif cross < 0:
return 1 # clockwise
else: # cross == 0
dot = self.dot(vec_pt1_to_pt)
if dot < 0:
return -2 # online back
else: # dot > 0
if self.abs() < vec_pt1_to_pt.abs():
return 2 # online front
else:
return 0 # on segment
def cross_point(self, other) -> Point:
d1 = abs(self.cross(Vector(self.pt1, other.pt1))) # / self.abs()
d2 = abs(self.cross(Vector(self.pt1, other.pt2))) # / self.abs()
t = d1 / (d1 + d2)
return other.pt1 + other * t
def distance_to_point(self, pt: Point) -> Union[int, float]:
vec_pt1_to_pt = Vector(self.pt1, pt)
if self.dot(vec_pt1_to_pt) <= 0:
return vec_pt1_to_pt.abs()
vec_pt2_to_pt = Vector(self.pt2, pt)
if Vector.dot(self * -1, vec_pt2_to_pt) <= 0:
return vec_pt2_to_pt.abs()
return (self.projection(pt) - pt).abs()
def distance_to_segment(self, other) -> Union[int, float]:
if self.is_intersected_with(other):
return 0.0
else:
return min(
self.distance_to_point(other.pt1),
self.distance_to_point(other.pt2),
other.distance_to_point(self.pt1),
other.distance_to_point(self.pt2),
)
def __repr__(self):
return f"{self.pt1},{self.pt2}"
class Circle(Point):
__slots__ = ["x", "y", "r"]
def __init__(self, x, y, r):
super().__init__(x, y)
self.r = r
def cross_point_with_circle(self, other) -> Tuple[Point, Point]:
vec_self_to_other = Vector(self, other)
vec_abs = vec_self_to_other.abs()
# if vec_abs > (self.r + other.r):
# raise AssertionError
t = ((pow(self.r, 2) - pow(other.r, 2)) / pow(vec_abs, 2) + 1) / 2
pt = (other - self) * t
abs_from_pt = math.sqrt(pow(self.r, 2) - pt.norm())
inv = (
Point(vec_self_to_other.y / vec_abs, -vec_self_to_other.x / vec_abs)
* abs_from_pt
)
pt_ = self + pt
return (pt_ + inv), (pt_ - inv)
def cross_point_with_circle2(self, other) -> Tuple[Point, Point]:
vec_self_to_other = Vector(self, other)
vec_abs = vec_self_to_other.abs()
# if vec_abs > (self.r + other.r):
# raise AssertionError
theta_base_to_other = vec_self_to_other.arg()
theta_other_to_pt = math.acos(
(pow(self.r, 2) + pow(vec_abs, 2) - pow(other.r, 2))
/ (2 * self.r * vec_abs)
)
return self + Vector.polar(
self.r, theta_base_to_other + theta_other_to_pt
), self + Vector.polar(self.r, theta_base_to_other - theta_other_to_pt)
def __repr__(self):
return f"({self.x},{self.y}), {self.r}"
class Polygon(object):
def __init__(self, vertices):
self.vertices = vertices
self.num_vertices = len(vertices)
def contains_point(self, pt: Point) -> int:
"""
{0:"not contained", 1: "on a edge", 2:"contained"}
"""
cross_count = 0
for i in range(self.num_vertices):
vec_a = Vector(pt, self.vertices[i])
vec_b = Vector(pt, self.vertices[(i + 1) % self.num_vertices])
if vec_a.y > vec_b.y:
vec_a, vec_b = vec_b, vec_a
dot = vec_a.dot(vec_b)
cross = vec_a.cross(vec_b)
# print("pt", pt, "vtx", self.vertices[i], self.vertices[(i+1) % self.num_vertices], "vec", vec_a, vec_b, "dot", dot, "cross", cross)
if math.isclose(cross, 0.0) and dot <= 0:
return 1 # on a edge
elif vec_a.y <= 0.0 < vec_b.y and cross > 0:
cross_count += 1
return [0, 2][cross_count % 2]
def __repr__(self):
return f"{self.vertices}"
def main():
num_vertices = int(input())
polygon_vertices = []
for i in range(num_vertices):
pt_x, pt_y = map(int, input().split())
polygon_vertices.append(Point(pt_x, pt_y))
polygon = Polygon(polygon_vertices)
num_queries = int(input())
for i in range(num_queries):
pt_x, pt_y = map(int, input().split())
ret = polygon.contains_point(Point(pt_x, pt_y))
print(ret)
return
main()
| Polygon-Point-Containment
For a given polygon g and target points t, print "2" if g contains t, "1" if t
is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line
segment connecting pn and p1 is also a side of the polygon.
Note that the polygon is not necessarily convex. | [{"input": "0 0\n 3 1\n 2 3\n 0 3\n 3\n 2 1\n 0 2\n 3 2", "output": "1\n 0"}] |
For each query of type 2, print a line containing the answer.
* * * | s607343140 | Runtime Error | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | from collections import Counter
def main():
n = int(input().strip())
s = list(input().strip())
bit = [Counter() for _ in range(n + 1)]
def query(i):
result = Counter()
while i:
result += bit[i]
i -= i & -i
return result
def update(i, cnt):
while i < len(bit):
bit[i] += cnt
i += i & -i
for i, c in enumerate(s, 1):
update(i, {c: 1})
q = int(input().strip())
for _ in range(q):
Q = input().strip().split()
if Q[0] == "1":
i, c = int(Q[1]), Q[2]
update(i, {s[i - 1]: -1, c: 1})
s[i - 1] = c
else:
cnt = query(int(Q[2])) - query(int(Q[1]) - 1)
print(len(cnt))
main()
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s622072558 | Accepted | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
seg_unit = 0
def seg_f(x, y):
return x | y
def build(seg, raw_data):
N = len(seg) // 2
seg[N:] = raw_data
for i in range(N - 1, 0, -1):
seg[i] = seg_f(seg[i << 1], seg[i << 1 | 1])
def set_val(seg, i, x):
N = len(seg) // 2
i += N
seg[i] = x
while i > 1:
i >>= 1
seg[i] = seg_f(seg[i << 1], seg[i << 1 | 1])
def fold(seg, l, r):
vl = vr = 0
N = len(seg) // 2
l, r = l + N, r + N
while l < r:
if l & 1:
vl = seg_f(vl, seg[l])
l += 1
if r & 1:
r -= 1
vr = seg_f(seg[r], vr)
l, r = l >> 1, r >> 1
return seg_f(vl, vr)
def main(N, S, query):
seg = np.zeros(N + N, np.int64)
build(seg, 1 << S)
for q in query:
t, a, b = q.split()
if t == b"1":
a, b = int(a) - 1, ord(b) - ord("a")
set_val(seg, a, 1 << b)
else:
a, b = int(a) - 1, int(b)
x = fold(seg, a, b)
print(bin(x).count("1"))
if sys.argv[-1] == "ONLINE_JUDGE":
import numba
from numba.pycc import CC
i8 = numba.int64
cc = CC("my_module")
def cc_export(f, signature):
cc.export(f.__name__, signature)(f)
return numba.njit(f)
seg_f = cc_export(seg_f, (i8, i8))
build = cc_export(build, (i8[:], i8[:]))
set_val = cc_export(set_val, (i8[:], i8, i8))
fold = cc_export(fold, (i8[:], i8, i8))
cc.compile()
from my_module import seg_f, build, set_val, fold
N = int(readline())
S = np.array(list(readline().rstrip()), np.int64) - ord("a")
query = readlines()[1:]
main(N, S, query)
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s555923705 | Runtime Error | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | #!/usr/bin/env python3
import sys
DEBUG = False
class SegmentTree:
def __init__(self, n):
self.n = 1
while self.n < n:
self.n *= 2
self.fillval = 0
self.nodes = [0 for _ in range(self.n)]
def update(self, idx, val):
nodes = self.nodes
idx += self.n - 1
nodes[idx] = val
while idx > 0:
idx = (idx - 1) // 2
nodes[idx] = nodes[idx * 2 + 1] | nodes[idx * 2 + 2]
def query(self, l, r):
fillval = self.fillval
nodes = self.nodes
def _query(l, r, scope_idx, scope_l, scope_r):
if r <= scope_l or l >= scope_r:
return fillval
if l <= scope_l and r >= scope_r:
return nodes[scope_idx]
vl = _query(l, r, scope_idx * 2 + 1, scope_l, (scope_l + scope_r) // 2)
vr = _query(l, r, scope_idx * 2 + 2, (scope_l + scope_r) // 2, scope_r)
return vl | vr
return _query(l, r, 0, 0, self.n)
def read(t=str):
return t(sys.stdin.readline().rstrip())
def read_list(t=str, sep=" "):
return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]
def dprint(*args, **kwargs):
if DEBUG:
print(*args, **kwargs)
return
class LetterAppearance:
def __init__(self, chars):
self.chars_app = SegmentTree(len(chars))
for i in range(0, len(chars)):
bit = ord(chars[i]) - ord("a")
self.chars_app.update(i, 1 << bit)
def replace(self, pos, char):
bit = ord(char) - ord("a")
self.chars_app.update(pos, 1 << bit)
def query(self, l, r):
return bin(self.chars_app.query(l, r)).count("1")
def main():
read()
s = read()
apps = LetterAppearance(s)
nr_q = read(int)
for i in range(0, nr_q):
q = read_list()
if q[0] == "1":
_, i, c = q # i_q in the question starts from 1, not 0
apps.replace(int(i) - 1, c)
else:
_, l, r = q # l_q and r_q in the question start from 1, not 0
print(
apps.query(int(l) - 1, int(r) - 1 + 1)
) # query in the question includes both edges
if __name__ == "__main__":
main()
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s264967282 | Runtime Error | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | import sys
N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]
CD = [list(map(int, input().split())) for i in range(K)]
# xの木の根を求める
def root(x, li):
if li[x] == x:
return x
else:
li[x] = root(li[x], li)
return li[x]
# xとyが同じ集合に属するかの判定
def find(x, y, li):
return root(x, li) == root(y, li)
# xとyを併合
def union(x, y, li):
x = root(x, li)
y = root(y, li)
if x == y:
return
else:
li[x] = y
li1 = [i for i in range(N)]
li2 = [i for i in range(N)]
for i in range(M):
a = AB[i][0]
b = AB[i][1]
union(a - 1, b - 1, li1)
# for i in range(K):
# c = CD[i][0]
# d = CD[i][1]
# union(c-1,d-1,li2)
sys.exit()
mm = [0 for i in range(max(li1))]
for i in range(N):
m = root(i, li1)
mm[m - 1] += 1
# print(li1)
# print(mm)
ans = [mm[li1[i] - 1] - 1 for i in range(N)]
# print(ans)
for i in range(M):
a = AB[i][0]
b = AB[i][1]
ans[a - 1] -= 1
ans[b - 1] -= 1
for i in range(K):
c = CD[i][0]
d = CD[i][1]
if find(c - 1, d - 1, li1):
ans[c - 1] -= 1
ans[d - 1] -= 1
print(*ans)
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s920188417 | Runtime Error | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | import sys
sys.setrecursionlimit(10**9)
def dfs(x, seen):
seen.add(x)
for i in G[x]:
if i in seen:
continue
dfs(i, seen)
N, M, K = map(int, input().split())
S = set()
G = [[] for i in range(N)]
for _ in range(M):
A, B = map(int, input().split())
A -= 1
B -= 1
G[A].append(B)
G[B].append(A)
S.add(A)
S.add(B)
R = []
while len(S) != 0:
seen = set()
dfs(S.pop(), seen)
R.append(seen)
S = S - seen
Block = [set() for i in range(N)]
for _ in range(K):
C, D = map(int, input().split())
Block[C - 1].add(D - 1)
Block[D - 1].add(C - 1)
seq = [0] * N
for r in R:
lr = len(r)
for j in r:
seq[j] = lr - len(G[j]) - len(r & Block[j]) - 1
print(*seq)
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s702405909 | Runtime Error | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | # import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
# n = int(input())
mod = 10**9 + 7
a.sort(reverse=True)
# print(a)
ans = 0
def C(n, k, mod):
if k == 0:
return 1
elif n < k or k < 0:
return 0
else:
x, y = 1, 1
while k > 0:
x *= n
y *= k
n, k = n - 1, k - 1
return x * pow(y, mod - 2, mod) % mod
for i in range(0, n - k + 1):
ans += a[i] * C(n - i - 1, k - 1, mod)
ans %= mod
a.reverse()
for i in range(0, n - k + 1):
ans -= a[i] * C(n - i - 1, k - 1, mod)
ans %= mod
print(ans)
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s647841431 | Wrong Answer | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | N = int(input())
S = input()
s = []
A = [[] for i in range(26)]
for i in range(N):
x = S[i]
s.append(x)
n = ord(x) - 97
A[n].append(i)
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s988293852 | Accepted | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | 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()))
def main():
class Segtree:
def __init__(self, A, ide_ele, initialize=True, segf=max):
self.N = len(A)
self.N0 = 2 ** (self.N - 1).bit_length()
self.ide_ele = ide_ele
self.segf = segf
if initialize:
self.data = [ide_ele] * self.N0 + A + [ide_ele] * (self.N0 - self.N)
for i in range(self.N0 - 1, 0, -1):
self.data[i] = self.segf(self.data[2 * i], self.data[2 * i + 1])
else:
self.data = [ide_ele] * (2 * self.N0)
def update(self, k, x):
k += self.N0
self.data[k] = x
while k > 0:
k = k >> 1
self.data[k] = self.segf(self.data[2 * k], self.data[2 * k + 1])
def query(self, l, r):
L, R = l + self.N0, r + self.N0
s = self.ide_ele
t = self.ide_ele
while L < R:
if R & 1:
R -= 1
t = self.segf(self.data[R], t)
if L & 1:
s = self.segf(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return self.segf(s, t)
# セグ木上で二分探索,[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す.
# reverse=Trueなら最大値かな
# ない時の返り値がNoneなことに注意
def binsearch(self, l, r, check, reverse=False):
L, R = l + self.N0, r + self.N0
SL, SR = [], []
while L < R:
if R & 1:
R -= 1
SR.append(R)
if L & 1:
SL.append(L)
L += 1
L >>= 1
R >>= 1
if reverse:
pre = self.ide_ele
for idx in SR + SL[::-1]:
if check(self.segf(self.data[idx], pre)):
break
else:
pre = self.segf(self.data[idx], pre)
else:
return None
while idx < self.N0:
if check(self.segf(self.data[2 * idx + 1], pre)):
idx = 2 * idx + 1
else:
pre = self.segf(self.data[2 * idx + 1], pre)
idx = 2 * idx
return idx - self.N0
else:
pre = self.ide_ele
for idx in SL + SR[::-1]:
if not check(self.segf(pre, self.data[idx])):
pre = self.segf(pre, self.data[idx])
else:
break
else:
return None
while idx < self.N0:
if check(self.segf(pre, self.data[2 * idx])):
idx = 2 * idx
else:
pre = self.segf(pre, self.data[2 * idx])
idx = 2 * idx + 1
return idx - self.N0
N = I()
S = input()
Q = I()
A = []
for i in range(N):
aaa = set(S[i])
A.append(aaa)
seg = Segtree(A, set([]), segf=lambda a, b: a | b)
for _ in range(Q):
q = input().split()
if q[0] == "1":
i = int(q[1]) - 1
c = q[2]
seg.update(i, set([c]))
else:
l = int(q[1])
r = int(q[2])
ans = seg.query(l - 1, r)
print(len(ans))
main()
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s926324683 | Accepted | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | class SegmentTree:
def __init__(self, initial_values, f=max, zero=0):
self.__size = len(initial_values)
self.__n = 1 << ((self.__size - 1).bit_length())
self.__f = f
self.__z = zero
self.__dat = [zero] * (2 * self.__n)
self.__get_leaf = lambda i: self.__n + i - 1
self.__get_parent = lambda i: (i - 1) // 2
self.__get_children = lambda i: (self.__dat[2 * i + 1], self.__dat[2 * i + 2])
self.__is_left = lambda i: i & 1 == 1
self.__is_right = lambda i: i & 1 == 0
zi = self.__get_leaf(0)
dat, get_children = self.__dat, self.__get_children
for i, v in enumerate(initial_values):
dat[zi + i] = v
for i in range(zi - 1, -1, -1):
dat[i] = f(*get_children(i))
def update(self, index, value):
f, dat, get_leaf, get_parent, get_children = (
self.__f,
self.__dat,
self.__get_leaf,
self.__get_parent,
self.__get_children,
)
i = get_leaf(index)
if dat[i] == value:
return
dat[i] = value
while i > 0:
i = get_parent(i)
dat[i] = f(*get_children(i))
def query(self, from_inclusive, to_exclusive):
f, z, dat, get_leaf, get_parent, is_left, is_right = (
self.__f,
self.__z,
self.__dat,
self.__get_leaf,
self.__get_parent,
self.__is_left,
self.__is_right,
)
if to_exclusive <= from_inclusive:
return z
a, b = get_leaf(from_inclusive), get_leaf(to_exclusive) - 1
ans = z
while b - a > 1:
if is_right(a):
ans = f(ans, dat[a])
if is_left(b):
ans, b = f(ans, dat[b]), b - 1
a, b = a // 2, get_parent(b)
ans = f(ans, dat[a])
if a != b:
ans = f(ans, dat[b])
return ans
N = int(input())
S = input()
g = lambda c: 1 << (ord(c) - ord("a"))
tree = SegmentTree([g(c) for c in S], lambda x, y: x | y)
Q = int(input())
for _ in range(Q):
t, a, b = input().split()
if t == "1":
tree.update(int(a) - 1, g(b))
else:
print(bin(tree.query(int(a) - 1, int(b))).count("1"))
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s614772875 | Accepted | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | n = int(input())
s = input()
# 初期化
ind = 1
while 2**ind <= n:
ind += 1
s += "*" * (2**ind - n)
seg = []
seg2 = []
from collections import deque
tmp = deque([s])
while len(tmp) > 0:
t = tmp.popleft()
cnt = 0
for ss in t:
if ss != "*":
cnt = cnt | 2 ** (ord(ss) - 97)
seg.append(cnt)
seg2.append(t)
if len(t) > 1:
tmp.append(t[: len(t) // 2])
tmp.append(t[len(t) // 2 :])
# セグ木が出来た!
# print(seg)
# print(seg2)
q = int(input())
def change(i, s):
# i文字目をsに変更する
# nの親は(n-1)//2
# nの子は2n+1,2n+2
global n, seg, ind
ii = len(seg) - 2**ind + i - 1
seg[ii] = 2 ** (ord(s) - 97)
p = (ii - 1) // 2
while 1:
seg[p] = seg[2 * p + 1] | seg[2 * p + 2]
if p == 0:
break
p = (p - 1) // 2
# print(seg)
from collections import deque
def count(l, r):
global n, seg, s
# nの親は(n-1)//2
# nの子は2n+1,2n+2
d = deque([(1, len(s), 0)])
ans = 0
while len(d) > 0:
tmp = d.popleft()
# print(tmp)
ll, rr, i = tmp[0], tmp[1], tmp[2]
if l <= ll and rr <= r:
ans = ans | seg[i]
elif (ll <= l and l <= rr) or (ll <= r and r <= rr):
d.append((ll, ll + (rr - ll) // 2, 2 * i + 1))
d.append((ll + (rr - ll) // 2 + 1, rr, 2 * i + 2))
return str(bin(ans)).count("1")
result = []
for _ in range(q):
b, i, c = map(str, input().split())
if b == "1":
# i文字目をcに変更
change(int(i), c)
else:
# l文字目からr文字目までに含まれる数
result.append(count(int(i), int(c)))
for item in result:
print(item)
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s846514707 | Wrong Answer | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | N = int(input())
S = list(input())
Q = int(input())
# print(S) 012345
do = [input().split() for i in range(Q)]
answer = []
check = []
# print(do)
for i in range(Q):
if int(do[i][0]) == 1:
S[int(do[i][1]) - 1] = do[i][2]
# print(S)###
else:
for j in range(int(do[i][1]) - 1, int(do[i][2])):
check.append(S[j])
check.sort()
# print(check)####
while True:
q = 0
for k in range(len(check) - 2):
if check[k] == check[k + 1]:
trash = check.pop(k)
# print(check)###
q = 1
break
if q == 0:
break
# print(check)#####
answer.append(len(check))
check = []
# print(answer)#####
kotae = ""
for h in range(len(answer)):
print(answer[h])
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
For each query of type 2, print a line containing the answer.
* * * | s596030032 | Runtime Error | p02763 | Input is given from Standard Input in the following format:
N
S
Q
Query_1
\vdots
Query_Q
Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:
1 i_q c_q
2 l_q r_q | N = int(input())
S = input()
Q = int(input())
a = list()
for i in range(0, Q):
a.append(0)
for i in range(0, Q):
a[i] = input()
for i in range(0, Q):
if int(a[i][0]) == 1:
S = S[0 : int(a[i][2])] + a[i][4] + S[int(a[i][2]) + 1 : N]
if int(a[i][0]) == 2:
b = set(list(S[int(a[i][2]) - 1 : int(a[i][4])]))
print(len(b))
| Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
* Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
* Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive). | [{"input": "7\n abcdbbd\n 6\n 2 3 6\n 1 5 z\n 2 1 1\n 1 4 a\n 1 7 d\n 2 1 7", "output": "3\n 1\n 5\n \n\nIn the first query, `cdbb` contains three kinds of letters: `b` , `c` , and\n`d`, so we print 3.\n\nIn the second query, S is modified to `abcdzbd`.\n\nIn the third query, `a` contains one kind of letter: `a`, so we print 1.\n\nIn the fourth query, S is modified to `abcazbd`.\n\nIn the fifth query, S does not change and is still `abcazbd`.\n\nIn the sixth query, `abcazbd` contains five kinds of letters: `a`, `b`, `c`,\n`d`, and `z`, so we print 5."}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s521325918 | Accepted | p03488 | Input is given from Standard Input in the following format:
s
x y | # 盤面座標は8000x8000(x 2)
N = 8000
s = input()
target_x, target_y = map(int, input().split())
# "FTTFF" -> [1, 0, 2]と変換。'F1TF0TF2T'のFだけとる
dat_f = [len(Fcount) for Fcount in s.split("T")]
# マイナスを含むxとyのDP用配列(=x2)を作る +1するのは原点用
# x, yの閾値判定するのが面倒なので倍(=x2)用意する(index error対策)
curmap_x = [False] * ((N * 2 * 2) + 1)
curmap_y = [False] * ((N * 2 * 2) + 1)
nextmap_x = [False] * ((N * 2 * 2) + 1)
nextmap_y = [False] * ((N * 2 * 2) + 1)
# 初期座標 0,0なのだが、最初Fから始まる場合は(x,0)から始まるし、y軸を向きながら処理する
if s[0] == "F":
start = 1
curmap_x[N * 2 + dat_f[0]] = True
direction_x = False
else:
start = 0
curmap_x[N * 2] = True
direction_x = True
# y=0
curmap_y[N * 2] = True
# 処理すべき最初のFから
for i in range(start, len(dat_f)):
step = dat_f[i]
if direction_x:
for j in range(N, N + (N * 2) + 1):
nextmap_x[j] = True if curmap_x[j - step] or curmap_x[j + step] else False
curmap_x, nextmap_x = nextmap_x, curmap_x
else:
for j in range(N, N + (N * 2) + 1):
nextmap_y[j] = True if curmap_y[j - step] or curmap_y[j + step] else False
curmap_y, nextmap_y = nextmap_y, curmap_y
# くる
direction_x = not direction_x
print("Yes" if curmap_x[N * 2 + target_x] and curmap_y[N * 2 + target_y] else "No")
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s930914312 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y | s = input()
x,y = map(int,input().split())
cur_x = 0
cur_y = 0
L_x = []
L_y = []
s += 'K'
temp = 0
dirc = 'yoko'
for i in range(len(s)):
if s[i] == 'F':
temp += 1
elif s[i] == 'T':
if temp == 0:
if dirc == 'yoko':
dirc = 'tate'
else:
dirc = 'yoko'
else:
if dirc == 'yoko':
L_x.append(temp)
temp = 0
dirc = 'tate'
else:
L_y.append(temp)
temp = 0
dirc = 'yoko'
else:
if temp != 0:
if dirc == 'yoko':
L_x.append(temp)
temp = 0
dirc = 'tate'
else:
L_y.append(temp)
temp = 0
dirc = 'yoko'
dp_x = [[False]*8001 for i in range(len(L_x)+1)]
dp_y = [[False]*8001 for i in range(len(L_y)+1)]
dp_x[0][0] = True
dp_y[0][0] = True
if s[0] != 'F':
for i in range(1,len(L_x)+1):
for j in range(8001):
if j+L_x[i-1] <= 8000:
dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])] or dp_x[i-1][j+L_x[i-1]]
else:
dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])]
for i in range(1,len(L_y)+1):
for j in range(8001):
if j+L_y[i-1] <= 8000:
dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
else:
dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
if dp_x[len(L_x)][abs(x)] == True and dp_y[len(L_y)][abs(y)] == True:
print('Yes')
else:
print('No')
else:
for i in range(2,len(L_x)+1):
for j in range(8001):
if j+L_x[i-1] <= 8000:
dp_x[i-1][j] = dp_x[i-2][abs(j-L_x[i-1])] or dp_x[i-2][j+L_x[i-1]]
else:
dp_x[i-1][j] = dp_x[i-2][abs(j-L_x[i-1])]
for i in range(1,len(L_y)+1):
for j in range(8001):
if j+L_y[i-1] <= 8000:
dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
else:
dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
if 1 == 2
print('Yes')
else:
print('No') | Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s746800342 | Accepted | p03488 | Input is given from Standard Input in the following format:
s
x y | #
# ,. -─────────‐- .、
# // ̄ ̄\ / ̄ ̄\\
# / \
# / :::::::::::::::::::::::::::::::: \
# / / / ̄\\::::;;;;;;;;;;;;;;;;;:::::// ̄\\ \
# / | |. ┃ .| | ::::;;;;;;;;;;;;;::::| |. ┃ .| | \
# / \ \_// :::::::::::::::::: \\_// \
# / ../ ̄ ̄\ / ::|:: \ / ̄ ̄\.. \
# / ::::: | | | ::::: ヽ.
# | | | | |.
# | \__/\__/ |
# | | | |
# | |r─‐┬──、| |
# ヽ |/ | | /
# \ \ / /
# \  ̄ ̄ ̄ ̄ /
#
#
import sys
input = sys.stdin.readline
inf = float("inf")
mod = 10**9 + 7
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [input() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
def main():
S = ST()
x, y = MI()
to_x_y = [[], []]
deleted = False
for i, s in enumerate(S):
if s == "T":
S = S[i:]
deleted = True
break
else:
x -= 1
if not deleted:
S = ""
toY = False
contin = False
# run length
for i, s in enumerate(S):
if s == "F":
if contin:
to_x_y[toY][-1] += 1
else:
to_x_y[toY].append(1)
contin = True
else:
toY = not toY
contin = False
# print((x,y),*to_x_y,sep="\n")
# xについてdp
now_x = set([0])
for distanse in to_x_y[0]:
next_x = set()
for i, X in enumerate(now_x):
next_x.add(X + distanse)
next_x.add(X - distanse)
now_x = next_x
# yについてdp
now_y = set([0])
for distanse in to_x_y[1]:
next_y = set()
for i, Y in enumerate(now_y):
next_y.add(Y + distanse)
next_y.add(Y - distanse)
now_y = next_y
# print(now_x,now_y)
print("YNeos"[x not in now_x or y not in now_y :: 2])
if __name__ == "__main__":
main()
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s193385441 | Wrong Answer | p03488 | Input is given from Standard Input in the following format:
s
x y | def examD():
St = S()
X, Y = LI()
N = len(St)
ans = "No"
Fx = deque()
Fy = deque()
ve = int(1)
cur = int(0)
for i in range(N):
if St[i] == "F":
cur += 1
else:
if ve == 1:
Fx.append(cur)
cur = int(0)
ve *= -1
else:
Fy.append(cur)
cur = int(0)
ve *= -1
if ve == 1:
Fx.append(cur)
cur = int(0)
else:
Fy.append(cur)
cur = int(0)
xfirst = Fx.popleft()
X = X - xfirst
# print(Fx)
# print(Fy)
xlen = len(Fx)
ylen = len(Fy)
xneed = -1
yneed = -1
if (sum(Fx) - X) % 2 == 0:
xneed = (sum(Fx) - X) // 2
if (sum(Fy) - Y) % 2 == 0:
yneed = (sum(Fy) - Y) // 2
# print(xneed)
dp = [[0] * (xneed + 1) for _ in range(xlen + 1)]
if xneed > 0:
dp[0][0] = 1
for i in range(xlen):
for j in range(max(xneed + 1, 0)):
if dp[i][j] != 0:
if xneed + 1 - Fx[i] > j:
dp[i + 1][j + Fx[i]] = dp[i][j]
dp[i + 1][j] = dp[i][j]
# print(dp)
# print(dp[xlen][xneed])
if (xneed > 0 and dp[xlen][xneed] == 1) or xneed == 0:
dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
for i in range(yneed + 1):
dp[0][i] = 1
for i in range(ylen):
for j in range(max(yneed + 1, 0)):
if dp[i][j] != 0:
if yneed + 1 - Fy[i] > j:
dp[i + 1][j + Fy[i]] = dp[i][j]
dp[i + 1][j] = dp[i][j]
if (yneed > 0 and dp[ylen][yneed] == 1) or yneed == 0:
ans = "Yes"
print(ans)
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def S():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
examD()
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s772642082 | Wrong Answer | p03488 | Input is given from Standard Input in the following format:
s
x y | import sys
input = sys.stdin.readline
s = input().rstrip()
x, y = [int(x) for x in input().split()]
horizontal = []
vertical = []
switch = 1
distance = 0
for i in range(len(s)):
if s[i] == "F":
distance += 1
elif switch:
horizontal.append(distance)
distance = 0
switch ^= 1
else:
vertical.append(distance)
distance = 0
switch ^= 1
if switch:
horizontal.append(distance)
else:
vertical.append(distance)
x_error = sum(horizontal) - abs(x)
y_error = sum(vertical) - abs(y)
if x_error < 0 or y_error < 0:
print("No")
exit()
elif x_error == 0 and y_error == 0:
print("Yes")
exit()
dp_x = [
[[0, 0] for _ in range(2 * (x_error + 1) - 1)] for _ in range(len(horizontal) + 1)
]
dp_y = [
[[0, 0] for _ in range(2 * (y_error + 1) - 1)] for _ in range(len(vertical) + 1)
]
dp_x[0][0 + x_error] = [1, 1]
dp_y[0][0 + y_error] = [1, 1]
for i in range(1, len(horizontal) + 1):
x_ = horizontal[i - 1]
for j in range(-x_error, x_error + 1):
for k in range(2):
if not k:
x_ *= -1
if -x_error <= j - x_ <= x_error:
dp_x[i][j][k] = max(
max(dp_x[i - 1][j + x_error]), max(dp_x[i - 1][j - x_ + x_error])
)
else:
dp_x[i][j][k] = max(dp_x[i - 1][j + x_error])
for i in range(1, len(vertical) + 1):
x_ = vertical[i - 1]
for j in range(-y_error, y_error + 1):
for k in range(2):
if not k:
x_ *= -1
if -y_error <= j - x_ <= y_error:
dp_y[i][j][k] = max(
max(dp_y[i - 1][j + y_error]), max(dp_y[i - 1][j - x_ + y_error])
)
else:
dp_y[i][j][k] = max(dp_y[i - 1][j + y_error])
if max(dp_x[-1][-1]) and max(dp_y[-1][-1]):
print("Yes")
else:
print("No")
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s962789194 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y | S = input()
X, Y = map(int, input().split())
def run_length(s) -> list:
res = [[s[0], 1]]
for i in range(1, len(s)):
if res[-1][0] == s[i]:
res[-1][1] += 1
else:
res.append([s[i], 1])
return res
RL = run_length(S)
if RL[0][0] == 'T':
RL = [['F', 0]] + RL
SIZE = len(S)
nx = 1 << SIZE
ny = 1 << SIZE
x_flag = 1
for i in range(0, len(RL), 2):
s, l = RL[i]
if i == 0:
nx = nx << l
else:
x_flag = (x_flag + RL[i - 1][1]) % 2
if x_flag:
nx = (nx << l) | (nx >> l)
else:
ny = (ny << l) | (ny >> l)
if ((nx >> (SIZE + X)) & 1) & ((ny >> (SIZE + Y)) & 1):
print("Yes")
else:
print("No") | Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s487957880 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y | import sys
input = sys.stdin.readline
s = list(input())
x, y = map(int, input().split())
y = abs(y)
s.append('T')
x1 = []
y1 = []
count = 0
u = 0
for i in range(len(s)):
if s[i] == 'F':
count += 1
else:
if u % 2 == 0:
x1.append(count)
u += 1
count = 0
else:
y1.append(count)
u += 1
count = 0
v = sum(x1)
w = sum(y1)
if v < x or w < y:
print('No')
exit()
dpx = [[0 for i in range(v + 1)] for j in range(len(x1) + 1)]
dpx[0][-1] = 1
x -= x1[0]
x1[0] = 0
v-=x1[0]
x=abs(x)
for i in range(len(x1)):
for j in range(v + 1):
if dpx[i][j] == 1:
if j - 2 * x1[i] >= 0:
dpx[i + 1][j - 2 * x1[i]] = 1
dpx[i + 1][j] = 1
if len(y1) == 0:
y1.append(0)
dpy = [[0 for i in range(w + 1)] for j in range(len(y1) + 1)]
dpy[0][-1] = 1
for i in range(len(y1)):
for j in range(w + 1):
if dpy[i][j] == 1:
if j - 2 * y1[i] >= 0:
dpy[i + 1][j - 2 * y1[i]] = 1
dpy[i + 1][j] = 1
if dpy[-1][y] == 1 and dpx[-1][x] == 1:
print('Yes')
else:
print('No') | Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s910692063 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y | #FT robot
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
for i in range(len(lists)):
if i%2==0:
xlist.append(len(lists[i]))
else:
ylist.append(len(lists[i]))
elif s[0]=="F":
for i in range(len(lists)):
if i%2==0:
xlist.append(len(lists[i]))
else:
ylist.append(len(lists[i]))
gx-=xlist[0]
del xlist[0]
Xsum=sum(xlist)
Ysum=sum(ylist)
if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
print("No")
else:
gx1=(Xsum+gx)//2
gx2=(Xsum-gx)//2
gy1=(Ysum+gy)//2
gy2=(Ysum-gy)//2
dpx=[[False for i in range(Xsum+2)] for j in range(len(xlist)+2)]
dpy=[[False for i in range(Ysum+2)] for j in range(len(ylist)+2)]
#dpx[i][j]でi番目のカードまでを足して、値jを取れるか判定する
dpx[0][0]=True
dpy[0][0]=True
for i in range(len(xlist)):
for j in range(Xsum+2):
dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
for i in range(len(ylist)):
for j in range(Ysum+2):
dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]
#ここまではあってそうなことがわかった
if ((0<=gy1<= Ysum and dpy[len(ylist)][gy1]) or ((0<=gy2<= Ysum and dpy[len(ylist)][gy2]) :
if ((0<=gx1<= Xsum and dpx[len(xlist)][gx1]) or ((0<=gx2<= Xsum and dpx[len(xlist)][gx2]) :
print("Yes")
else:
print("No")
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s847839680 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y | def solve():
S = input()
X,Y = map(int, input().split())
S_F = S.split('T')
move_x = list(map(len, S_F[::2]))
move_y = list(map(len,S_F[1::2]))
# たどりつけない場合
if sum(move_x) < abs(X) or sum(move_y) < abs(Y):
print('No')
return
# →移動しかできない場合
if not move_y and len(move_x) == 1
if sum(move_x) == X and Y == 0:
print('Yes')
return
if not move_y:
print('No')
return
move_x_process = [mx for mx in move_x if mx > 0]
move_y_process = [my for my in move_y if my > 0]
X = abs(X); Y = abs(Y)
len_move_x = len(move_x_process)
sum_x = sum(move_x_process)
len_move_y = len(move_y_process)
sum_y = sum(move_y_process)
dp_table = [[False for _ in range(sum_x+1)] for _ in range(len_move_x+1)]
dp_table[0][0] = True
for i in range(0,len_move_x):
for j in range(0, sum_x+1):
dp_table[i+1][j] = dp_table[i][abs(j-move_x_process[i])]
if j+move_x_process[i] <= sum_x:
dp_table[i+1][j] = dp_table[i+1][j] or dp_table[i][j+move_x_process[i]]
# print(dp_table)
ret = dp_table[len_move_x][X]
dp_table = [[False for _ in range(sum_y+1)] for _ in range(len_move_y+1)]
dp_table[0][0] = True
for i in range(0,len_move_y):
for j in range(0, sum_y+1):
# if j-move_x_process[i] >= 0:
dp_table[i+1][j] = dp_table[i][abs(j-move_y_process[i])]
if j+move_y_process[i] <= sum_y:
dp_table[i+1][j] = dp_table[i+1][j] or dp_table[i][j+move_y_process[i]]
ret = ret and dp_table[len_move_y][Y]
print('Yes' if ret else 'No')
solve() | Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s544300966 | Accepted | p03488 | Input is given from Standard Input in the following format:
s
x y | def main():
s = input()
x, y = map(int, input().split())
lens = len(s)
ind = 0
if "T" in s:
ind = s.index("T")
x -= ind
else:
ind = lens
x -= lens
x_lst = []
y_lst = []
direct = 0
while ind < lens:
acc = 0
if s[ind] == "F":
while ind < lens and s[ind] == "F":
ind += 1
acc += 1
if direct == 0:
x_lst.append(acc)
else:
y_lst.append(acc)
elif s[ind] == "T":
while ind < lens and s[ind] == "T":
ind += 1
acc += 1
direct = (direct + acc) % 2
x = abs(x)
y = abs(y)
sumx = sum(x_lst)
sumy = sum(y_lst)
if sumx < x or (sumx - x) % 2 or sumy < y or (sumy - y) % 2:
print("No")
else:
target_x = (sumx - x) // 2
target_y = (sumy - y) // 2
canx = [False] * (target_x + 1)
canx[0] = True
cany = [False] * (target_y + 1)
cany[0] = True
break_flag = False
for v in x_lst:
for i in range(target_x - v + 1):
if canx[i]:
canx[i + v] = True
if i + v == target_x:
break_flag = True
break
if break_flag:
break
break_flag = False
for v in y_lst:
for i in range(target_y - v + 1):
if cany[i]:
cany[i + v] = True
if i + v == target_y:
break_flag = True
break
if break_flag:
break
if canx[target_x] and cany[target_y]:
print("Yes")
else:
print("No")
main()
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s719510088 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y | # coding: utf-8
# Your code here!
def possible(goal, move):
if len(move) == 0:
if goal == 0:
return True
else:
return False
sumup = sum(move)
if (sumup+goal)%2 == 1:
return False
dp = [[False for j in range((goal+sumup)+1)] for i in range(len(move))]
dp[0][0] = True
dp[0][move[0]] = True
for i in range(1, len(move)):
for j in range((sumup+goal)//2+1):
dp[i][j] = dp[i][j] or dp[i-1][j]
if j >= move[i]:
dp[i][j] = dp[i][j] or dp[i-1][j-move[i]]
return dp[len(move)-1][(sumup+goal)//2]
if __name__ == '__main__':
S = input()
goalx,goaly = [int(i) for i in input().split()]
xmove_ind = 0
ymove_ind = 0
dir_x = True
count = 0
xmove = []
ymove = []
for i in range(0, len(S)+1):
if i == len(S) or S[i] == 'T' :
if dir_x == True:
if count > 0:
xmove.append(count)
else:
if count > 0:
ymove.append(count)
count = 0
dir_x = not dir_x
else:
count += 1
print(xmove)
print(ymove)
if possible(abs(goaly) , ymove):
if len(xmove) == 1:
if goalx == xmove[0]:
print("Yes")
else:
print("No")
else:
if possible(abs(goalx-xmove[0]), xmove[1:]):
print("Yes")
else:
print("No")
else:
print("No")
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s216650501 | Wrong Answer | p03488 | Input is given from Standard Input in the following format:
s
x y | s = input()
xy = input()
print("Yes")
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s672285489 | Runtime Error | p03488 | Input is given from Standard Input in the following format:
s
x y |
Beta
paiza.IO
新規コード
一覧
ウェブ開発
New!
日本語 サインアップ ログイン
Python3 Split Button!
Enter a title here
Main.py
Success
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
s=input()
x,y = [int(i) for i in input().split()]
#print(s)
susumu = [0]
for i in range(len(s)):
if s[i] == 'F':
susumu[-1] += 1
else:
susumu.append(0)
#print(susumu)
syokiti = susumu.pop(0)
susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]
x -= syokiti
実行 (Ctrl-Enter) Split Button!
出力
入力
コメント 0
(0.04 sec)
No | Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
If the objective is achievable, print `Yes`; if it is not, print `No`.
* * * | s034973174 | Wrong Answer | p03488 | Input is given from Standard Input in the following format:
s
x y | f, *l = map(len, input().split("T"))
x, y = map(int, input().split())
z = 8000
bx = 1 << f + z
by = 1 << z
for dy, dx in zip(*[iter(l)] * 2):
bx = bx << dx | bx >> dx
by = by << dy | by >> dy
print("NYoe s"[bx & (1 << x + z) and by & (1 << y + z) :: 2])
| Statement
A robot is put at the origin in a two-dimensional plane. Initially, the robot
is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the
following two kinds of letters, and will be executed in order from front to
back.
* `F` : Move in the current direction by distance 1.
* `T` : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the
instructions are executed. Determine whether this objective is achievable. | [{"input": "FTFFTFFF\n 4 2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FTFFTFFF\n -2 -2", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning clockwise in the first\n`T` and turning clockwise in the second `T`.\n\n* * *"}, {"input": "FF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "TF\n 1 0", "output": "No\n \n\n* * *"}, {"input": "FFTTFF\n 0 0", "output": "Yes\n \n\nThe objective can be achieved by, for example, turning counterclockwise in the\nfirst `T` and turning counterclockwise in the second `T`.\n\n* * *"}, {"input": "TTTT\n 1 0", "output": "No"}] |
Print the number of ways for the children to share candies, modulo 10^9 + 7.
* * * | s725355751 | Accepted | p03172 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | #!/usr/bin/env python3
# from collections import defaultdict
# from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10**9 + 1 # sys.maxsize # float("inf")
MOD = 10**9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, XS):
table = [0] * (K + 1)
for i in range(XS[0] + 1):
table[i] = 1
for i in range(1, N):
v = 0
newtable = [0] * (K + 1)
accum = [0] * (K + 1)
acc = 0
for j in range(K + 1):
acc += table[j]
accum[j] = acc
# debug(": table", table)
# debug(": accum", accum)
for j in range(K + 1):
# v = 0
# for k in range(XS[i] + 1):
# if j - k < 0:
# break
# v += table[j - k]
# v %= MOD
v = accum[j]
k = j - XS[i] - 1
if k >= 0:
v -= accum[k]
newtable[j] = v % MOD
table = newtable
return table[K]
def main():
# parse input
N, K = map(int, input().split())
XS = list(map(int, input().split()))
print(solve(N, K, XS))
# tests
T1 = """
3 4
1 2 3
"""
def test_T1():
"""
>>> as_input(T1)
>>> main()
5
"""
T2 = """
1 10
9
"""
def test_T2():
"""
>>> as_input(T2)
>>> main()
0
"""
T3 = """
2 0
0 0
"""
def test_T3():
"""
>>> as_input(T3)
>>> main()
1
"""
T4 = """
4 100000
100000 100000 100000 100000
"""
# def test_T4():
# """
# >>> as_input(T4)
# >>> main()
# """
# add tests above
def _test():
import doctest
doctest.testmod()
def as_input(s):
"use in test, use given string as input file"
import io
global read, input
f = io.StringIO(s.strip())
def input():
return bytes(f.readline(), "ascii")
def read():
return bytes(f.read(), "ascii")
USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == "ONLINE_JUDGE") or sys.argv[-1] == "-c":
print("compiling")
from numba.pycc import CC
cc = CC("my_module")
cc.export("solve", solve.__doc__.strip().split()[0])(solve)
cc.compile()
exit()
else:
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if (USE_NUMBA and sys.argv[-1] != "-p") or sys.argv[-1] == "--numba":
# -p: pure python mode
# if not -p, import compiled module
from my_module import solve # pylint: disable=all
elif sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
elif sys.argv[-1] != "-p" and len(sys.argv) == 2:
# input given as file
input_as_file = open(sys.argv[1])
input = input_as_file.buffer.readline
read = input_as_file.buffer.read
main()
| Statement
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1
\leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.
Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two
ways are said to be different when there exists a child who receives a
different number of candies. | [{"input": "3 4\n 1 2 3", "output": "5\n \n\nThere are five ways for the children to share candies, as follows:\n\n * (0, 1, 3)\n * (0, 2, 2)\n * (1, 0, 3)\n * (1, 1, 2)\n * (1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that\nChild i receives.\n\n* * *"}, {"input": "1 10\n 9", "output": "0\n \n\nThere may be no ways for the children to share candies.\n\n* * *"}, {"input": "2 0\n 0 0", "output": "1\n \n\nThere is one way for the children to share candies, as follows:\n\n * (0, 0)\n\n* * *"}, {"input": "4 100000\n 100000 100000 100000 100000", "output": "665683269\n \n\nBe sure to print the answer modulo 10^9 + 7."}] |
Print the number of ways for the children to share candies, modulo 10^9 + 7.
* * * | s695992767 | Runtime Error | p03172 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | import numpy as np
from numba import njit
@njit( cache=True)
def main():
N,K=map(int,input().split())
a=np.array([int(i) for i in input().split()],dtype=np.int64)
MOD=10**9+7
dp=np.full((N+1,K+1),0,dtype=np.int64)
c=np.full(K+2,0,dtype=np.int64)
dp[0][0]=1
for i in range(1,N+1):
c[0]=0
for j in range(1,K+2):
c[j]=(c[j-1]+dp[i-1][j-1])%MOD
for j in range(K+1):
dp[i][j]=(c[j+1]-c[max(0,j-a[i-1])])%MOD
print(dp[N][K])
def main()
| Statement
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1
\leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.
Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two
ways are said to be different when there exists a child who receives a
different number of candies. | [{"input": "3 4\n 1 2 3", "output": "5\n \n\nThere are five ways for the children to share candies, as follows:\n\n * (0, 1, 3)\n * (0, 2, 2)\n * (1, 0, 3)\n * (1, 1, 2)\n * (1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that\nChild i receives.\n\n* * *"}, {"input": "1 10\n 9", "output": "0\n \n\nThere may be no ways for the children to share candies.\n\n* * *"}, {"input": "2 0\n 0 0", "output": "1\n \n\nThere is one way for the children to share candies, as follows:\n\n * (0, 0)\n\n* * *"}, {"input": "4 100000\n 100000 100000 100000 100000", "output": "665683269\n \n\nBe sure to print the answer modulo 10^9 + 7."}] |
Print the number of ways for the children to share candies, modulo 10^9 + 7.
* * * | s422972130 | Accepted | p03172 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())
INF, NINF = float("inf"), float("-inf")
def pprint(M):
for row in M:
print(row)
print("~~~")
def main():
MOD = 10**9 + 7
n, k = rli()
A = list(rli())
dp = [[0 for __ in range(k + 1)] for _ in range(n)]
psums = [[0 for __ in range(k + 1)] for _ in range(n)]
for c in range(min(k + 1, A[0] + 1)):
dp[0][c] = 1
psums[0][0] = dp[0][0]
for c in range(1, k + 1):
psums[0][c] = dp[0][c] + psums[0][c - 1]
psums[0][c] %= MOD
for r in range(1, n):
for c in range(k + 1):
cutoff = c - A[r] - 1
dp[r][c] = psums[r - 1][c] - (psums[r - 1][cutoff] if cutoff >= 0 else 0)
dp[r][c] %= MOD
psums[r][0] = dp[r][0]
for c in range(1, k + 1):
psums[r][c] = dp[r][c] + psums[r][c - 1]
psums[r][c] %= MOD
print(dp[n - 1][k] % MOD)
stdout.close()
if __name__ == "__main__":
main()
| Statement
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1
\leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.
Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two
ways are said to be different when there exists a child who receives a
different number of candies. | [{"input": "3 4\n 1 2 3", "output": "5\n \n\nThere are five ways for the children to share candies, as follows:\n\n * (0, 1, 3)\n * (0, 2, 2)\n * (1, 0, 3)\n * (1, 1, 2)\n * (1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that\nChild i receives.\n\n* * *"}, {"input": "1 10\n 9", "output": "0\n \n\nThere may be no ways for the children to share candies.\n\n* * *"}, {"input": "2 0\n 0 0", "output": "1\n \n\nThere is one way for the children to share candies, as follows:\n\n * (0, 0)\n\n* * *"}, {"input": "4 100000\n 100000 100000 100000 100000", "output": "665683269\n \n\nBe sure to print the answer modulo 10^9 + 7."}] |
Print the number of ways for the children to share candies, modulo 10^9 + 7.
* * * | s669312704 | Accepted | p03172 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | def main():
M = 10**9 + 7
n, k, *a = map(int, open(0).read().split())
dp = [[1] + [0] * k]
for b, i in zip(dp, a):
t, d = 0, []
for v in b[: i + 1]:
t += v
t %= M
d += (t,)
for w, v in zip(b, b[i + 1 :]):
t += v - w
t %= M
d += (t,)
dp += (d,)
print(t)
main()
| Statement
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1
\leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.
Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two
ways are said to be different when there exists a child who receives a
different number of candies. | [{"input": "3 4\n 1 2 3", "output": "5\n \n\nThere are five ways for the children to share candies, as follows:\n\n * (0, 1, 3)\n * (0, 2, 2)\n * (1, 0, 3)\n * (1, 1, 2)\n * (1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that\nChild i receives.\n\n* * *"}, {"input": "1 10\n 9", "output": "0\n \n\nThere may be no ways for the children to share candies.\n\n* * *"}, {"input": "2 0\n 0 0", "output": "1\n \n\nThere is one way for the children to share candies, as follows:\n\n * (0, 0)\n\n* * *"}, {"input": "4 100000\n 100000 100000 100000 100000", "output": "665683269\n \n\nBe sure to print the answer modulo 10^9 + 7."}] |
Print the number of ways for the children to share candies, modulo 10^9 + 7.
* * * | s409052940 | Accepted | p03172 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = SR()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
n, k = LI()
a = LI()
dp = [0 for i in range(k + 1)]
f = [0 for i in range(k + 1)]
for i in range(k + 1):
if not f[i]:
for j in a:
if i - j >= 0:
dp[i] = 1 - dp[i - j]
if dp[i] == 0:
break
else:
dp[i] = 1
print(["First", "Second"][dp[k]])
# B
def B():
n = I()
a = LI()
ma = n * (n + 1) // 2
su = sum(a)
s = [1 for i in range(n + 1)]
for i in range(1, n):
s[i + 1] = s[i] + n - i + 1
d = [None for i in range(ma + 1)]
d[0] = 0
k = 1
for i in range(1, n + 1):
for j in range(n + 1 - i):
d[k + j] = i
k += n + 1 - i
k = n % 2
dp = [su if (d[i] + k) % 2 else -su for i in range(ma + 1)]
dp[0] = 0
if k:
for i in range(n):
dp[i + 1] = a[n - 1 - i]
else:
for i in range(n):
dp[i + 1] = -a[n - 1 - i]
for i in range(1, ma):
r = n - 1 - (i - s[d[i]])
l = r + 1 - d[i]
j = i + (n - d[i])
j2 = j + 1
if (d[i] + k) % 2:
if r < n - 1:
if a[r + 1] + dp[i] > dp[j]:
dp[j] = a[r + 1] + dp[i]
if l > 0:
if a[l - 1] + dp[i] > dp[j2]:
dp[j2] = a[l - 1] + dp[i]
else:
if r < n - 1:
if -a[r + 1] + dp[i] < dp[j]:
dp[j] = -a[r + 1] + dp[i]
if l > 0:
if -a[l - 1] + dp[i] < dp[j2]:
dp[j2] = -a[l - 1] + dp[i]
print(dp[ma])
return
# C
def C():
def comb(a, b):
return fact[a] * inv[b] * inv[a - b] % mod
n, k = LI()
a = LI()
"""
fact = [1]
for i in range(n+k):
fact.append(fact[-1]*(i+1)%mod)
inv = [1]*(n+k+1)
inv[n+k] = pow(fact[n+k],mod-2,mod)
for i in range(n+k)[::-1]:
inv[i] = inv[i+1]*(i+1)%mod
f = [comb(i+n-1,n-1) for i in range(k+1)]
for i in a:
for j in range(k-i)[::-1]:
f[j+i+1] -= f[j]
f[j+i+1] %= mod
print(f[k])
"""
dp = [[0] * (k + 1) for i in range(n + 1)]
for i in range(k + 1):
dp[0][i] = 1
for i in range(n):
ni = i + 1
ai = a[i]
for j in range(k + 1):
if j >= ai + 1:
dp[ni][j] = (dp[i][j] - dp[i][j - ai - 1]) % mod
else:
dp[ni][j] = dp[i][j]
if i < n - 1:
for j in range(k):
dp[ni][j + 1] += dp[ni][j]
dp[ni][j + 1] %= mod
print(dp[n][k] % mod)
return
# D
def D():
return
# E
def E():
n = I()
a = LIR(n)
b = [1 << i for i in range(n + 1)]
dp = [0 for i in range(b[n])]
dp[0] = 1
for i in range(n):
for k in range(b[n])[::-1]:
for j in range(n):
if a[i][j] and not b[j] & k:
dp[b[j] | k] += dp[k]
dp[b[j] | k] %= mod
print(dp[-1])
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
C()
| Statement
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1
\leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.
Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two
ways are said to be different when there exists a child who receives a
different number of candies. | [{"input": "3 4\n 1 2 3", "output": "5\n \n\nThere are five ways for the children to share candies, as follows:\n\n * (0, 1, 3)\n * (0, 2, 2)\n * (1, 0, 3)\n * (1, 1, 2)\n * (1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that\nChild i receives.\n\n* * *"}, {"input": "1 10\n 9", "output": "0\n \n\nThere may be no ways for the children to share candies.\n\n* * *"}, {"input": "2 0\n 0 0", "output": "1\n \n\nThere is one way for the children to share candies, as follows:\n\n * (0, 0)\n\n* * *"}, {"input": "4 100000\n 100000 100000 100000 100000", "output": "665683269\n \n\nBe sure to print the answer modulo 10^9 + 7."}] |
Print the number of ways for the children to share candies, modulo 10^9 + 7.
* * * | s162048930 | Wrong Answer | p03172 | Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N | def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(" ")))
def solve():
"""
OPT[N][K] = sum(OPT[N-1][K-i]) 0 <= i <= A[N]
OPT[0][0] = 1
N*K
3 4
1 2 3
1 0 0 0 0
1 1 0 0 0
1 2 2 1 0
1 3 5 6 5
OPT[3][1] = OPT[2][1]+OPT[2][0]
OPT[3][2] = OPT[2][2]+OPT[2][1]+OPT[2][0]
OPT[3][3] = OPT[2][3]+OPT
"""
N, K = read_ints()
A = read_ints()
modulo = 10**9 + 7
OPT = [[0] * (K + 1) for _ in range(N + 1)]
for i in range(N + 1):
OPT[i][0] = 1
for j in range(K + 1):
OPT[0][j] = 1
for i in range(1, N + 1):
for j in range(1, K + 1):
OPT[i][j] += OPT[i][j - 1] + OPT[i - 1][j]
if j - A[i - 1] - 1 >= 0:
OPT[i][j] -= OPT[i - 1][j - A[i - 1] - 1]
OPT[i][j] %= modulo
return (OPT[-1][-1]) % modulo
if __name__ == "__main__":
print(solve())
| Statement
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1
\leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.
Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two
ways are said to be different when there exists a child who receives a
different number of candies. | [{"input": "3 4\n 1 2 3", "output": "5\n \n\nThere are five ways for the children to share candies, as follows:\n\n * (0, 1, 3)\n * (0, 2, 2)\n * (1, 0, 3)\n * (1, 1, 2)\n * (1, 2, 1)\n\nHere, in each sequence, the i-th element represents the number of candies that\nChild i receives.\n\n* * *"}, {"input": "1 10\n 9", "output": "0\n \n\nThere may be no ways for the children to share candies.\n\n* * *"}, {"input": "2 0\n 0 0", "output": "1\n \n\nThere is one way for the children to share candies, as follows:\n\n * (0, 0)\n\n* * *"}, {"input": "4 100000\n 100000 100000 100000 100000", "output": "665683269\n \n\nBe sure to print the answer modulo 10^9 + 7."}] |
Print the minimum amount of money required to buy all the items.
* * * | s042997059 | Wrong Answer | p02912 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N | a = [2, 3, 4]
b = max(a)
b = b / 2
print(a)
| Statement
Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an
item.
If Y tickets are used when buying an item priced X yen, he can get the item
for \frac{X}{2^Y} (rounded down to the nearest integer) yen.
What is the minimum amount of money required to buy all the items? | [{"input": "3 3\n 2 13 8", "output": "9\n \n\nWe can buy all the items for 9 yen, as follows:\n\n * Buy the 1-st item for 2 yen without tickets.\n * Buy the 2-nd item for 3 yen with 2 tickets.\n * Buy the 3-rd item for 4 yen with 1 ticket.\n\n* * *"}, {"input": "4 4\n 1 9 3 5", "output": "6\n \n\n* * *"}, {"input": "1 100000\n 1000000000", "output": "0\n \n\nWe can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.\n\n* * *"}, {"input": "10 1\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "9500000000"}] |
Print the minimum amount of money required to buy all the items.
* * * | s153017158 | Accepted | p02912 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N | import sys
from collections import Counter
sys.setrecursionlimit(10**7)
rl = sys.stdin.readline
def upsqrt(x):
k = x**0.5
res = 1
while res < k:
res <<= 1
return res
def botsqrt(x):
k = x**0.5
res = 1
while res <= k:
res <<= 1
return res >> 1
class VanEmdeBoasTree:
def __init__(self, size):
self.universe_size = 1
while self.universe_size < size:
self.universe_size <<= 1
self.minimum = -1
self.maximum = -1
self.summary = None
self.cluster = {}
def __high(self, x):
return x // botsqrt(self.universe_size)
def __low(self, x):
return x % botsqrt(self.universe_size)
def __generate_index(self, x, y):
return x * botsqrt(self.universe_size) + y
def min(self):
return self.minimum
def max(self):
return self.maximum
def __empinsert(self, key):
self.minimum = self.maximum = key
def insert(self, key):
if self.minimum == -1:
self.__empinsert(key)
else:
if key < self.minimum:
self.minimum, key = key, self.minimum
if 2 < self.universe_size:
if self.__high(key) not in self.cluster:
self.cluster[self.__high(key)] = VanEmdeBoasTree(
botsqrt(self.universe_size)
)
if self.summary is None:
self.summary = VanEmdeBoasTree(upsqrt(self.universe_size))
self.summary.insert(self.__high(key))
self.cluster[self.__high(key)].__empinsert(self.__low(key))
else:
self.cluster[self.__high(key)].insert(self.__low(key))
if self.maximum < key:
self.maximum = key
def is_member(self, key):
if self.minimum == key or self.maximum == key:
return True
elif self.universe_size == 2:
return False
else:
if self.__high(key) in self.cluster:
return self.cluster[self.__high(key)].is_member(self.__low(key))
else:
return False
def successor(self, key):
if self.universe_size == 2:
if key == 0 and self.maximum == 1:
return 1
else:
return -1
elif self.minimum != -1 and key < self.minimum:
return self.minimum
else:
max_incluster = -1
if self.__high(key) in self.cluster:
max_incluster = self.cluster[self.__high(key)].max()
if max_incluster != -1 and self.__low(key) < max_incluster:
offset = self.cluster[self.__high(key)].successor(self.__low(key))
return self.__generate_index(self.__high(key), offset)
else:
succ_cluster = -1
if self.summary is not None:
succ_cluster = self.summary.successor(self.__high(key))
if succ_cluster == -1:
return -1
else:
offset = self.cluster[succ_cluster].min()
return self.__generate_index(succ_cluster, offset)
def predecessor(self, key):
if self.universe_size == 2:
if key == 1 and self.minimum == 0:
return 0
else:
return -1
elif self.maximum != -1 and self.maximum < key:
return self.maximum
else:
min_incluster = -1
if self.__high(key) in self.cluster:
min_incluster = self.cluster[self.__high(key)].min()
if min_incluster != -1 and min_incluster < self.__low(key):
offset = self.cluster[self.__high(key)].predecessor(self.__low(key))
return self.__generate_index(self.__high(key), offset)
else:
pred_cluster = -1
if self.summary is not None:
pred_cluster = self.summary.predecessor(self.__high(key))
if pred_cluster == -1:
if self.minimum != -1 and self.minimum < key:
return self.minimum
else:
return -1
else:
offset = self.cluster[pred_cluster].max()
return self.__generate_index(pred_cluster, offset)
def delete(self, key):
if self.minimum == self.maximum:
self.minimum = self.maximum = -1
return True
elif self.universe_size == 2:
if key == 0:
self.minimum = 1
else:
self.minimum = 0
self.maximum = self.minimum
return False
else:
if key == self.minimum:
first_cluster = self.summary.min()
key = self.__generate_index(
first_cluster, self.cluster[first_cluster].min()
)
self.minimum = key
flg0 = self.cluster[self.__high(key)].delete(self.__low(key))
if flg0:
del self.cluster[self.__high(key)]
flg1 = self.summary.delete(self.__high(key))
if key == self.maximum:
if flg1:
self.maximum = self.minimum
else:
max_insummary = self.summary.max()
self.maximum = self.__generate_index(
max_insummary, self.cluster[max_insummary].max()
)
elif key == self.maximum:
self.maximum = self.__generate_index(
self.__high(key), self.cluster[self.__high(key)].max()
)
def solve():
N, M = map(int, rl().split())
A = list(map(int, rl().split()))
veb = VanEmdeBoasTree(10**9)
for ai in A:
veb.insert(ai)
counter = Counter(A)
for _ in range(M):
maximum = veb.max()
counter[maximum] -= 1
if counter[maximum] == 0:
veb.delete(maximum)
if counter[maximum // 2] == 0:
veb.insert(maximum // 2)
counter[maximum // 2] += 1
val = veb.max()
ans = val * counter[val]
for _ in range(N - 1):
val = veb.predecessor(val)
ans += val * counter[val]
print(ans)
if __name__ == "__main__":
solve()
| Statement
Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an
item.
If Y tickets are used when buying an item priced X yen, he can get the item
for \frac{X}{2^Y} (rounded down to the nearest integer) yen.
What is the minimum amount of money required to buy all the items? | [{"input": "3 3\n 2 13 8", "output": "9\n \n\nWe can buy all the items for 9 yen, as follows:\n\n * Buy the 1-st item for 2 yen without tickets.\n * Buy the 2-nd item for 3 yen with 2 tickets.\n * Buy the 3-rd item for 4 yen with 1 ticket.\n\n* * *"}, {"input": "4 4\n 1 9 3 5", "output": "6\n \n\n* * *"}, {"input": "1 100000\n 1000000000", "output": "0\n \n\nWe can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.\n\n* * *"}, {"input": "10 1\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "9500000000"}] |
Print the minimum amount of money required to buy all the items.
* * * | s253531864 | Wrong Answer | p02912 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N | N, M = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])
B = A[M + 1 :]
A = A[: M + 1]
for i in range(M):
t = A.index(max(A))
A[t] = A[t] // 2
print(sum(A) + sum(B))
| Statement
Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an
item.
If Y tickets are used when buying an item priced X yen, he can get the item
for \frac{X}{2^Y} (rounded down to the nearest integer) yen.
What is the minimum amount of money required to buy all the items? | [{"input": "3 3\n 2 13 8", "output": "9\n \n\nWe can buy all the items for 9 yen, as follows:\n\n * Buy the 1-st item for 2 yen without tickets.\n * Buy the 2-nd item for 3 yen with 2 tickets.\n * Buy the 3-rd item for 4 yen with 1 ticket.\n\n* * *"}, {"input": "4 4\n 1 9 3 5", "output": "6\n \n\n* * *"}, {"input": "1 100000\n 1000000000", "output": "0\n \n\nWe can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.\n\n* * *"}, {"input": "10 1\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "9500000000"}] |
Print the minimum amount of money required to buy all the items.
* * * | s421492185 | Accepted | p02912 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N | class Heap:
# 初期化
def __init__(self):
self.array = []
def num(self):
return len(self.array)
# valを追加する
def put(self, val):
pos = len(self.array)
# valを末尾に追加する
self.array.append(val)
# valを適当な位置まで上にあげる
self.pop_up(pos)
# 最大の要素を取り出す
def get(self):
assert len(self.array) > 0
val = self.array[0]
# 末尾の要素を0に移動してから下に下げる
t_val = self.array[-1]
self.array[0] = t_val
del self.array[-1]
self.push_down(0)
return val
# posの位置の要素を適当な位置まで上げる
def pop_up(self, pos):
while pos > 0:
p_pos = (pos - 1) // 2
val = self.array[pos]
p_val = self.array[p_pos]
if val > p_val:
self.array[pos] = p_val
self.array[p_pos] = val
pos = p_pos
else:
break
def push_down(self, pos):
while True:
l_pos = 2 * pos + 1
r_pos = 2 * pos + 2
n = len(self.array)
if n <= l_pos:
# 子がいない場合
break
elif n == r_pos:
# 子が一人の場合
val = self.array[pos]
l_val = self.array[l_pos]
if val < l_val:
self.array[pos] = l_val
self.array[l_pos] = val
break #
else:
# 子が二人いるとき
val = self.array[pos]
l_val = self.array[l_pos]
r_val = self.array[r_pos]
if l_val > r_val:
if val < l_val:
self.array[pos] = l_val
self.array[l_pos] = val
pos = l_pos
else:
break
else:
if val < r_val:
self.array[pos] = r_val
self.array[r_pos] = val
pos = r_pos
else:
break
h = Heap()
sn, sm = input().split(" ")
n = int(sn)
m = int(sm)
sa_list = input().split(" ")
for sa in sa_list:
a = int(sa)
h.put(a)
for i in range(m):
max_a = h.get()
h.put(max_a // 2)
print(sum(h.array))
| Statement
Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an
item.
If Y tickets are used when buying an item priced X yen, he can get the item
for \frac{X}{2^Y} (rounded down to the nearest integer) yen.
What is the minimum amount of money required to buy all the items? | [{"input": "3 3\n 2 13 8", "output": "9\n \n\nWe can buy all the items for 9 yen, as follows:\n\n * Buy the 1-st item for 2 yen without tickets.\n * Buy the 2-nd item for 3 yen with 2 tickets.\n * Buy the 3-rd item for 4 yen with 1 ticket.\n\n* * *"}, {"input": "4 4\n 1 9 3 5", "output": "6\n \n\n* * *"}, {"input": "1 100000\n 1000000000", "output": "0\n \n\nWe can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.\n\n* * *"}, {"input": "10 1\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "9500000000"}] |
Print the minimum amount of money required to buy all the items.
* * * | s171389027 | Accepted | p02912 | Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_N | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda: sys.stdin.readline().rstrip()
class Heap(object):
def __init__(self, A):
self._heap = []
# heapify は O(n) でできるらしいが、O(nlogn) で妥協
# cf. https://github.com/python/cpython/blob/3.8/Lib/heapq.py
for a in A:
self.append(a)
def __len__(self):
return len(self._heap)
def __bool__(self):
return bool(self._heap)
def front(self):
assert self
return self._heap[0]
def append(self, x):
self._heap.append(x)
now = len(self) - 1
heap = self._heap
# n の親は (n-1)//2
while now != 0 and heap[now] < heap[(now - 1) // 2]:
heap[now], heap[(now - 1) // 2] = heap[(now - 1) // 2], heap[now]
now = (now - 1) // 2
def pop(self):
assert self
if len(self) == 1:
return self._heap.pop()
heap = self._heap
res, heap[0] = heap[0], heap.pop()
# n の子は 2*n+1, 2*n+2
now = 0
while 1:
if now * 2 + 1 >= len(self):
break # 子が存在しない
# 子がひとつだけのとき、必要なら入れ替えて終わり
if now * 2 + 1 == len(self) - 1:
if heap[now] > heap[now * 2 + 1]:
heap[now], heap[now * 2 + 1] = heap[now * 2 + 1], heap[now]
break
# 子が複数のとき
else:
# 親、子1、子2のうち、親が最小であれば終わり
if min(heap[now], heap[2 * now + 1], heap[2 * now + 2]) == heap[now]:
break
# そうでないとき、子のうち小さい方を親と入れ替える
next = min(
(heap[2 * now + 1], 2 * now + 1), (heap[2 * now + 2], 2 * now + 2)
)[1]
heap[now], heap[next] = heap[next], heap[now]
now = next
return res
def sort(self):
return [self.pop() for _ in range(len(self))]
def resolve():
n, m = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heap = Heap(A)
for _ in range(m):
x = -heap.pop()
x //= 2
heap.append(-x)
print(-sum(heap._heap))
resolve()
| Statement
Takahashi is going to buy N items one by one.
The price of the i-th item he buys is A_i yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an
item.
If Y tickets are used when buying an item priced X yen, he can get the item
for \frac{X}{2^Y} (rounded down to the nearest integer) yen.
What is the minimum amount of money required to buy all the items? | [{"input": "3 3\n 2 13 8", "output": "9\n \n\nWe can buy all the items for 9 yen, as follows:\n\n * Buy the 1-st item for 2 yen without tickets.\n * Buy the 2-nd item for 3 yen with 2 tickets.\n * Buy the 3-rd item for 4 yen with 1 ticket.\n\n* * *"}, {"input": "4 4\n 1 9 3 5", "output": "6\n \n\n* * *"}, {"input": "1 100000\n 1000000000", "output": "0\n \n\nWe can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.\n\n* * *"}, {"input": "10 1\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "9500000000"}] |
Print the maximum possible amount of the allowance.
* * * | s846587447 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | l = list((map(int, input().split())))
ls = sorted(l, reverse=True)
print(ls[0] * 10 + ls[1] + ls[2])
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s589519150 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | num = sorted(list(map(int, input().split())), reverse=True)
print(num[0] * 10 + sum(num[1:]))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s380823883 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | IN = list(map(int, input().split(" ")))
IN = sorted(IN)[::-1]
print(eval("{}{}+{}".format(*IN)))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s626054752 | Wrong Answer | p03250 | Input is given from Standard Input in the following format:
A B C | A, B, C = map(str, input().split(" "))
print(max([int(A + B) + int(C), int(A + C) + int(B), int(B + C) + int(A)]))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s953010010 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | A = list(map(int, input().split()))
A.sort(reverse = True)
print(A[0] * 10 + A[1] + A[2] | Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s600635292 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | listabc = sorted(list(map(int, input().split())))
print(9 * listabc[2] + sum(listabc))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s540232759 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | k = list(map(int, input().split()))
s = sum(k) - max(k) + max(k) * 10
print(s)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s825570543 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | A, B, C = sorted(map(int, input().split()))[::-1]
print(A * 10 + B * 1 + C)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s900298610 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | N = sorted(list(map(int, input().split())))
print(N[2] * 10 + N[1] + N[0])
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s289562701 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | n = sorted(input().split())
print(int(n.pop() + n.pop()) + int(n.pop()))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s636535040 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | pritn(eval("+".join(sorted(input())) + "*10"))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s297685248 | Wrong Answer | p03250 | Input is given from Standard Input in the following format:
A B C | print(eval("+".join(sorted(input())) + "+10"))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s561933712 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | import sys
import heapq, math
from itertools import (
zip_longest,
permutations,
combinations,
combinations_with_replacement,
)
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
I = list(map(int, input().split()))
I.sort(reverse=True)
print(I[0] * 10 + sum(I[1:3]))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s960737214 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | ###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
###############################################################################
def main():
a, b, c = intin()
abc = [a, b, c]
abc.sort()
print(abc[2] * 10 + abc[1] + abc[0])
if __name__ == "__main__":
main()
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s587643106 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | x = list(map(int, input().split()))
a = max(x)
b = min(x)
x.remove(a)
x.remove(b)
c = x[0]
a = str(a)
b = str(b)
ab = int(a + b)
print(ab + c)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s978712647 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | from copy import deepcopy
from sys import exit, setrecursionlimit
import math
from collections import defaultdict, Counter, deque
from fractions import Fraction as frac
setrecursionlimit(1000000)
def main():
a = list(map(int, input().split()))
a.sort()
print(a[2] * 10 + sum(a[:2]))
def zip(a):
mae = a[0]
ziparray = [mae]
for i in range(1, len(a)):
if mae != a[i]:
ziparray.append(a[i])
mae = a[i]
return ziparray
def is_prime(n):
if n < 2:
return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
def list_replace(n, f, t):
return [t if i == f else i for i in n]
def base_10_to_n(X, n):
X_dumy = X
out = ""
while X_dumy > 0:
out = str(X_dumy % n) + out
X_dumy = int(X_dumy / n)
if out == "":
return "0"
return out
def gcd(l):
x = l.pop()
y = l.pop()
while x % y != 0:
z = x % y
x = y
y = z
l.append(min(x, y))
return gcd(l) if len(l) > 1 else l[0]
class Queue:
def __init__(self):
self.q = deque([])
def push(self, i):
self.q.append(i)
def pop(self):
return self.q.popleft()
def size(self):
return len(self.q)
def debug(self):
return self.q
class Stack:
def __init__(self):
self.q = []
def push(self, i):
self.q.append(i)
def pop(self):
return self.q.pop()
def size(self):
return len(self.q)
def debug(self):
return self.q
class graph:
def __init__(self):
self.graph = defaultdict(list)
def addnode(self, l):
f, t = l[0], l[1]
self.graph[f].append(t)
self.graph[t].append(f)
def rmnode(self, l):
f, t = l[0], l[1]
self.graph[f].remove(t)
self.graph[t].remove(f)
def linked(self, f):
return self.graph[f]
class dgraph:
def __init__(self):
self.graph = defaultdict(set)
def addnode(self, l):
f, t = l[0], l[1]
self.graph[f].append(t)
def rmnode(self, l):
f, t = l[0], l[1]
self.graph[f].remove(t)
def linked(self, f):
return self.graph[f]
main()
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s331797520 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
x = LI()
x.sort(reverse=1)
ans = x[0] * 10 + x[1] + x[2]
print(ans)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s966575095 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | import collections, math, sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, M = LI()
ans = 1
def prime_factor(num):
prime_factor = collections.defaultdict(int)
for i in range(2, int(num**0.5) + 1):
while num % i == 0:
prime_factor[i] += 1
num //= i
if num > 1:
prime_factor[num] = 1
return prime_factor
for v in prime_factor(M).values():
ans *= math.factorial(v + N - 1) // math.factorial(v) // math.factorial(N - 1)
ans %= 10**9 + 7
print(ans)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s834939624 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | n, m, X, Y = sorted(map(int, input().split()))
x = max([X], max(map(int, input().split())))
y = min([Y], min(map(int, input().split())))
print("No War" if x < y else "War")
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s257451072 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | mod = 10**9 + 7
mod2 = 2**61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right
def iip(listed=True):
ret = [int(i) for i in input().split()]
if len(ret) == 1 and not listed:
return ret[0]
return ret
def iip_ord():
return [ord(i) - ord("a") for i in input()]
def main():
ans = solve()
if ans is not None:
print(ans)
def solve():
# N, M = iip(False)
S = input()
T = input()
d1 = {}
d2 = {}
for s, t in zip(S, T):
if t not in d1:
d1[t] = s
d2[s] = t
if s not in d2:
d2[s] = t
d1[t] = s
# print(t, t, d[s])
if d1[t] != s or d2[s] != t:
print("No")
return
print("Yes")
#####################################################ライブラリ集ここから
def fprint(s):
for i in s:
print(i)
def split_print_space(s):
print(" ".join([str(i) for i in s]))
def split_print_enter(s):
print("\n".join([str(i) for i in s]))
def koenai_saidai_x_index(sorted_list, n):
l = 0
r = len(sorted_list)
if len(sorted_list) == 0:
return False
if sorted_list[0] > n:
return False
while r - l > 1:
x = (l + r) // 2
if sorted_list[x] == n:
return x
elif sorted_list[x] > n:
r = x
else:
l = x
return l
def searchsorted(sorted_list, n, side):
if side not in ["right", "left"]:
raise Exception("sideはrightかleftで指定してください")
l = 0
r = len(sorted_list)
if n > sorted_list[-1]:
# print(sorted_list)
return len(sorted_list)
if n < sorted_list[0]:
return 0
while r - l > 1:
x = (l + r) // 2
if sorted_list[x] > n:
r = x
elif sorted_list[x] < n:
l = x
else:
if side == "left":
r = x
elif side == "right":
l = x
if side == "left":
if sorted_list[l] == n:
return r - 1
else:
return r
if side == "right":
if sorted_list[l] == n:
return l + 1
else:
return l
def soinsuu_bunkai(n):
ret = []
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
n //= i
ret.append(i)
if i > n:
break
if n != 1:
ret.append(n)
return ret
def conbination(n, r, mod, test=False):
if n <= 0:
return 0
if r == 0:
return 1
if r < 0:
return 0
if r == 1:
return n
ret = 1
for i in range(n - r + 1, n + 1):
ret *= i
ret = ret % mod
bunbo = 1
for i in range(1, r + 1):
bunbo *= i
bunbo = bunbo % mod
ret = (ret * inv(bunbo, mod)) % mod
if test:
# print(f"{n}C{r} = {ret}")
pass
return ret
def inv(n, mod):
return power(n, mod - 2)
def power(n, p, mod_=mod):
if p == 0:
return 1
if p % 2 == 0:
return (power(n, p // 2, mod_) ** 2) % mod_
if p % 2 == 1:
return (n * power(n, p - 1, mod_)) % mod_
if __name__ == "__main__":
main()
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s740911296 | Wrong Answer | p03250 | Input is given from Standard Input in the following format:
A B C | A, B, C = map(str, input().split())
print(max(int(A + B) + int(C), int(B + C) + int(A)))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s768629870 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | l = [int(i) for i in input().split()]
if l.index(max(l)) == 0:
print(l[0] * 10 + l[1] + l[2])
elif l.index(max(l)) == 1:
print(l[1] * 10 + l[0] + l[2])
else:
print(l[2] * 10 + l[1] + l[0])
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s122048672 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | s1 = input()
s2 = input()
dict_s1 = {}
dict_s2 = {}
for i in range(len(s1)):
if s1[i] not in dict_s1:
dict_s1[s1[i]] = s2[i]
else:
if dict_s1[s1[i]] != s2[i]:
print("No")
quit()
if s2[i] not in dict_s2:
dict_s2[s2[i]] = s1[i]
else:
if dict_s2[s2[i]] != s1[i]:
print("No")
quit()
print("Yes")
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s362932613 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | L = sorted(input().split(), reverse=True)
print(int(L[0] + L[1]) + int(L[2]))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s825240517 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | A, B, C = map(int, input().split())
AB_C = A * 10 + B + C
A_BC = A + B * 10 + C
A_CB = A + C * 10 + B
B_AC = B + A * 10 + C
B_CA = B + C * 10 + A
C_BA = C + B * 10 + A
max = 0
S = []
S.append(AB_C)
S.append(A_BC)
S.append(A_CB)
S.append(B_AC)
S.append(B_CA)
S.append(C_BA)
for i in range(len(S)):
if S[i] > max:
max = S[i]
print(max)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s501444912 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | a, b, c = [x for x in input().split()]
sum1 = int(a) + int(b + c)
sum2 = int(a) + int(c + b)
sum3 = int(b) + int(a + c)
sum4 = int(b) + int(c + a)
sum5 = int(c) + int(a + b)
sum6 = int(c) + int(b + a)
print(max(sum1, sum2, sum3, sum4, sum5, sum6))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s649723678 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | abc = input().split(" ")
nums = []
nums.append(int(abc[0] + abc[1]) + int(abc[2]))
nums.append(int(abc[1] + abc[0]) + int(abc[2]))
nums.append(int(abc[0]) + int(abc[1] + abc[2]))
nums.append(int(abc[0]) + int(abc[2] + abc[1]))
nums.append(int(abc[0] + abc[2]) + int(abc[1]))
nums.append(int(abc[2] + abc[0]) + int(abc[1]))
print(max(nums))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s364648948 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | nums = [int(num) for num in input().split()]
a = nums[0]
b = nums[1]
c = nums[2]
maxi = max(a, b)
maxi = max(maxi, c)
if maxi == a:
ans = a * 10 + b + c
elif maxi == b:
ans = b * 10 + a + c
else:
ans = c * 10 + a + b
print(ans)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s163664873 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | abc = input().split()
a = abc[0]
b = abc[1]
c = abc[2]
d = eval((a + b) + "+" + c)
e = eval((b + a) + "+" + c)
f = eval((a + c) + "+" + b)
g = eval((c + a) + "+" + b)
h = eval((b + c) + "+" + a)
i = eval((c + b) + "+" + a)
h = [d, e, f, g, h, i]
print(max(h))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s414240566 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | number = []
num_m = []
number = input().split()
num_m = number
j = 0
for j in range(2):
i = 0
for i in range(2):
if number[i] < number[i + 1]:
tmp = number[i]
number[i] = number[i + 1]
number[i + 1] = tmp
num_m[0] = int(number[0]) * 10
num_m[1] = int(number[1])
num_m[2] = int(number[2])
sum = 0
sum = num_m[0] + num_m[1] + num_m[2]
print(sum)
n, j = 0, 0
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s915692572 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | d = input().split()
a = int(d[0])
b = int(d[1])
c = int(d[2])
int e = 0
e = a*10+b+c
if e < b*10+a+c:
e = b*10+a+c
if e < c*10+a+b:
e = c*10+a+b
if e < c*10+a+b:
e= c*10+a+b
if e < b*10+a+c:
e = b*10+a+c
print(e)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s918110382 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | import time
import collections
import scipy.misc
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(int(n))
return table
N, M = map(int, input().split())
t_strt = time.time()
factors = collections.Counter(prime_decomposition(M))
t_elps = time.time()
# print(f"{t_elps - t_strt} [sec]")
num_pattern = 1
for exponent in factors.values():
tmp_num_pattern = scipy.misc.comb(exponent + N - 1, N - 1, exact=True)
num_pattern = num_pattern * int(tmp_num_pattern)
# print(num_pattern%(10**9+7))
t_elps = time.time()
print(f"{t_elps - t_strt} [sec]")
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s482450147 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | x, y, z = map(int, input().split())
max_lines = [
[int(x + y), int(z)],
[int(x + z), int(y)],
[int(y + x), int(z)],
[int(y + z), int(x)],
[int(z + x), int(y)],
[int(z + y), int(x)],
]
max_point = 0
one_point = 0
for max_line in max_lines:
if max_line[0] >= max_point:
max_point = max_line[0]
one_point = max_line[1]
print(max_point + one_point)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s177743253 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
N, M = map(int, input().split())
if M == 1:
print(1)
else:
primes0 = prime_factorize(M)
keys = list(set(primes0))
primes = {}
for i in range(len(keys)):
k = keys[i]
primes[k] = 0
for j in range(len(primes0)):
if primes0[j] == k:
primes[k] += 1
def cmb(n, k, mod, fac, ifac): # calc nCk under mod
if n < k or n < 0 or k < 0:
return 0
else:
k = min(k, n - k)
return fac[n] * ifac[k] * ifac[n - k] % mod
def make_tables(mod, n): # Make factorial and inverse tables under mod
fac = [1, 1] # factorial table
ifac = [1, 1] # factorial of inverse table
inverse = [0, 1] # inverse
for i in range(2, n + 1):
fac.append((fac[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
ifac.append((ifac[-1] * inverse[-1]) % mod)
return fac, ifac
mod = 10**9 + 7
fac, ifac = make_tables(mod, N * 2)
ans = 1
for i in range(len(keys)):
ans *= cmb(N + primes[keys[i]] - 1, primes[keys[i]], mod, fac, ifac)
ans %= mod
print(ans)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s340357805 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | N, M = map(int, input().split())
mod = 1000000007
f = [] # 素因数分解(指数部のみ)
for p in range(2, M): # 素因数分解
e = 0
while M%p == 0:
e += 1
M /= p
if e>0:
f.append(e)
if M == 1:
break
def pw(a, e):
if e == 1:
return a
p = pw(a, e // 2)
if e%2 == 1:
return p * p % mod a % mod
else:
return p * p % mod
# fact, inv の計算
fact = [1] * 100040
inv = [1] * 100040
for k in range(1, 100040):
fact[k] = fact[k-1] * k % mod
inv[k] = pw(fact[k], mod-2)
ans = 1
for e in f:
ans = ans * fact[e+N-1] % mod * inv[e] % mod * inv[N-1] % mod # N_H_e (重複組合せ)
print(ans)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s769989955 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | N, M = map(int, input().split())
mod = 1000000007
f = [] # 素因数分解(指数部のみ)
for p in range(2, M): # 素因数分解
e = 0
while M%p == 0:
e += 1
M /= p
if e>0:
f.append(e)
if M == 1:
break
def pw(a, e):
if e == 1:
return a
p = pw(a, e // 2)
if e%2 == 1:
return p * p % mod * a % mod
else:
return p * p % mod
# fact, inv の計算
fact = [1] * 100033
inv = [1] * 100033
for k in range(1, 100033):
fact[k] = fact[k-1] * k % mod
inv[k] = pw(fact[k], mod-2))
def combine(n, k):
return fact[n] * inv[k] % mod * inv[n-k] % mod
ans = 1
for e in f:
ans *= combine(e+N-1, e) # N_H_e (重複組合せ)
ans %= mod
print(ans)
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s827631460 | Runtime Error | p03250 | Input is given from Standard Input in the following format:
A B C | one = list(input())
# print(one)
two = list(input())
for num, i in enumerate(one):
if i not in z:
z[i] = [num]
else:
z[i].append(num)
p = {}
for num, i in enumerate(two):
if i not in p:
p[i] = [num]
else:
p[i].append(num)
w = []
# print(p)
# print(z)
for k, v in z.items():
w.append(v)
o = []
for k, v in p.items():
o.append(v)
print("Yes") if w == o else print("No")
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s492714788 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | panels = list(sorted(map(str, input().split())))
print(int(panels[0]) + int(panels[2] + panels[1]))
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Print the maximum possible amount of the allowance.
* * * | s152219223 | Accepted | p03250 | Input is given from Standard Input in the following format:
A B C | panel = list(map(int, input().split()))
panel.sort()
print(panel[2] * 10 + panel[1] + panel[0])
| Statement
You have decided to give an allowance to your child depending on the outcome
of the game that he will play now.
The game is played as follows:
* There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a `+` printed on it.
* The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
* Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game,
find the maximum possible amount of the allowance. | [{"input": "1 5 2", "output": "53\n \n\nThe amount of the allowance will be 53 when the panels are arranged as `52+1`,\nand this is the maximum possible amount.\n\n* * *"}, {"input": "9 9 9", "output": "108\n \n\n* * *"}, {"input": "6 6 7", "output": "82"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.