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 maximum positive integer K that satisfies the condition.
* * *
|
s556583909
|
Accepted
|
p02939
|
Input is given from Standard Input in the following format:
S
|
while True:
try:
S = input()
result = 0
prev = None
cur = ""
for c in S:
if prev is None:
prev = c
result += 1
continue
cur += c
if prev == cur:
continue
result += 1
prev = cur
cur = ""
print(result)
except EOFError:
break
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s216194618
|
Wrong Answer
|
p02939
|
Input is given from Standard Input in the following format:
S
|
s = input()
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s797160887
|
Wrong Answer
|
p02939
|
Input is given from Standard Input in the following format:
S
|
s = input().rstrip()
# start from 1
idx = 0
pata = []
patb = []
pata.append(s[idx])
idx += 1
while idx < len(s):
pata.append(s[idx])
idx += 1
while len(pata) > 1 and pata[-2] == pata[-1]:
if idx < len(s):
pata[-1] += s[idx]
idx += 1
else:
last = pata.pop()
pata[-1] += last
# start from 2
idx = 0
patb = []
patb.append(s[idx : idx + 2])
idx += 2
while idx < len(s):
patb.append(s[idx])
idx += 1
while len(patb) > 1 and patb[-2] == patb[-1]:
if idx < len(s):
patb[-1] += s[idx]
idx += 1
else:
last = patb.pop()
patb[-1] += last
print(max(len(pata), len(patb)))
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s478801016
|
Accepted
|
p02939
|
Input is given from Standard Input in the following format:
S
|
S = input()
P = []
P.append(S[0])
S = S[1:]
while len(S) > 0:
for i in range(1, len(S) + 1):
if not S[0:i] == P[-1]:
P.append(S[0:i])
S = S[i:]
break
else:
break
print(len(P))
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s938654394
|
Runtime Error
|
p02939
|
Input is given from Standard Input in the following format:
S
|
t = list(input())
u = [0]
while len(t) >= 3:
if u[-1] != t[0]:
u.append(t.pop(0))
else:
u.append([t.pop(0) + t.pop(0)])
if len(t) == 1:
if u[-1] != t[0]:
u.append(t.pop(0))
if len(t) == 2:
if u[-1] == t[0]:
u.append([t.pop(0) + t.pop(0)])
if u[-1] != t[0]:
if t[0] != t[1]:
u.append(t.pop(0))
u.append(t.pop(0))
else:
u.append([t.pop(0) + t.pop(0)])
print(len(u) - 1)
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s478087948
|
Wrong Answer
|
p02939
|
Input is given from Standard Input in the following format:
S
|
def get_cache(chars, start, end, cache=dict()):
pair = (start, end)
block = cache.get(pair)
if block is not None:
return block
else:
block = chars[start:end]
cache[pair] = block
return block
def get_skip(chars, previous_start, previous_end, cache=dict()):
pair = (previous_start, previous_end)
if pair in cache:
return cache[pair]
skip = len(chars)
previous_len = previous_end - previous_start
if previous_end + previous_len < len(chars):
previous = get_cache(chars, previous_start, previous_end)
suspicious_end = previous_end + previous_len
suspicious = get_cache(chars, previous_end, previous_end + previous_len)
if previous == suspicious:
skip = suspicious_end
cache[pair] = skip
return skip
def count_k(chars):
cache = dict()
stack = []
previous_start = 0
previous_end = 0
max_k = 1
current = 1
while True:
skip = get_skip(chars, previous_start, previous_end)
while current < len(chars):
if current == skip:
current += 1
continue
pair = (previous_end, current)
if pair in cache:
k = cache[pair]
if max_k < k:
max_k = k
else:
current = len(chars)
else:
stack.append((previous_start, previous_end, current, max_k))
previous_start = previous_end
previous_end = current
current = current + 1
max_k = 1
break
current += 1
else:
if previous_end + 1 != len(chars):
max_k += 1
cache[(previous_start, previous_end)] = max_k
if len(stack) == 0:
break
_previous_start, _previous_end, _current, _max_k = stack.pop()
assert _current == previous_end
assert _previous_end == previous_start
if _max_k < max_k:
_max_k = max_k
previous_start = _previous_start
previous_end = _previous_end
current = _current
max_k = _max_k
return max_k
s = input()
print(count_k(list(s)))
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s503883256
|
Accepted
|
p02939
|
Input is given from Standard Input in the following format:
S
|
s = str(input())
n = len(s)
dp = [[0, 0] for i in range(n + 1)]
for i in range(n):
for j in [1, 2]:
for k in [1, 2]:
if i + k <= n:
a = s[i - j : i]
b = s[i : i + k]
if a != b:
dp[i + k][k - 1] = max(dp[i + k][k - 1], dp[i][j - 1] + 1)
print(max(dp[n]))
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s380427993
|
Wrong Answer
|
p02939
|
Input is given from Standard Input in the following format:
S
|
S = input()
Slen = len(S)
S_inv = S[::-1]
prev_f = S[0]
ptr_f = 1
div_f = 0
while ptr_f < Slen:
# print(prev_f)
if len(prev_f) != 1 or prev_f != S[ptr_f : ptr_f + 1]:
prev_f = S[ptr_f]
ptr_f += 1
else:
prev_f = S[ptr_f : ptr_f + 2]
ptr_f += 2
div_f += 1
# print(div_f)
prev_i = S_inv[0]
ptr_i = 1
div_i = 0
while ptr_i < Slen:
if len(prev_i) != 1 or prev_i != S[ptr_i : ptr_i + 1]:
prev_i = S[ptr_i]
ptr_i += 1
else:
prev_i = S[ptr_i : ptr_i + 2]
ptr_i += 2
div_i += 1
div_max = max(div_f, div_i)
print(div_max)
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print the maximum positive integer K that satisfies the condition.
* * *
|
s834918129
|
Wrong Answer
|
p02939
|
Input is given from Standard Input in the following format:
S
|
pre_input_line = input("")
input_line = []
for c in pre_input_line:
input_line.append(c)
input_line += ["END"]
string_letters = ""
string_list = []
for i in range(len(input_line) - 1):
if input_line[i] == input_line[i + 1]:
string_letters += input_line[i]
else:
string_letters += input_line[i]
string_list.append(string_letters)
string_letters = ""
string_list.append("")
K = 0
count = 0
for n in range(len(string_list)):
if len(string_list[n]) % 3 == 2:
count += 1
if count == 2:
K += (len(string_list[n - 1]) + len(string_list[n])) // 6 * 4 + 3
count = 0
else:
if count == 1:
K += len(string_list[n - 1]) // 3 * 2 + 1
count = 0
if len(string_list[n]) % 3 == 0:
K += len(string_list[n]) // 3 * 2
else:
K += len(string_list[n]) // 3 * 2 + 1
if count == 1:
K += len(string_list[-1]) // 3 * 2 + 1
print(K)
|
Statement
Given is a string S consisting of lowercase English letters. Find the maximum
positive integer K that satisfies the following condition:
* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).
Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this
order.
|
[{"input": "aabbaa", "output": "4\n \n\nWe can, for example, divide S into four strings `aa`, `b`, `ba`, and `a`.\n\n* * *"}, {"input": "aaaccacabaababc", "output": "12"}]
|
Print N lines. In the i-th line, if it is possible to choose exactly i jewels,
print the maximum possible sum of the values of chosen jewels in that case,
and print -1 otherwise.
* * *
|
s376975084
|
Runtime Error
|
p03144
|
Input is given from Standard Input in the following format:
N K
C_1 V_1
C_2 V_2
:
C_N V_N
|
giveup
|
Statement
There are N jewels, numbered 1 to N. The color of these jewels are represented
by integers between 1 and K (inclusive), and the color of Jewel i is C_i.
Also, these jewels have specified values, and the value of Jewel i is V_i.
Snuke would like to choose some of these jewels to exhibit. Here, the set of
the chosen jewels must satisfy the following condition:
* For each chosen jewel, there is at least one more jewel of the same color that is chosen.
For each integer x such that 1 \leq x \leq N, determine if it is possible to
choose exactly x jewels, and if it is possible, find the maximum possible sum
of the values of chosen jewels in that case.
|
[{"input": "5 2\n 1 1\n 1 2\n 1 3\n 2 4\n 2 5", "output": "-1\n 9\n 6\n 14\n 15\n \n\nWe cannot choose exactly one jewel.\n\nWhen choosing exactly two jewels, the total value is maximized when Jewel 4\nand 5 are chosen.\n\nWhen choosing exactly three jewels, the total value is maximized when Jewel 1,\n2 and 3 are chosen.\n\nWhen choosing exactly four jewels, the total value is maximized when Jewel 2,\n3, 4 and 5 are chosen.\n\nWhen choosing exactly five jewels, the total value is maximized when Jewel 1,\n2, 3, 4 and 5 are chosen.\n\n* * *"}, {"input": "5 2\n 1 1\n 1 2\n 2 3\n 2 4\n 2 5", "output": "-1\n 9\n 12\n 12\n 15\n \n\n* * *"}, {"input": "8 4\n 3 2\n 2 3\n 4 5\n 1 7\n 3 11\n 4 13\n 1 17\n 2 19", "output": "-1\n 24\n -1\n 46\n -1\n 64\n -1\n 77\n \n\n* * *"}, {"input": "15 5\n 3 87\n 1 25\n 1 27\n 3 58\n 2 85\n 5 19\n 5 39\n 1 58\n 3 12\n 4 13\n 5 54\n 4 100\n 2 33\n 5 13\n 2 55", "output": "-1\n 145\n 173\n 285\n 318\n 398\n 431\n 491\n 524\n 576\n 609\n 634\n 653\n 666\n 678"}]
|
If there is a price that satisfies the condition, print an integer
representing the lowest such price; otherwise, print `-1`.
* * *
|
s851312853
|
Wrong Answer
|
p02755
|
Input is given from Standard Input in the following format:
A B
|
A, B = [int(n) for n in input().split()]
XA = 100 * A // 8
XB = 10 * B
r = abs(XA - XB) * 0.1
print(-1 if r > 0.9 else max(XA, XB))
|
Statement
Find the price of a product before tax such that, when the consumption tax
rate is 8 percent and 10 percent, the amount of consumption tax levied on it
is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of
consumption tax is rounded down to the nearest integer.
If multiple prices satisfy the condition, print the lowest such price; if no
price satisfies the condition, print `-1`.
|
[{"input": "2 2", "output": "25\n \n\nIf the price of a product before tax is 25 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible\nprices, such as 26 yen, but print the minimum such price, 25.\n\n* * *"}, {"input": "8 10", "output": "100\n \n\nIf the price of a product before tax is 100 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\n* * *"}, {"input": "19 99", "output": "-1\n \n\nThere is no price before tax satisfying this condition, so print `-1`."}]
|
If there is a price that satisfies the condition, print an integer
representing the lowest such price; otherwise, print `-1`.
* * *
|
s953046693
|
Wrong Answer
|
p02755
|
Input is given from Standard Input in the following format:
A B
|
A, B = (int(i) for i in input().split())
A_p_min = A / 0.08
A_p_max = (A + 1) / 0.08
B_p_min = B / 0.1
B_p_max = (B + 1) / 0.1
cnt = -1
for i in range(int(A_p_max) - 1, int(A_p_min) - 1, -1):
# print(i)
for j in range(int(B_p_max) - 1, int(B_p_min) - 1, -1):
if i == j:
cnt = i
print(cnt)
|
Statement
Find the price of a product before tax such that, when the consumption tax
rate is 8 percent and 10 percent, the amount of consumption tax levied on it
is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of
consumption tax is rounded down to the nearest integer.
If multiple prices satisfy the condition, print the lowest such price; if no
price satisfies the condition, print `-1`.
|
[{"input": "2 2", "output": "25\n \n\nIf the price of a product before tax is 25 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible\nprices, such as 26 yen, but print the minimum such price, 25.\n\n* * *"}, {"input": "8 10", "output": "100\n \n\nIf the price of a product before tax is 100 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\n* * *"}, {"input": "19 99", "output": "-1\n \n\nThere is no price before tax satisfying this condition, so print `-1`."}]
|
If there is a price that satisfies the condition, print an integer
representing the lowest such price; otherwise, print `-1`.
* * *
|
s706377534
|
Wrong Answer
|
p02755
|
Input is given from Standard Input in the following format:
A B
|
print(-1)
|
Statement
Find the price of a product before tax such that, when the consumption tax
rate is 8 percent and 10 percent, the amount of consumption tax levied on it
is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of
consumption tax is rounded down to the nearest integer.
If multiple prices satisfy the condition, print the lowest such price; if no
price satisfies the condition, print `-1`.
|
[{"input": "2 2", "output": "25\n \n\nIf the price of a product before tax is 25 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible\nprices, such as 26 yen, but print the minimum such price, 25.\n\n* * *"}, {"input": "8 10", "output": "100\n \n\nIf the price of a product before tax is 100 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\n* * *"}, {"input": "19 99", "output": "-1\n \n\nThere is no price before tax satisfying this condition, so print `-1`."}]
|
If there is a price that satisfies the condition, print an integer
representing the lowest such price; otherwise, print `-1`.
* * *
|
s470030226
|
Wrong Answer
|
p02755
|
Input is given from Standard Input in the following format:
A B
|
A, B = map(int, input().split())
a = set(map(int, [A / 0.08, (A + 0.5) / 0.1]))
b = set(map(int, [B / 0.1, (B + 0.5) / 0.1]))
ab = a & b
print(list(ab)[0] if len(ab) >= 1 else -1)
|
Statement
Find the price of a product before tax such that, when the consumption tax
rate is 8 percent and 10 percent, the amount of consumption tax levied on it
is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of
consumption tax is rounded down to the nearest integer.
If multiple prices satisfy the condition, print the lowest such price; if no
price satisfies the condition, print `-1`.
|
[{"input": "2 2", "output": "25\n \n\nIf the price of a product before tax is 25 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible\nprices, such as 26 yen, but print the minimum such price, 25.\n\n* * *"}, {"input": "8 10", "output": "100\n \n\nIf the price of a product before tax is 100 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\n* * *"}, {"input": "19 99", "output": "-1\n \n\nThere is no price before tax satisfying this condition, so print `-1`."}]
|
If there is a price that satisfies the condition, print an integer
representing the lowest such price; otherwise, print `-1`.
* * *
|
s865497941
|
Accepted
|
p02755
|
Input is given from Standard Input in the following format:
A B
|
a, b = [int(i) for i in input().split(" ")]
lA = []
lB = []
minV, minID = 0, 0
for i in range(1300):
k = int(i * 0.08)
if minV < k:
lA.append((minID, i - 1))
minV = k
minID = i
minV, minID = 0, 0
for i in range(1300):
k = int(i * 0.1)
if minV < k:
lB.append((minID, i - 1))
minV = k
minID = i
a1, a2 = lA[a]
b1, b2 = lB[b]
for i in range(min(a1, a2, b1, b2), max(a1, a2, b1, b2) + 1):
if a1 <= i and b1 <= i and a2 >= i and b2 >= i:
print(i)
exit(0)
print(-1)
|
Statement
Find the price of a product before tax such that, when the consumption tax
rate is 8 percent and 10 percent, the amount of consumption tax levied on it
is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of
consumption tax is rounded down to the nearest integer.
If multiple prices satisfy the condition, print the lowest such price; if no
price satisfies the condition, print `-1`.
|
[{"input": "2 2", "output": "25\n \n\nIf the price of a product before tax is 25 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible\nprices, such as 26 yen, but print the minimum such price, 25.\n\n* * *"}, {"input": "8 10", "output": "100\n \n\nIf the price of a product before tax is 100 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\n* * *"}, {"input": "19 99", "output": "-1\n \n\nThere is no price before tax satisfying this condition, so print `-1`."}]
|
If there is a price that satisfies the condition, print an integer
representing the lowest such price; otherwise, print `-1`.
* * *
|
s234346985
|
Accepted
|
p02755
|
Input is given from Standard Input in the following format:
A B
|
# N = int(input())
A, B = map(int, input().split())
# X=list(map(int,input().split()))
a = int(A / 0.08)
b = int(B / 0.1)
aa = []
bb = []
if int(a * 0.08) == A:
aa.append(a)
if int(b * 0.1) == B:
bb.append(b)
au = a + 1
ap = a - 1
bu = b + 1
bs = b - 1
f1 = True
f2 = True
f3 = True
f4 = True
while f1 == True or f2 == True:
if int(au * 8 / 100) == A:
aa.append(au)
au += 1
else:
f1 = False
if int(ap * 8 / 100) == A:
aa.append(ap)
ap -= 1
else:
f2 = False
while f3 == True or f4 == True:
if int(bu * 10 / 100) == B:
bb.append(bu)
bu += 1
else:
f3 = False
if int(bs * 8 / 100) == B:
bb.append(bs)
bs -= 1
else:
f4 = False
cc = []
for i in aa:
for j in bb:
if i == j:
cc.append(j)
if len(cc) == 0:
print(-1)
else:
print(min(cc))
|
Statement
Find the price of a product before tax such that, when the consumption tax
rate is 8 percent and 10 percent, the amount of consumption tax levied on it
is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a positive integer, and the amount of
consumption tax is rounded down to the nearest integer.
If multiple prices satisfy the condition, print the lowest such price; if no
price satisfies the condition, print `-1`.
|
[{"input": "2 2", "output": "25\n \n\nIf the price of a product before tax is 25 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.\n\nThus, the price of 25 yen satisfies the condition. There are other possible\nprices, such as 26 yen, but print the minimum such price, 25.\n\n* * *"}, {"input": "8 10", "output": "100\n \n\nIf the price of a product before tax is 100 yen, the amount of consumption tax\nlevied on it is:\n\n * When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.\n * When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.\n\n* * *"}, {"input": "19 99", "output": "-1\n \n\nThere is no price before tax satisfying this condition, so print `-1`."}]
|
For each dataset, your program should output team numbers (from 1 to _T_),
higher ranked teams first. The separator between two team numbers should be a
comma. When two teams are ranked the same, the separator between them should
be an equal sign. Teams ranked the same should be listed in decreasing order
of their team numbers.
|
s087389124
|
Wrong Answer
|
p00768
|
The input is a sequence of datasets each in the following format. The last
dataset is followed by a line with four zeros.
> _M_ _T_ _P_ _R_
> _m_ 1 _t_ 1 _p_ 1 _j_ 1
> _m_ 2 _t_ 2 _p_ 2 _j_ 2
> .....
> _m R_ _t R_ _p R_ _j R_
>
The first line of a dataset contains four integers _M_ , _T_ , _P_ , and _R_.
_M_ is the duration of the contest. _T_ is the number of teams. _P_ is the
number of problems. _R_ is the number of submission records. The relations 120
≤ _M_ ≤ 300, 1 ≤ _T_ ≤ 50, 1 ≤ _P_ ≤ 10, and 0 ≤ _R_ ≤ 2000 hold for these
values. Each team is assigned a team number between 1 and _T_ , inclusive.
Each problem is assigned a problem number between 1 and _P_ , inclusive.
Each of the following _R_ lines contains a submission record with four
integers _m k_, _t k_, _p k_, and _j k_ (1 ≤ _k_ ≤ _R_). _m k_ is the elapsed
time. _t k_ is the team number. _p k_ is the problem number. _j k_ is the
judgment (0 means correct, and other values mean incorrect). The relations 0 ≤
_m k_ ≤ _M_ −1, 1 ≤ _t k_ ≤ _T_ , 1 ≤ _p k_ ≤ _P_ , and 0 ≤ _j k_ ≤ 10 hold
for these values.
The elapsed time fields are rounded off to the nearest minute.
Submission records are given in the order of submission. Therefore, if _i_ <
_j_ , the _i_ -th submission is done before the _j_ -th submission (_m i_ ≤ _m
j_). In some cases, you can determine the ranking of two teams with a
difference less than a minute, by using this fact. However, such a fact is
never used in the team ranking. Teams are ranked only using time information
in minutes.
|
while True:
M, T, P, R = map(int, input().split())
if M == 0 and T == 0 and P == 0 and R == 0:
break
teams = [[0, 0, [0 for _ in range(P)], i + 1] for i in range(T)]
solved, time, miss = 0, 1, 2
logs = [map(int, input().split()) for _ in range(R)]
for m, t, p, r in logs:
t -= 1
p -= 1
if r == 0:
teams[t][solved] += 1
teams[t][time] -= m + teams[t][miss][p] * 20
else:
teams[t][miss][p] += 1
teams = sorted(teams, reverse=True)
before_s, before_t = 0, 0
for i in range(T):
s, t, _, n = teams[i]
if i != 0:
print("=" if (s == before_s and t == before_t) else ",", end="")
before_s, before_t = s, t
print(n, end="")
print("")
|
ICPC Ranking
Your mission in this problem is to write a program which, given the submission
log of an ICPC (International Collegiate Programming Contest), determines team
rankings.
The log is a sequence of records of program submission in the order of
submission. A record has four fields: elapsed time, team number, problem
number, and judgment. The elapsed time is the time elapsed from the beginning
of the contest to the submission. The judgment field tells whether the
submitted program was correct or incorrect, and when incorrect, what kind of
an error was found.
The team ranking is determined according to the following rules. Note that the
rule set shown here is one used in the real ICPC World Finals and Regionals,
with some detail rules omitted for simplification.
1. Teams that solved more problems are ranked higher.
2. Among teams that solve the same number of problems, ones with smaller total consumed time are ranked higher.
3. If two or more teams solved the same number of problems, and their total consumed times are the same, they are ranked the same.
The total consumed time is the sum of the consumed time for each problem
solved. The consumed time for a solved problem is the elapsed time of the
accepted submission plus 20 penalty minutes for every previously rejected
submission for that problem.
If a team did not solve a problem, the consumed time for the problem is zero,
and thus even if there are several incorrect submissions, no penalty is given.
You can assume that a team never submits a program for a problem after the
correct submission for the same problem.
|
[{"input": "10 8 5\n 50 5 2 1\n 70 5 2 0\n 75 1 1 0\n 100 3 1 0\n 150 3 2 0\n 240 5 5 7\n 50 1 1 0\n 60 2 2 0\n 70 2 3 0\n 90 1 3 0\n 120 3 5 0\n 140 4 1 0\n 150 2 4 1\n 180 3 5 4\n 15 2 2 1\n 20 2 2 1\n 25 2 2 0\n 60 1 1 0\n 120 5 5 4\n 15 5 4 1\n 20 5 4 0\n 40 1 1 0\n 40 2 2 0\n 120 2 3 4\n 30 1 1 0\n 40 2 1 0\n 50 2 2 0\n 60 1 2 0\n 120 3 3 2\n 0 1 1 0\n 1 2 2 0\n 300 5 8 0\n 0 0 0 0", "output": ",1,5,10=9=8=7=6=4=2\n 2,1,3,4,5\n 1,2,3\n 5=2=1,4=3\n 2=1\n 1,2,3\n 5=4=3=2=1"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s720167784
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
N = int(input())
MOD = 10**9 + 7
dp = [[0] * 3 for _ in range(61)]
dp[60][0] = 1
for d in range(59, -1, -1):
for s in range(3):
for k in range(3):
ns = min(2, 2 * s + ((N >> d) & 1) - k)
if ns < 0:
continue
dp[d][ns] += dp[d + 1][s]
dp[d][ns] %= MOD
print(sum(dp[0]) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s112264618
|
Wrong Answer
|
p03847
|
The input is given from Standard Input in the following format:
N
|
n = int(input())
print(n * (n - 1) / 2)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s139191039
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = float("INF")
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
dp = [[0] * 3 for _ in range(62)]
dp[0][0] = 1
for i in range(61):
zero, one, two = dp[i]
if n >> (60 - i) & 1:
zero, one, two = zero, zero + one, 2 * one + 3 * two
else:
zero, one, two = zero + one, one, one + 3 * two
dp[i + 1] = [zero % mod, one % mod, two % mod]
print(sum(dp[-1]) % mod)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s645787019
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
n = int(input())
mod = 10**9 + 7
bt = bin(n)[2:]
k = len(bt)
dp = [[0] * 2 for i in range(k + 1)]
dp[0][0] = 1
dp[0][1] = 1
for i in range(k):
j = int(bt[k - i - 1])
a, b, c = [(1, 0, 0), (1, 1, 0)][j]
d, e, f = [(1, 1, 1), (0, 1, 2)][j]
dp[i + 1][0] = (a * dp[i][0] + b * dp[i][1] + c * (3**i)) % mod
dp[i + 1][1] = (d * dp[i][0] + e * dp[i][1] + f * (3**i)) % mod
print(dp[k][0])
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s303372584
|
Runtime Error
|
p03847
|
The input is given from Standard Input in the following format:
N
|
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
N, K, L = map(int, input().split())
mark = 0
U1 = UnionFind(N)
U2 = UnionFind(N)
for i in range(K):
p, q = map(int, input().split())
U1.unite(p - 1, q - 1)
for i in range(L):
r, s = map(int, input().split())
U2.unite(r - 1, s - 1)
List = []
for i in range(N):
List.append((U1.par[i], U2.par[i], i))
List = sorted(List)
cnt = 0
member = []
ans = [0] * N
for i in range(N - 1):
if List[i][0] == List[i + 1][0] and List[i][1] == List[i + 1][1]:
cnt += 1
if member:
member.append(List[i + 1][2])
else:
member.append(List[i][2])
member.append(List[i + 1][2])
else:
for j in member:
ans[j] = cnt
cnt = 0
member = []
for j in member:
ans[j] = cnt
for i in range(N):
print(ans[i] + 1)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s286306026
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
n = int(input())
a = format(n, "b")
mod = 1000000007
dp = [[0 for j in range(3)] for i in range(len(a) + 1)]
dp[0][0] = 1
for i in range(len(a)):
for j in range(3):
for x in range(2):
for y in range(x, 2):
b = (n >> i) & 1
dp[i + 1][(x + y + j - b + 1) // 2] = (
dp[i + 1][(x + y + j - b + 1) // 2] + dp[i][j]
) % mod
print(dp[len(a)][0])
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s725438402
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
N = int(input())
mod = 10**9 + 7
ANSLIST = [1]
for i in range(61):
ANSLIST.append((ANSLIST[-1] * 3 - 1) % mod)
ANS = [1, 2, 4, 5]
ANSDICT = dict()
def ans(k):
if 0 <= k <= 3:
return ANS[k]
if ANSDICT.get(k) != None:
return ANSDICT[k]
for i in range(61):
if k == 2**i - 2:
return ANSLIST[i] - 1
if k == 2**i - 1:
return ANSLIST[i]
if 2**i - 1 > k:
break
x = k - (2 ** (i - 1) - 1)
ANSDICT[k] = (ans(x - 1) + ANSLIST[i - 1] * 2 - ans(2 ** (i - 1) - x - 2) - 1) % mod
return ANSDICT[k]
print(ans(N))
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s131804132
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
P = 10**9 + 7
inv2 = (1 + P) // 2
def exp(a, k):
if k == 0:
return 1
elif k % 2 == 0:
return (exp(a * a, k // 2)) % P
else:
return (a * exp(a * a, k // 2)) % P
D = dict()
def f(N):
if N in D:
return D[N]
if N <= 1:
D[N] = N
return N
i = 0
while 1:
if 2**i <= N < 2 ** (i + 1):
break
i += 1
if N == 2**i:
D[N] = ((1 + exp(3, i)) * inv2) % P
return D[N]
D[N] = (f(N - 2**i) - f(2 ** (i + 1) - N - 1) + exp(3, i)) % P
return D[N]
print(f(int(input()) + 1))
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s147404717
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N = INT()
N = format(N, "060b")[::-1]
# N[i] := Nのiビット目としておく
N = [0] + list(map(int, N))
# dp[i][j] := iビット目まで見て、その桁までの値において、a+b がNより j*2^i 小さい通り数(j>=2はj=2で同一視)
dp = list2d(61, 3, 0)
dp[60][0] = 1
for i in range(60, 0, -1):
# jの状態 j=0,1,2以上 の3通り
for j in range(3):
# 今回の桁でのa,bの選び方 (0,0)=0,(0,1)=1,(1,1)=2 の3通り
for k in range(3):
# 1桁下がる時に、現在のjは 2^i = 2*2^(i-1) から、*2される
# Nのビットが立っている桁なら1を足す
# 今回追加するk(0~2)を引く
nxt = min(j * 2 + N[i] - k, 2)
# nxtがマイナスなら繰り上がりでNを超えるので遷移させない
if nxt >= 0:
dp[i - 1][nxt] += dp[i][j]
dp[i - 1][nxt] %= MOD
print((dp[0][0] + dp[0][1] + dp[0][2]) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s908365402
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
N = int(input())
a, b, c = 1, 0, 0
for i in range(80)[::-1]:
if N >> i & 1:
a, b, c = a, a + b, 2 * b + 3 * c
else:
a, b, c = a + b, b, b + 3 * c
print((a + b + c) % (10**9 + 7))
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s531392066
|
Runtime Error
|
p03847
|
The input is given from Standard Input in the following format:
N
|
MOD = int(1e9) + 7
N = int(input())
dp = [1,0,0]
for i in range(64,-1,-1):
ndp = [0,0,0]
for d in range(3):
nd = d*2 + (n>>>i&1)
ndp[min(2,nd)] += dp[d]
if nd >= 1: ndp[min(2,nd-1)] += dp[d]
if nd >= 2: ndp[min(2,nd-2)] += dp[d]
dp = ndp
print(sum(dp) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s758801126
|
Runtime Error
|
p03847
|
The input is given from Standard Input in the following format:
N
|
MOD = int(1e9) + 7
N = int(input())
dp[0][0] = 1
for i in range(64,-1,-1):
ndp[0][0] = 0
for d in range(3):
nd = d*2 + (N>>>i&1)
ndp[min(2,nd)] += dp[d]
if nd >= 1: ndp[min(2,nd-1)] += dp[d]
if nd >= 2: ndp[min(2,nd-2)] += dp[d]
dp = ndp
print(sum(dp) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s686006672
|
Wrong Answer
|
p03847
|
The input is given from Standard Input in the following format:
N
|
# 桁DP 要復習
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s204293712
|
Runtime Error
|
p03847
|
The input is given from Standard Input in the following format:
N
|
MOD = 10**9+7
N = int(input())
dp = [1,0,0]
for i in range(64,-1,-1):
ndp = [0,0,0]
for d in range(3):
nd = d*2 + (n>>>i&1)
ndp[min(2,nd)] += dp[d]
if nd >= 1: ndp[min(2,nd-1)] += dp[d]
if nd >= 2: ndp[min(2,nd-2)] += dp[d]
dp = ndp
print(sum(dp) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s648507151
|
Runtime Error
|
p03847
|
The input is given from Standard Input in the following format:
N
|
MOD = int(10**9)+7
N = int(input())
dp[0][0] = 1
for i in range(64,-1,-1):
ndp = [0,0,0]
for d in range(3):
nd = d*2 + (N>>>i&1)
ndp[min(2,nd)] += dp[d]
if nd >= 1: ndp[min(2,nd-1)] += dp[d]
if nd >= 2: ndp[min(2,nd-2)] += dp[d]
dp = ndp
print(sum(dp) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
* * *
|
s619788243
|
Accepted
|
p03847
|
The input is given from Standard Input in the following format:
N
|
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# 解説AC
N = int(sys.stdin.readline())
# # dp[i][j]: 右からiビット目まで決まってて、vがjとなるパターン数
# dp = [[0] * (N + 1) for _ in range(N.bit_length())]
# # 両方0
# dp[0][0] += 1
# # 片方1
# dp[0][1] += 1
# # 両方1
# dp[0][2] += 1
# for i in range(1, N.bit_length()):
# for j in range(N + 1):
# # 両方0
# dp[i][j] += dp[i - 1][j]
# # 片方1
# if j + pow(2, i) <= N:
# dp[i][j + pow(2, i)] += dp[i - 1][j]
# # 両方1
# if j + pow(2, i + 1) <= N:
# dp[i][j + pow(2, i + 1)] += dp[i - 1][j]
# print(sum(dp[-1]))
# # dp[j]: vがjとなるパターン数
# # 上から決めてく
# dp = [0] * (N + 1)
# # 両方0
# dp[0] = 1
# # 片方1
# dp[1 << (N.bit_length() - 1)] = 1
# for i in reversed(range(N.bit_length() - 1)):
# for j in reversed(range(N + 1)):
# # 片方1
# if j + pow(2, i) <= N:
# dp[j + pow(2, i)] += dp[j]
# # 両方1
# if j + pow(2, i + 1) <= N:
# dp[j + pow(2, i + 1)] += dp[j]
# print(dp)
# print(sum(dp))
# # dp[i][j]: 右からiビット目まで決まってて、N-vがjとなるパターン数
# # 上から決めてく
# dp = [[0] * (N + 1) for _ in range(N.bit_length())]
# # 両方0
# dp[-1][-1] = 1
# # 片方1
# dp[-1][N - (1 << (N.bit_length() - 1))] = 1
# for i in reversed(range(N.bit_length() - 1)):
# for j in reversed(range(N + 1)):
# # 両方0
# dp[i][j] += dp[i + 1][j]
# # 片方1
# if j - (1 << i) >= 0:
# dp[i][j - (1 << i)] += dp[i + 1][j]
# # 両方1
# if j - (1 << i + 1) >= 0:
# dp[i][j - (1 << i + 1)] += dp[i + 1][j]
# print(dp)
# print(sum(dp[0]))
# # dp[i][j]: 右からiビット目まで決まってて、(N>>i)-(v>>i)がjとなるパターン数
# # 上から決めてく
# dp = [[0] * (N * 3) for _ in range(N.bit_length())]
# # 両方0
# dp[-1][1] = 1
# # 片方1
# dp[-1][0] = 1
# for i in reversed(range(N.bit_length() - 1)):
# for j in reversed(range(N + 1)):
# if N >> i & 1:
# # 両方0
# dp[i][(j << 1) + 1] += dp[i + 1][j]
# # 片方1
# dp[i][j << 1] += dp[i + 1][j]
# if j > 0:
# # 両方1
# dp[i][(j << 1) - 1] += dp[i + 1][j]
# else:
# # 両方0
# dp[i][j << 1] += dp[i + 1][j]
# if j > 0:
# # 片方1
# dp[i][(j << 1) - 1] += dp[i + 1][j]
# # 両方1
# dp[i][(j << 1) - 2] += dp[i + 1][j]
# print(dp)
# print(sum(dp[0]))
# dp[i][j]: 右からiビット目まで決まってて、(N>>i)-(v>>i)がjとなるパターン数
# j >= 2 以降は j <= 1 に入ってこないので j == 2 としてまとめる
# 上から決めてく
dp = [[0] * 3 for _ in range(N.bit_length())]
# 両方0
dp[-1][1] = 1
# 片方1
dp[-1][0] = 1
for i in reversed(range(N.bit_length() - 1)):
if N >> i & 1:
# 両方0
# dp[i][(j << 1) + 1] += dp[i + 1][j]
dp[i][1] += dp[i + 1][0]
dp[i][2] += dp[i + 1][1]
dp[i][2] += dp[i + 1][2]
# 片方1
# dp[i][j << 1] += dp[i + 1][j]
dp[i][0] += dp[i + 1][0]
dp[i][2] += dp[i + 1][1]
dp[i][2] += dp[i + 1][2]
# 両方1
# dp[i][(j << 1) - 1] += dp[i + 1][j]
dp[i][1] += dp[i + 1][1]
dp[i][2] += dp[i + 1][2]
else:
# 両方0
# dp[i][j << 1] += dp[i + 1][j]
dp[i][0] += dp[i + 1][0]
dp[i][2] += dp[i + 1][1]
dp[i][2] += dp[i + 1][2]
# 片方1
# dp[i][(j << 1) - 1] += dp[i + 1][j]
dp[i][1] += dp[i + 1][1]
dp[i][2] += dp[i + 1][2]
# 両方1
# dp[i][(j << 1) - 2] += dp[i + 1][j]
dp[i][0] += dp[i + 1][1]
dp[i][2] += dp[i + 1][2]
dp[i][0] %= MOD
dp[i][1] %= MOD
dp[i][2] %= MOD
print(sum(dp[0]) % MOD)
|
Statement
You are given a positive integer N. Find the number of the pairs of integers u
and v (0≦u,v≦N) such that there exist two non-negative integers a and b
satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.
|
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
|
Print "4", "3", "2", "1" or "0" in a line.
|
s496397726
|
Accepted
|
p02305
|
Coordinates and radii of $c1$ and $c2$ are given in the following format.
$c1x \; c1y \; c1r$
$c2x \; c2y \; c2r$
$c1x$, $c1y$ and $c1r$ represent the center coordinate and radius of the first
circle. $c2x$, $c2y$ and $c2r$ represent the center coordinate and radius of
the second circle. All input values are given in integers.
|
import math
from enum import Enum, auto
class TwoCircle(Enum):
DISTANT = auto()
CIRCUMCSCRIBING = auto()
INTERSECTING = auto()
INSCRIBING = auto()
CONTAINING = auto()
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def distance(self, pnt):
return math.sqrt((self.x - pnt.x) ** 2 + (self.y - pnt.y) ** 2)
class Circle:
def __init__(self, x, y, r):
self.c = Point(x, y)
self.r = r
def is_intersected(self, cir):
d = self.c.distance(cir.c)
if d > self.r + cir.r:
return TwoCircle.DISTANT
elif d == self.r + cir.r:
return TwoCircle.CIRCUMCSCRIBING
elif d == abs(self.r - cir.r):
return TwoCircle.INSCRIBING
elif d < abs(self.r - cir.r):
return TwoCircle.CONTAINING
else:
return TwoCircle.INTERSECTING
x1, y1, r1 = list(map(int, input().split(" ")))
x2, y2, r2 = list(map(int, input().split(" ")))
cir1 = Circle(x1, y1, r1)
cir2 = Circle(x2, y2, r2)
judged = cir1.is_intersected(cir2)
if judged == TwoCircle.DISTANT:
print(4)
elif judged == TwoCircle.CIRCUMCSCRIBING:
print(3)
elif judged == TwoCircle.INTERSECTING:
print(2)
elif judged == TwoCircle.INSCRIBING:
print(1)
elif judged == TwoCircle.CONTAINING:
print(0)
|
Intersection of Circles
For given two circles $c1$ and $c2$, print
4
if they do not cross (there are 4 common tangent lines),
3
if they are circumscribed (there are 3 common tangent lines),
2
if they intersect (there are 2 common tangent lines),
1
if a circle is inscribed in another (there are 1 common tangent line),
0
if a circle includes another (there is no common tangent line).
|
[{"input": "1 1 1\n 6 2 2", "output": "4"}, {"input": "1 2 1\n 4 2 2", "output": "3"}, {"input": "1 2 1\n 3 2 2", "output": "2"}, {"input": "0 0 1\n 1 0 2", "output": "1"}, {"input": "0 0 1\n 0 0 2", "output": "0"}]
|
Print "4", "3", "2", "1" or "0" in a line.
|
s216292788
|
Runtime Error
|
p02305
|
Coordinates and radii of $c1$ and $c2$ are given in the following format.
$c1x \; c1y \; c1r$
$c2x \; c2y \; c2r$
$c1x$, $c1y$ and $c1r$ represent the center coordinate and radius of the first
circle. $c2x$, $c2y$ and $c2r$ represent the center coordinate and radius of
the second circle. All input values are given in integers.
|
# Single Source Shortest Path
class node:
def __init__(self, v, cost):
self.v = v
self.cost = cost
infty = 999999999
dict_c = {}
[vertex, edge, r] = list(map(int, input("").split()))
root_c = [node(r, 0)]
final_c = [infty for i in range(vertex)]
final_c[r] = 0
for i in range(edge):
[e1, e2, c] = list(map(int, input("").split()))
if e1 == r:
root_c.append(node(e2, c))
final_c[e2] = c
else:
dict_c[(e1, e2)] = c
def min_heap(i):
global root_c
l = 2 * i
r = 2 * i + 1
if l <= len(root_c) - 1 and root_c[l].cost <= root_c[i].cost:
if root_c[l].cost < root_c[i].cost:
min = l
elif root_c[l].v < root_c[i].v:
min = l
else:
min = i
else:
min = i
if r <= len(root_c) - 1 and root_c[r].cost <= root_c[min].cost:
if root_c[r].cost < root_c[min].cost:
min = r
elif root_c[r].v < root_c[min].v:
min = r
# else:
if min != i:
root_c[i], root_c[min] = root_c[min], root_c[i]
min_heap(min)
def build_min_heap():
global root_c
length = len(root_c) - 1
for i in range(int(length / 2), 0, -1):
min_heap(i)
def extract_min():
global root_c
min = root_c[1]
# print("min_cost ", root_c[1].cost, root_c[2].cost, root_c[3].cost, root_c[4].cost, root_c[5].cost, root_c[6].cost, root_c[7].cost)
# print("min_vertex", root_c[1].v, root_c[2].v, root_c[3].v, root_c[4].v, root_c[5].v, root_c[6].v, root_c[7].v)
root_c[1] = root_c[len(root_c) - 1]
# print("1: ",root_c[1].cost, root_c[1].v)
del root_c[len(root_c) - 1]
min_heap(1)
# print("min_cost 2", root_c[1].cost, root_c[2].cost, root_c[3].cost, root_c[4].cost, root_c[5].cost, root_c[6].cost)
# print("min_vertex2", root_c[1].v, root_c[2].v, root_c[3].v, root_c[4].v, root_c[5].v, root_c[6].v)
# print("length: ",len(root_c))
return min
def decrease_key(i, c):
global root_c
root_c[i].cost = c
while i > 1 and root_c[int(i / 2)].cost >= root_c[i].cost:
if root_c[int(i / 2)].cost > root_c[i].cost:
root_c[int(i / 2)], root_c[i] = root_c[i], root_c[int(i / 2)]
elif root_c[int(i / 2)].v > root_c[i].v:
root_c[int(i / 2)], root_c[i] = root_c[i], root_c[int(i / 2)]
else:
root_c[int(i / 2)], root_c[i] = root_c[int(i / 2)], root_c[i]
i = int(i / 2)
def min_insert(v, c):
global infty, root_c
for i in range(1, len(root_c)):
if root_c[i].v == v:
decrease_key(i, c)
return
root_c.append(node(v, infty))
decrease_key(len(root_c) - 1, c)
def Dijkstra(root, n):
count = 1
global infty, dict_c, root_c, final_c
label = [i for i in range(n)]
# print(count, label[root], final_c[label[root]])
count += 1
del label[root]
while len(label) != 0:
if len(root_c) > 1:
min_node = extract_min()
else:
break
for i in range(len(label)):
if min_node.v == label[i]:
delete_label = i
continue
if ((min_node.v, label[i]) in dict_c.keys()) == True:
if (
final_c[label[i]]
> final_c[min_node.v] + dict_c[(min_node.v, label[i])]
):
final_c[label[i]] = (
final_c[min_node.v] + dict_c[(min_node.v, label[i])]
)
min_insert(label[i], final_c[label[i]])
# print(count, label[delete_label], final_c[label[delete_label]])
count += 1
del label[delete_label]
build_min_heap()
"""
print("root_c :")
for i in range(len(root_c)):
print(root_c[i].cost)
print("\n")
"""
Dijkstra(r, vertex)
# print("\n")
for i in range(vertex):
if final_c[i] == infty:
print("INF")
else:
print(final_c[i])
|
Intersection of Circles
For given two circles $c1$ and $c2$, print
4
if they do not cross (there are 4 common tangent lines),
3
if they are circumscribed (there are 3 common tangent lines),
2
if they intersect (there are 2 common tangent lines),
1
if a circle is inscribed in another (there are 1 common tangent line),
0
if a circle includes another (there is no common tangent line).
|
[{"input": "1 1 1\n 6 2 2", "output": "4"}, {"input": "1 2 1\n 4 2 2", "output": "3"}, {"input": "1 2 1\n 3 2 2", "output": "2"}, {"input": "0 0 1\n 1 0 2", "output": "1"}, {"input": "0 0 1\n 0 0 2", "output": "0"}]
|
Print T lines. The i-th line should contain the answer to the i-th test case.
* * *
|
s133946991
|
Runtime Error
|
p02610
|
Input is given from Standard Input in the following format:
T
\mathrm{case}_1
\vdots
\mathrm{case}_T
Each case is given in the following format:
N
K_1 L_1 R_1
\vdots
K_N L_N R_N
|
n = int(input())
x = list(input())
cnt = x.count("1")
def popcount(x):
"""xの立っているビット数をカウントする関数
(xは64bit整数)"""
# 2bitごとの組に分け、立っているビット数を2bitで表現する
x = x - ((x >> 1) & 0x5555555555555555)
# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F # 8bitごと
x = x + (x >> 8) # 16bitごと
x = x + (x >> 16) # 32bitごと
x = x + (x >> 32) # 64bitごと = 全部の合計
return x & 0x0000007F
for i in range(n):
y = x[:]
if x[i] == "1":
y[i] = "0"
z = "".join(y)
z = int(z, 2)
z %= cnt - 1
if z == 0:
print(1)
else:
ans = 1
while z > 0:
z %= popcount(z)
ans += 1
print(ans)
else:
y[i] = "1"
z = "".join(y)
z = int(z, 2)
z %= cnt + 1
if z == 0:
print(1)
else:
ans = 1
while z > 0:
z %= popcount(z)
ans += 1
print(ans)
|
Statement
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find the maximum
possible total happiness of the camel.
Solve this problem for each of the T test cases given.
|
[{"input": "3\n 2\n 1 5 10\n 2 15 5\n 3\n 2 93 78\n 1 71 59\n 3 57 96\n 19\n 19 23 16\n 5 90 13\n 12 85 70\n 19 67 78\n 12 16 60\n 18 48 28\n 5 4 24\n 12 97 97\n 4 57 87\n 19 91 74\n 18 100 76\n 7 86 46\n 9 100 57\n 3 76 73\n 6 84 93\n 1 6 84\n 11 75 94\n 19 15 3\n 12 11 34", "output": "25\n 221\n 1354\n \n\n * In the first test case, it is optimal to line up the camels in the order 2, 1.\n * Camel 1 is not the frontmost camel, so its happiness will be 10.\n * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n * Camel 2 is the frontmost camel, so its happiness will be 71.\n * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]
|
Print T lines. The i-th line should contain the answer to the i-th test case.
* * *
|
s812192540
|
Accepted
|
p02610
|
Input is given from Standard Input in the following format:
T
\mathrm{case}_1
\vdots
\mathrm{case}_T
Each case is given in the following format:
N
K_1 L_1 R_1
\vdots
K_N L_N R_N
|
import sys
from heapq import heappush, heappop
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**-10
for _ in range(INT()):
N = INT()
ans = 0
adjli1 = [[] for i in range(N)]
adjli2 = [[] for i in range(N + 1)]
for _ in range(N):
k, l, r = MAP()
k -= 1
if l > r:
adjli1[k].append(l - r)
elif l < r:
adjli2[k + 1].append(r - l)
ans += min(l, r)
que = []
for i in range(N):
for a in adjli1[i]:
heappush(que, a)
while len(que) > i + 1:
heappop(que)
ans += sum(que)
que = []
for i in range(N - 1, -1, -1):
for a in adjli2[i]:
heappush(que, a)
while len(que) > N - i:
heappop(que)
ans += sum(que)
print(ans)
|
Statement
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find the maximum
possible total happiness of the camel.
Solve this problem for each of the T test cases given.
|
[{"input": "3\n 2\n 1 5 10\n 2 15 5\n 3\n 2 93 78\n 1 71 59\n 3 57 96\n 19\n 19 23 16\n 5 90 13\n 12 85 70\n 19 67 78\n 12 16 60\n 18 48 28\n 5 4 24\n 12 97 97\n 4 57 87\n 19 91 74\n 18 100 76\n 7 86 46\n 9 100 57\n 3 76 73\n 6 84 93\n 1 6 84\n 11 75 94\n 19 15 3\n 12 11 34", "output": "25\n 221\n 1354\n \n\n * In the first test case, it is optimal to line up the camels in the order 2, 1.\n * Camel 1 is not the frontmost camel, so its happiness will be 10.\n * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n * Camel 2 is the frontmost camel, so its happiness will be 71.\n * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]
|
Print T lines. The i-th line should contain the answer to the i-th test case.
* * *
|
s694534960
|
Accepted
|
p02610
|
Input is given from Standard Input in the following format:
T
\mathrm{case}_1
\vdots
\mathrm{case}_T
Each case is given in the following format:
N
K_1 L_1 R_1
\vdots
K_N L_N R_N
|
# from collections import deque,defaultdict
printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
# R = 998244353
def ddprint(x):
if DBG:
print(x)
# # # # class Segtree # # # #
# 0
# 1 2
# 3 4 5 6
# :
# leaf i - n-1+i
# parent - (i-1)//2
# children - 2*i+1, 2*i+2
class Segtree:
# modify UNIT and oper depending on the reduce operation
# UNIT = 0 # sum/or:0 and:fff..f min:BIG max:-BIG gcd:0 lcm:1 ..
# @classmethod
# def oper(c,x,y):
# return x|y # sum:+ or/and/min/max/gcd/lcm:(same)
# call like this: sgt = Segtree(n, 0, lambda x,y: max(x,y))
def __init__(s, l, unit, oper):
s.unit = unit
s.oper = oper
s.n = 1
while s.n < l:
s.n *= 2
s.ary = [s.unit for i in range(2 * s.n - 1)]
def get(s, i):
return s.ary[i + s.n - 1]
def set(s, i, v):
k = i + s.n - 1
s.ary[k] = v
while k > 0:
k = (k - 1) // 2
s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])
def setary(s, a):
for i, v in enumerate(a):
s.ary[i + s.n - 1] = v
for k in range(s.n - 2, -1, -1):
s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])
def query(s, x, y):
l = x + s.n - 1
r = y + s.n - 1
res = s.unit
while l < r:
if not l % 2:
res = s.oper(res, s.ary[l])
l += 1
if not r % 2:
r -= 1
res = s.oper(res, s.ary[r])
l >>= 1
r >>= 1
return res
# # # # class Segtree end # # # #
t = inn()
for tt in range(t):
# ddprint(f"{tt=}")
n = inn()
klr = []
nl = 0
for i in range(n):
k, l, r = inm()
klr.append((abs(l - r), (-k if l > r else -(n + 1 - k)), i, k, l, r))
if l > r:
nl += 1
klrc = [z for z in klr]
klr.sort(reverse=True)
h = {}
tol = Segtree(n, -1, lambda x, y: max(x, y))
tor = Segtree(n, n + 1, lambda x, y: min(x, y))
tol.setary(list(range(n)))
tor.setary(list(range(n)))
for j in range(n):
v, w, i, k, l, r = klr[j]
if k == n:
continue
if l > r:
x = min(nl - 1, k - 1)
m = tol.query(0, x + 1)
if m < 0:
continue
tol.set(m, -1)
h[m] = i
else:
x = max(nl, k)
m = tor.query(x, n)
if m > n:
continue
tor.set(m, n + 1)
h[m] = i
# ddprint(f"{j=} {i=} {x=} {m=} {k=} {l=} {r=} {v=} {w=}")
# ddprint(f"h1 {h}")
put = {}
for x in h:
put[h[x]] = 1
top = 0
for i in range(n):
if i in put:
continue
while top in h:
top += 1
h[top] = i
# ddprint(f"h2 {h}")
rev = [-1] * n
sm = 0
for i in range(n):
j = h[i]
v, w, ii, k, l, r = klrc[j]
sm += l if i <= k - 1 else r
# ddprint(f"{i=} {j=} {k=} {sm=}")
print(sm)
|
Statement
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find the maximum
possible total happiness of the camel.
Solve this problem for each of the T test cases given.
|
[{"input": "3\n 2\n 1 5 10\n 2 15 5\n 3\n 2 93 78\n 1 71 59\n 3 57 96\n 19\n 19 23 16\n 5 90 13\n 12 85 70\n 19 67 78\n 12 16 60\n 18 48 28\n 5 4 24\n 12 97 97\n 4 57 87\n 19 91 74\n 18 100 76\n 7 86 46\n 9 100 57\n 3 76 73\n 6 84 93\n 1 6 84\n 11 75 94\n 19 15 3\n 12 11 34", "output": "25\n 221\n 1354\n \n\n * In the first test case, it is optimal to line up the camels in the order 2, 1.\n * Camel 1 is not the frontmost camel, so its happiness will be 10.\n * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n * Camel 2 is the frontmost camel, so its happiness will be 71.\n * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]
|
Print T lines. The i-th line should contain the answer to the i-th test case.
* * *
|
s423592433
|
Wrong Answer
|
p02610
|
Input is given from Standard Input in the following format:
T
\mathrm{case}_1
\vdots
\mathrm{case}_T
Each case is given in the following format:
N
K_1 L_1 R_1
\vdots
K_N L_N R_N
|
class BinaryIndexedTree:
def __init__(self, size):
self.data = [0] * (size + 1)
self.msb = 1 << (size.bit_length() - 1)
def _add(self, i, w):
i += 1
while i < len(self.data):
self.data[i] += w
i += i & -i
def _get_sum(self, i):
res = 0
while i > 0:
res += self.data[i]
i -= i & -i
return res
def __getitem__(self, i):
"""
[0,i)
"""
if isinstance(i, slice):
if i.start is None:
return self._get_sum(i.stop)
else:
return self._get_sum(i.stop) - self._get_sum(i.start)
else:
return 0 # fake value
__setitem__ = _add
def bisect_left(self, v):
"""
return smallest i s.t v <= sum[:i]
"""
i = 0
k = self.msb
while k > 0:
i += k
if i < len(self.data) and self.data[i] < v:
v -= self.data[i]
else:
i -= k
k >>= 1
return i
def bisect_right(self, v):
"""
return smallest i s.t v < sum[:i]
"""
i = 0
k = self.msb
while k > 0:
i += k
if i < len(self.data) and self.data[i] <= v:
v -= self.data[i]
else:
i -= k
k >>= 1
return i
bisect = bisect_right
def solve(KLR):
min2 = lambda x, y: x if x < y else y
N = len(KLR)
offset = sum(min2(l, r) for k, l, r in KLR)
KLR.sort()
p = sorted(
(l - r, k, i, True) if l > r else (r - l, k, i, False)
for i, (k, l, r) in enumerate(KLR)
)
lbit = BinaryIndexedTree(N)
rbit = BinaryIndexedTree(N)
res = 0
for v, k, i, is_l in p:
if is_l:
if lbit[:i] + 1 <= k:
lbit[i] += 1
res += v
else:
rbit[i] += 1
else:
if rbit[i + 1 : N] + 1 <= N - k:
rbit[i] += 1
res += v
else:
lbit[i] += 1
return res + offset
if __name__ == "__main__":
T = int(input())
for t in range(T):
N = int(input())
KLR = [tuple(map(int, input().split())) for _ in range(N)]
print(solve(KLR))
|
Statement
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find the maximum
possible total happiness of the camel.
Solve this problem for each of the T test cases given.
|
[{"input": "3\n 2\n 1 5 10\n 2 15 5\n 3\n 2 93 78\n 1 71 59\n 3 57 96\n 19\n 19 23 16\n 5 90 13\n 12 85 70\n 19 67 78\n 12 16 60\n 18 48 28\n 5 4 24\n 12 97 97\n 4 57 87\n 19 91 74\n 18 100 76\n 7 86 46\n 9 100 57\n 3 76 73\n 6 84 93\n 1 6 84\n 11 75 94\n 19 15 3\n 12 11 34", "output": "25\n 221\n 1354\n \n\n * In the first test case, it is optimal to line up the camels in the order 2, 1.\n * Camel 1 is not the frontmost camel, so its happiness will be 10.\n * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n * Camel 2 is the frontmost camel, so its happiness will be 71.\n * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]
|
Print T lines. The i-th line should contain the answer to the i-th test case.
* * *
|
s554962451
|
Wrong Answer
|
p02610
|
Input is given from Standard Input in the following format:
T
\mathrm{case}_1
\vdots
\mathrm{case}_T
Each case is given in the following format:
N
K_1 L_1 R_1
\vdots
K_N L_N R_N
|
t = int(input())
nlist = []
klists = []
for i in range(t):
n = int(input())
nlist.append(n)
klist = []
for j in range(n):
klist.append(input())
klists.append(klist)
for i in range(t):
n = nlist[i]
klist = klists[i]
l_list = []
r_list = []
for j in range(n):
k, l, r = map(int, klist[j].split())
if l - r > 0:
l_list.append([k, l, r])
else:
r_list.append([k, l, r])
l_list.sort(key=lambda x: (x[1] - x[2]), reverse=True)
l_list.sort(key=lambda x: x[0])
r_list.sort(key=lambda x: (x[1] - x[2]), reverse=True)
r_list.sort(key=lambda x: x[0])
l_list.extend(r_list)
sort_list = l_list
ans_list = []
temp_list = []
for j in range(n):
while sort_list != [] and sort_list[0][0] <= j + 1:
temp_list.append(sort_list[0])
sort_list.pop(0)
temp_list.sort(key=lambda x: (x[1] - x[2]), reverse=True)
while temp_list != [] and len(ans_list) < j + 1:
ans_list.append(temp_list[0])
temp_list.pop(0)
while temp_list != []:
ans_list.append(temp_list[0])
temp_list.pop(0)
sum = 0
for j in range(n):
if ans_list[j][0] >= j + 1:
sum += ans_list[j][1]
else:
sum += ans_list[j][2]
print(sum)
|
Statement
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find the maximum
possible total happiness of the camel.
Solve this problem for each of the T test cases given.
|
[{"input": "3\n 2\n 1 5 10\n 2 15 5\n 3\n 2 93 78\n 1 71 59\n 3 57 96\n 19\n 19 23 16\n 5 90 13\n 12 85 70\n 19 67 78\n 12 16 60\n 18 48 28\n 5 4 24\n 12 97 97\n 4 57 87\n 19 91 74\n 18 100 76\n 7 86 46\n 9 100 57\n 3 76 73\n 6 84 93\n 1 6 84\n 11 75 94\n 19 15 3\n 12 11 34", "output": "25\n 221\n 1354\n \n\n * In the first test case, it is optimal to line up the camels in the order 2, 1.\n * Camel 1 is not the frontmost camel, so its happiness will be 10.\n * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n * Camel 2 is the frontmost camel, so its happiness will be 71.\n * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]
|
Print T lines. The i-th line should contain the answer to the i-th test case.
* * *
|
s831927259
|
Runtime Error
|
p02610
|
Input is given from Standard Input in the following format:
T
\mathrm{case}_1
\vdots
\mathrm{case}_T
Each case is given in the following format:
N
K_1 L_1 R_1
\vdots
K_N L_N R_N
|
from collections import namedtuple
import sys
input = sys.stdin.readline
Camel = namedtuple("Camel", "k v".split(" "))
def read_int():
return int(input())
def read_int_array():
return [int(ss) for ss in input().split()]
class SegmentNode:
def __init__(self, minidx, maxidx, capacity, occupied, left, right):
self.minidx = minidx
self.maxidx = maxidx
self.capacity = capacity
self.occupied = occupied
self.left = left
self.right = right
def __repr__(self):
return f"[{self.minidx}-{self.maxidx}, {self.occupied}/{self.capacity}]"
def print_tree(self, lvl=0):
print((" " * lvl) + self.__repr__())
if self.left:
self.left.print_tree(lvl + 2)
if self.right:
self.right.print_tree(lvl + 2)
def occupy(self, rightmost_idx):
if self.minidx > rightmost_idx:
return False
if self.capacity == self.occupied:
return False
is_leaf = not (self.left or self.right)
if is_leaf:
self.occupied += 1
return True
if self.right:
result = self.right.occupy(rightmost_idx)
if result:
self.occupied += 1
return True
result = self.left.occupy(rightmost_idx)
if result:
self.occupied += 1
return True
return False
def buildtree(size):
row = [SegmentNode(i, i, 1, 0, None, None) for i in range(size)]
while len(row) > 1:
newrow = []
for i in range(0, len(row), 2):
left = row[i]
right = row[i + 1] if i + 1 < len(row) else None
minidx = left.minidx
maxidx = left.maxidx
capacity = left.capacity
if right:
maxidx = right.maxidx
capacity += right.capacity
newrow.append(SegmentNode(minidx, maxidx, capacity, 0, left, right))
row = newrow
return row[0]
# st = buildtree(5)
# print(st.occupy(2))
# # print(st.occupy(1))
# st.print_tree()
def solution():
n = read_int()
lefties = []
righties = []
total = 0
for _ in range(n):
k, l, r = read_int_array()
total += min(l, r)
if l > r:
lefties.append(Camel(k - 1, l - r))
if r > l:
righties.append(Camel(k - 1, r - l))
lefties = sorted(lefties, key=lambda c: -c.v)
righties = sorted(righties, key=lambda c: -c.v)
ltree = buildtree(len(lefties))
rtree = buildtree(len(righties))
for l in lefties:
if ltree.occupy(l.k):
total += l.v
for r in righties:
if rtree.occupy(n - r.k - 2):
total += r.v
return total
def main():
t = read_int()
for i in range(t):
s = solution()
print(s)
main()
# ss = buildtree(100_000)
#
# for i in range(50000):
# ss.occupy(50000)
#
|
Statement
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find the maximum
possible total happiness of the camel.
Solve this problem for each of the T test cases given.
|
[{"input": "3\n 2\n 1 5 10\n 2 15 5\n 3\n 2 93 78\n 1 71 59\n 3 57 96\n 19\n 19 23 16\n 5 90 13\n 12 85 70\n 19 67 78\n 12 16 60\n 18 48 28\n 5 4 24\n 12 97 97\n 4 57 87\n 19 91 74\n 18 100 76\n 7 86 46\n 9 100 57\n 3 76 73\n 6 84 93\n 1 6 84\n 11 75 94\n 19 15 3\n 12 11 34", "output": "25\n 221\n 1354\n \n\n * In the first test case, it is optimal to line up the camels in the order 2, 1.\n * Camel 1 is not the frontmost camel, so its happiness will be 10.\n * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n * Camel 2 is the frontmost camel, so its happiness will be 71.\n * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]
|
For each query, print "yes" if $t$ is reachable from $s$ through the social
network, "no" otherwise.
|
s248605770
|
Runtime Error
|
p02240
|
In the first line, two integer $n$ and $m$ are given. $n$ is the number of
users in the SNS and $m$ is the number of relations in the SNS. The users in
the SNS are identified by IDs $0, 1, ..., n-1$.
In the following $m$ lines, the relations are given. Each relation is given by
two integers $s$ and $t$ that represents $s$ and $t$ are friends (and
reachable each other).
In the next line, the number of queries $q$ is given. In the following $q$
lines, $q$ queries are given respectively. Each query consists of two integers
$s$ and $t$ separated by a space character.
|
from sys import stdin
def read_graph(n, k):
A = [[] for _ in range(n)]
for _ in range(k):
line = stdin.readline().strip().split()
A[int(line[0])].append(int(line[1]))
A[int(line[1])].append(int(line[0]))
return A
def dfs_ctrl(n, A, s, t):
color = ["WHITE"] * n
d = [0] * n
f = [0] * n
time = 0
def dfs(u):
nonlocal color
nonlocal time
color[u] = "GRAY"
time += 1
d[u] = time
for v in A[u]:
if color[v] == "WHITE":
dfs(v)
color[u] = "BLACK"
time += 1
f[u] = time
dfs(s)
if d[t] != 0:
print("yes")
else:
print("no")
def read_and_print_connection(m):
for _ in range(m):
line = stdin.readline().strip().split()
s = int(line[0])
t = int(line[1])
dfs_ctrl(n, A, s, t)
n, k = [int(i) for i in input().split()]
A = read_graph(n, k)
m = int(input())
read_and_print_connection(m)
|
Connected Components
Write a program which reads relations in a SNS (Social Network Service), and
judges that given pairs of users are reachable each other through the network.
|
[{"input": "9\n 0 1\n 0 2\n 3 4\n 5 7\n 5 6\n 6 7\n 6 8\n 7 8\n 8 9\n 3\n 0 1\n 5 9\n 1 3", "output": "yes\n yes\n no"}]
|
For each query, print "yes" if $t$ is reachable from $s$ through the social
network, "no" otherwise.
|
s182857381
|
Accepted
|
p02240
|
In the first line, two integer $n$ and $m$ are given. $n$ is the number of
users in the SNS and $m$ is the number of relations in the SNS. The users in
the SNS are identified by IDs $0, 1, ..., n-1$.
In the following $m$ lines, the relations are given. Each relation is given by
two integers $s$ and $t$ that represents $s$ and $t$ are friends (and
reachable each other).
In the next line, the number of queries $q$ is given. In the following $q$
lines, $q$ queries are given respectively. Each query consists of two integers
$s$ and $t$ separated by a space character.
|
import sys
from collections import defaultdict
def main():
lines = sys.stdin.readlines()
n, m = map(int, lines[0].split())
relation_lines = lines[1 : 1 + m]
relations = defaultdict(list)
for idx, relation_line in enumerate(relation_lines):
s, t = relation_line.split()
relations[s].append(t)
relations[t].append(s)
group = {}
for key in relations.keys():
group[key] = -1
group_num = 0
# assign a group number for ids
for key, val in relations.items():
if group[key] != -1:
continue
group[key] = group_num
group_num += 1
group_no = group[key]
friends = [key]
while len(friends) != 0:
n_fs = relations[friends.pop()]
for n_f in n_fs:
if group[n_f] == -1:
group[n_f] = group_no
friends.append(n_f)
q = int(lines[1 + m])
question_lines = lines[1 + m + 1 :]
answers = [None] * q
for i, question in enumerate(question_lines):
s, t = question.split()
if s not in group or t not in group:
answers[i] = "no"
continue
elif group[s] == group[t]:
answers[i] = "yes"
else:
answers[i] = "no"
# answer
[print(ans) for ans in answers]
return
main()
|
Connected Components
Write a program which reads relations in a SNS (Social Network Service), and
judges that given pairs of users are reachable each other through the network.
|
[{"input": "9\n 0 1\n 0 2\n 3 4\n 5 7\n 5 6\n 6 7\n 6 8\n 7 8\n 8 9\n 3\n 0 1\n 5 9\n 1 3", "output": "yes\n yes\n no"}]
|
For each query, print "yes" if $t$ is reachable from $s$ through the social
network, "no" otherwise.
|
s982172896
|
Wrong Answer
|
p02240
|
In the first line, two integer $n$ and $m$ are given. $n$ is the number of
users in the SNS and $m$ is the number of relations in the SNS. The users in
the SNS are identified by IDs $0, 1, ..., n-1$.
In the following $m$ lines, the relations are given. Each relation is given by
two integers $s$ and $t$ that represents $s$ and $t$ are friends (and
reachable each other).
In the next line, the number of queries $q$ is given. In the following $q$
lines, $q$ queries are given respectively. Each query consists of two integers
$s$ and $t$ separated by a space character.
|
Connected Components
Write a program which reads relations in a SNS (Social Network Service), and
judges that given pairs of users are reachable each other through the network.
|
[{"input": "9\n 0 1\n 0 2\n 3 4\n 5 7\n 5 6\n 6 7\n 6 8\n 7 8\n 8 9\n 3\n 0 1\n 5 9\n 1 3", "output": "yes\n yes\n no"}]
|
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s416699382
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
h, w, x, y = map(int, input().split())
print(h * w / 2, int((2 * x == w) and (y * 2 == h)))
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s495715375
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
import collections
w, h, x, y = map(int, input().split())
area = []
# xの直線
area.append(min(h * x, h * (w - x)))
# yの直線
area.append(min(w * y, w * (h - y)))
# 角たち
a = w * h
if y != 0:
if h / y * x <= w:
tmp = h / y * x * h
area.append(min(tmp, a - tmp))
if h - y != 0:
if h / (h - y) * x <= w:
tmp = h / (h - y) * x * h
area.append(min(tmp, a - tmp))
if x != 0:
if w / x * y <= h:
tmp = w / x * y * w
area.append(min(tmp, a - tmp))
if w - x != 0:
if w / (w - x) * y <= h:
tmp = w / (w - x) * y * w
area.append(min(tmp, a - tmp))
ans_c = collections.Counter(area)
ans = sorted(ans_c.items(), reverse=True)[0]
size = ans[0]
a = 0
if ans[1] > 1:
a = 1
print("{} {}".format(size, a))
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s517736071
|
Accepted
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
W, H, x, y = list(map(int, input().split()))
judge = 0
# 綺麗に二等分するのが面積は最善である。
area = float(W * H / 2)
# (x,y)を通るときもう一点は自動的に(y,x)になる。だがx == yの時は別に考える。
"""
・図形を二等分する直線が二つ以上ある
・その二つの直線の中点が重なりそれが点(x,y)となる
この二つの条件を満たせば複数の分割法があると言える。
これを考えるとW,Hが偶数値で、x,yはそれぞれx = W/2, y = H/2でなくてはならない
"""
if W % 2 == 0 and H % 2 == 0:
if x == int(W / 2) and y == int(H / 2):
judge += 1
# 結果
print(area, judge)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s138620191
|
Accepted
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, x, y = map(int, input().split())
cx = w / 2
cy = h / 2
if (cx == x) and (cy == y):
print(w * h / 2, end=" ")
print(1)
exit()
elif cx == x:
print(w * h / 2, end=" ")
print(0)
exit()
elif cy == y:
print(w * h / 2, end=" ")
print(0)
exit()
else:
t = 0
b = y - x * ((y - cy) / (x - cx))
if (b >= 0) and (b <= h):
bb = ((y - cy) / (x - cx)) * w + b
s = (b + bb) * w / 2
elif b < 0:
a = (0 - b) * (x - cx) / (y - cy)
aa = (h - b) * (x - cx) / (y - cy)
s = ((-b + h) * aa / 2) - ((-b) * a / 2)
elif b > h:
a = (0 - b) * (x - cx) / (y - cy)
aa = (h - b) * (x - cx) / (y - cy)
s = (b * a / 2) - ((b - h) * aa / 2)
print(s, end=" ")
print(t)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s675958154
|
Runtime Error
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, x, y = map(int, input().split())
area = w * h
if x != 0:
if (y / x) * w >= h:
ax = (h / y) * x
if ((y - h) / x) * w + h >= 0:
ayy = ((y - h) / x) * w + h
axx = ((x - w) * w) / y + w
if y != h:
ay = ((y - h) / (w - x)) * w + h
lst = [
min(area - ((w - axx) * h) / 2, ((w - axx) * h) / 2),
min(area - ((h - ayy) * w) / 2, ((h - ayy) * w) / 2),
min(area - h * x, h * x),
min(area - w * y, w * y),
min(area - (ax * h) / 2, (ax * h) / 2),
min(area - (ay * w) / 2, (ay * w) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
else:
lst = [
min(area - ((w - axx) * h) / 2, ((w - axx) * h) / 2),
min(area - h * x, h * x),
min(area - (ax * h) / 2, (ax * h) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
else:
axx = (h * x) / (h - y)
ayy = (w * y) / (w - y)
ay = ((y - h) / (w - x)) * w + h
lst = [
min(area - (w * ayy) / 2, (w * ayy) / 2),
min(area - (axx * h) / 2, (axx * h) / 2),
min(area - h * x, h * x),
min(area - w * y, w * y),
min(area - (ax * h) / 2, (ax * h) / 2),
min(area - (ay * w) / 2, (ay * w) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
else:
ay = (w * y) / x
if ((y - h) / x) * w + h >= 0:
axx = ((x - w) * w) / y + w
ayy = ((y - h) / x) * w + h
if x != w:
ax = ((w - x) / (y - h)) * h + w
lst = [
min(area - ((w - axx) * h) / 2, ((w - axx) * h) / 2),
min(area - ((h - ayy) * w) / 2, ((h - ayy) * w) / 2),
min(area - h * x, h * x),
min(area - w * y, w * y),
min(area - (ay * w) / 2, (ay * w) / 2),
min(area - ((w - ax) * h) / 2, ((w - ax) * h) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
else:
lst = [
min(area - ((h - ayy) * w) / 2, ((h - ayy) * w) / 2),
min(area - w * y, w * y),
min(area - (ay * w) / 2, (ay * w) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
else:
axx = (h * x) / (h - y)
ayy = (w * y) / (w - y)
ax = ((w - x) / (y - h)) * h + w
lst = [
min(area - (w * ayy) / 2, (w * ayy) / 2),
min(area - (axx * h) / 2),
min(area - (axx * h) / 2, (axx * h) / 2),
min(area - h * x, h * x),
min(area - w * y, w * y),
min(area - (ay * w) / 2, (ay * w) / 2),
min(area - ((w - ax) * h) / 2, ((w - ax) * h) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
else:
lst = [
min(area - w * y, w * y),
min(((h - y) * w) / 2, area - ((h - y) * w) / 2),
min(area - (y * w) / 2, (y * w) / 2),
]
ans = max(lst)
if lst.count(ans) == 1:
f = 0
else:
f = 1
print(ans, f)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s839333768
|
Accepted
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, *xy = map(int, input().split())
print(w * h / 2, ([w / 2, h / 2] == xy) + 0)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s878585103
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
n, m, x, y = map(int, input().split())
print(n * m / 2, int(x == n / 2 and y == n / 2))
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s627526692
|
Runtime Error
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
N, K = map(int, input().split())
a = [int(x) for x in input().split()]
start = 0
end = 0
a_sum = a[0]
ans = 0
# 右に進めるだけ進む -> a_sum >= Kを満たすまで
# 左を詰めていく -> a_sum >= K の間だけ
# 右端までいったらbreak
while True:
if a_sum < K:
end += 1
if end == N:
break
# 新たに追加した最後の数字を追加
a_sum += a[end]
else:
# もしK以上の場合、end以降の全ての要素が追加されても満たすため、その数を足す
# その数はこの場合、N - end ex:10個あってa[2]~a[5]個で満たしているとき、 2~a[6], a[7], a[8], a[9]とあって計 N - 5個
ans += N - end
# 左を詰める
a_sum -= a[start]
start += 1
print(ans)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s381416812
|
Runtime Error
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
n, k = map(int, input().split())
c = list(map(int, input().split()))
s = [0]
ans = 0
for i in range(n):
s.append(s[-1] + c[i])
r = 0
for l in range(n):
while r < n and s[r] - s[l] < k:
r += 1
ans += n - r + int(s[r] - s[l] >= k)
print(ans)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s159241617
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
W, H, x, y = map(float, input().split())
hor = min([W * y, W * H - W * y])
ver = min([H * x, W * H - H * x])
if y == (H / W * x) or y == H - (H / W * x):
slash = W * H / 2
else:
slash = 0
tmp = [hor, ver, slash, W * H / 2]
if len(list(set(tmp))) != 4:
tf = 1
else:
tf = 0
print(" ".join([str(W * H / 2), str(tf)]))
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s540332929
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, x, y = map(float, input().split())
if x == 0 and y == 0:
print(0, "0")
elif x == 0:
print(min(w * y, w * (h - y)), "0")
elif y == 0:
print(min(h * x, h * (w - x)), "0")
elif w - x == w / 2 and h - y == h / 2:
print(max(min(w * y, w * (h - y)), min(h * x, h * (w - x))), "1")
else:
print(max(min(w * y, w * (h - y)), min(h * x, h * (w - x))), "0")
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s097255977
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, x, y = map(int, input().split())
if x < w / 2 and y < h / 2:
print(str(max(float(x * h), float(y * w))), "1")
elif x < w / 2 and y > h / 2:
print(str(max(float(x * h), float((h - y) * w))), "1")
elif x > w / 2 and y < h / 2:
print(str(max(float((w - x) * h), float(y * w))), "1")
elif x > w / 2 and y > h / 2:
print(str(max(float((w - x) * h), float((h - y) * w))), "1")
elif x == w / 2 or y == h / 2:
print(str(w * h / 2), "0")
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s522972257
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
print("A")
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s314959685
|
Accepted
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
a, b, c, d = map(int, input().split())
res1 = a * b / 2
res2 = 0
if c * 2 == a and d * 2 == b:
res2 = 1
print(res1, res2)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s146684848
|
Accepted
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
a, b, x, y = map(int, input().rstrip().split(" "))
r = 0
if x + x == a and y + y == b:
r = 1
print(a * b / 2, r)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s387779203
|
Runtime Error
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
W, H, x, y = map(int, input().spilt())
print(W * H / 2, 1 if (x == W / 2 and y == H / 2) else W * H / 2, 0)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s539930449
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
t = list(map(int, input().split()))
S = t[0] * t[1] / 2
print(S, "0")
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s085316092
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, x, y = map(int, input().split())
S = w * h
vertical = min(x, w - x)
horizontal = min(y, h - y)
maxS = max(vertical / w, horizontal / h) * S
if vertical / w == horizontal / h:
x = 1
else:
x = 0
print(str(maxS) + " " + str(x))
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s172219486
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
W, H, x, y = map(int, input().split())
hy = W * (H - y)
by = W * y
rx = (W - x) * H
lx = x * H
arry = {hy, by}
arrx = {rx, lx}
miny = min(arry)
minx = min(arrx)
ans = max({miny, minx})
print(str(ans) + " " + ("1" if len(arry) == 1 and len(arrx) == 1 else "0"))
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s427645759
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
w, h, x, y = map(int, input().split())
a = w * h
b = x * h
c = y * w
g = 0
d = (h - y) * w // 2
e = a - d
o = b / 2
p = c / 2
f = max(min((a - c), c), min(p, a - p))
i = max(min((a - b), b), min(o, a - o))
if b == c or d == f or d == e or i == f or i == e:
g = 1
if x != w and y != h:
print(
"{:.9f}".format(
max(min(a - max(b, c), max(b, c)), min(a - min(b, c), min(b, c)))
),
g,
)
elif x == w or x == 0:
print("{:.9f}".format(f), g)
elif y == h or y == 0:
print("{:.9f}".format(i), g)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum possible area of the part whose area is not larger than that
of the other, followed by `1` if there are multiple ways to cut the rectangle
and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is
at most 10^{-9}.
* * *
|
s731576501
|
Wrong Answer
|
p03001
|
Input is given from Standard Input in the following format:
W H x y
|
n = list(map(int, input().split()))
answer2 = 0
if n[2] == 0 or n[2] == n[0]: # x座標が0 複数
# print("1")
answer = min(n[1] * n[2], n[1] * (n[0] - n[2]))
answer2 = answer2 + 1
elif n[3] == 0 or n[3] == n[1]: # 複数
# print("2")
answer = min(n[0] * n[3], n[0] * (n[1] - n[3]))
answer2 = answer2 + 1
elif n[0] < n[1]: # 縦長の長方形
# print("3")
answer = min(n[1] * n[2], n[1] * (n[0] - n[2]))
elif n[1] < n[0]:
# print("4")
answer = min(n[0] * n[3], n[0] * (n[1] - n[3]))
elif n[0] == n[1]: # 複数
answer = min(n[0] * n[3], n[0] * (n[1] - n[3]))
answer2 = answer2 + 1
print(answer, end=" ")
print(answer2)
|
Statement
There is a rectangle in a coordinate plane. The coordinates of the four
vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which
is within the rectangle or on its border. We will draw a straight line passing
through (x,y) to cut the rectangle into two parts. Find the maximum possible
area of the part whose area is not larger than that of the other.
Additionally, determine if there are multiple ways to cut the rectangle and
achieve that maximum.
|
[{"input": "2 3 1 2", "output": "3.000000 0\n \n\nThe line x=1 gives the optimal cut, and no other line does.\n\n* * *"}, {"input": "2 2 1 1", "output": "2.000000 1"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s721822010
|
Accepted
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
def resolve():
import sys
input = sys.stdin.readline
# 整数 1 つ
n = int(input())
# 整数複数個
# a, b = map(int, input().split())
# 整数 N 個 (改行区切り)
# N = [int(input()) for i in range(N)]
# 整数 N 個 (スペース区切り)
# N = list(map(int, input().split()))
# 整数 (縦 H 横 W の行列)
A = [list(map(int, input().split())) for i in range(2)]
Candy = [[0 for _ in range(n)] for _ in range(2)]
Candy[0][0] = A[0][0]
Candy[1][0] = A[0][0] + A[1][0]
for i in range(1, n):
Candy[0][i] = Candy[0][i - 1] + A[0][i]
for j in range(1, n):
Candy[1][j] = max(Candy[1][j - 1], Candy[0][j]) + A[1][j]
print(Candy[1][n - 1])
# print(Candy)
resolve()
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s393008372
|
Runtime Error
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
import sys
input = sys.stdin.readline
import heapq as hq
n, m = map(int, input().split())
s, t = map(int, input().split())
abd = [list(map(int, input().split())) for i in range(m)]
mod = 10**9 + 7
graph = [[] for i in range(n + 1)]
for a, b, d in abd:
graph[a].append((b, d))
graph[b].append((a, d))
dists = [[10**18, 0] for i in range(n + 1)]
distt = [[10**18, 0] for i in range(n + 1)]
for start, dist in (s, dists), (t, distt):
dist[start] = [0, 1]
q = [(0, start)]
hq.heapify(q)
while q:
dx, x = hq.heappop(q)
k = dist[x][1]
for y, d in graph[x]:
if dist[y][0] > dx + d:
dist[y][0] = dx + d
dist[y][1] = k
hq.heappush(q, (dist[y][0], y))
elif dist[y][0] == dx + d:
dist[y][1] = (dist[y][1] + k) % mod
dst = dists[t][0]
ansls = []
for u, v, d in abd:
for a, b in (u, v), (v, u):
if dists[a][0] < distt[a][0]:
if dists[a][0] * 2 < dst and distt[b][0] * 2 < dst:
if dists[a][0] + distt[b][0] + d == dst:
ansls.append(dists[a][1] * distt[b][1] % mod)
for v in range(1, n + 1):
if dists[v][0] * 2 == distt[v][0] * 2 == dst:
ansls.append(dists[v][1] * distt[v][1] % mod)
sm = sum(ansls) % mod
ans = sm**2 % mod
for i in ansls:
ans = (ans - i**2) % mod
print(ans)
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s677659384
|
Accepted
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
N = int(input())
A1 = [int(i) for i in input().split()]
A2 = [int(i) for i in input().split()]
cumA1 = [0]
cumA2 = [0]
asum = 0
bsum = 0
for a, b in zip(A1, A2):
asum += a
bsum += b
cumA1.append(asum)
cumA2.append(bsum)
print(cumA2[N] + max([cumA1[i] - cumA2[i - 1] for i in range(1, N + 1)]))
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s837592665
|
Runtime Error
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
N = int(input())
L1 = map(int, input().split())
L2 = map(int, input().split())
P1 = L1[:]
P2 = L2[:]
for i in range(1, N):
P1[i] += P1[i - 1]
for j in range(N - 1, -1, -1):
P2[j] += P2[j + 1]
L3 = [0] * N
for k in range(N):
L3[k] = P1[k] + P2[k]
print(max(L3))
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s938374776
|
Accepted
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
n = int(input())
r, s = 2, n
a = []
for i in range(r):
a.append(list(map(int, input().split())))
jagoda = [[-1 for j in range(s)] for i in range(r)]
# Pocetno polje
jagoda[0][0] = a[0][0]
# Prvi redak
for j in range(1, s):
jagoda[0][j] = jagoda[0][j - 1] + a[0][j]
# Prvi stupac
for i in range(1, r):
jagoda[i][0] = jagoda[i - 1][0] + a[i][0]
# Ostala polja
for i in range(1, r):
for j in range(1, s):
jagoda[i][j] = max(jagoda[i - 1][j], jagoda[i][j - 1]) + a[i][j]
print(jagoda[-1][-1])
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s342281359
|
Runtime Error
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
import sys
n, m = map(int, input().split())
adj_list = [[] for i in range(n)]
for i in range(m):
l, r, d = map(int, input().split())
adj_list[l - 1].append((r - 1, d))
adj_list[r - 1].append((l - 1, -d))
def search(start, goal):
q = [[start]]
q_d = [0]
d_set = set()
while len(q) > 0:
path = q.pop(0)
dist = q_d.pop(0)
w = path[len(path) - 1]
if w == goal:
d_set.add(dist)
if len(d_set) > 1:
return False
else:
for x in adj_list[w]:
if x[0] not in path:
new_path = path[:]
new_path.append(x[0])
q.append(new_path)
q_d.append(dist + x[1])
return True
for i in range(n):
for j in range(i + 1):
if not search(i, j):
print("No")
exit(0)
print("Yes")
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s027991376
|
Runtime Error
|
p03451
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
Candies=[]
for i in range(n):
Candies.appned(sum(a[:i+1])+sum(b[i+1:])
print(max(Candies))
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the answer.
* * *
|
s552625819
|
Wrong Answer
|
p02539
|
Input is given from Standard Input in the following format:
N
h_1
:
h_{2N}
|
from operator import mul
from functools import reduce
import math
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, range(n, n - r, -1), 1)
denom = reduce(mul, range(1, r + 1), 1)
return numer // denom
n = int(input())
dic = {}
for i in range(2 * n):
tmp = int(input())
dic.setdefault(tmp, 0)
dic[tmp] += 1
print(dic)
dic_max = max(dic.values())
dic_min = min(dic.values())
print(dic_max, dic_min)
print(combinations_count(dic_max, dic_min))
ans = 1
for vl in dic.values():
print(dic_max, vl)
ans *= combinations_count(dic_max, vl) * math.factorial(vl)
ans = ans // math.factorial(dic_max)
print(ans)
|
Statement
There are 2N people numbered 1 through 2N. The height of Person i is h_i.
How many ways are there to make N pairs of people such that the following
conditions are satisfied? Compute the answer modulo 998,244,353.
* Each person is contained in exactly one pair.
* For each pair, the heights of the two people in the pair are different.
Two ways are considered different if for some p and q, Person p and Person q
are paired in one way and not in the other.
|
[{"input": "2\n 1\n 1\n 2\n 3", "output": "2\n \n\nThere are two ways:\n\n * Form the pair (Person 1, Person 3) and the pair (Person 2, Person 4).\n * Form the pair (Person 1, Person 4) and the pair (Person 2, Person 3).\n\n* * *"}, {"input": "5\n 30\n 10\n 20\n 40\n 20\n 10\n 10\n 30\n 50\n 60", "output": "516"}]
|
Print the answer.
* * *
|
s219276383
|
Wrong Answer
|
p02539
|
Input is given from Standard Input in the following format:
N
h_1
:
h_{2N}
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import defaultdict
from collections import deque
MOD = 998244353
def DD(arg):
return defaultdict(arg)
def inv(n):
return pow(n, MOD - 2, MOD)
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
import numpy as np
def fft_convolve(f, g):
"""
数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで,
30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える.
"""
Lf, Lg = f.shape[-1], g.shape[-1]
Lg = g.shape[-1]
L = Lf + Lg - 1
fft_len = 1 << L.bit_length()
fh, fl = f >> 15, f & (1 << 15) - 1
gh, gl = g >> 15, g & (1 << 15) - 1
def conv(f, g):
Ff = np.fft.rfft(f, fft_len)
Fg = np.fft.rfft(g, fft_len)
h = np.fft.irfft(Ff * Fg)
return np.rint(h)[..., :L].astype(np.int64) % MOD
x = conv(fl, gl)
z = conv(fh, gh)
y = conv(fl + fh, gl + gh) - x - z
return (x + (y << 15) + (z << 30)) % MOD
N = int(input())
nokori = [1]
for n in range(1, 2 * N + 10):
nokori.append((nokori[-1] * (2 * n - 1) * (2 * n) * inv(2) * inv(n)) % MOD)
dic = DD(int)
for _ in range(N * 2):
dic[int(input())] += 1
A = [dic[k] for k in dic]
P = []
for a in A:
temp = 1
count = 0
P.append([temp])
while a >= 2:
temp *= a * (a - 1) // 2
temp %= MOD
count += 1
P[-1].append((temp * gyaku_kaijo(count)) % MOD)
a -= 2
Q = deque([np.array(p) for p in P])
exit()
while len(Q) > 1:
p = Q.popleft()
q = Q.popleft()
Q.append(fft_convolve(p, q))
Q = list(Q[0])
ans = 0
M = len(Q)
def sign(x):
if x % 2:
return -1
else:
return 1
for i in range(M):
ans += sign(i) * Q[i] * nokori[N - i]
ans %= MOD
print(ans)
|
Statement
There are 2N people numbered 1 through 2N. The height of Person i is h_i.
How many ways are there to make N pairs of people such that the following
conditions are satisfied? Compute the answer modulo 998,244,353.
* Each person is contained in exactly one pair.
* For each pair, the heights of the two people in the pair are different.
Two ways are considered different if for some p and q, Person p and Person q
are paired in one way and not in the other.
|
[{"input": "2\n 1\n 1\n 2\n 3", "output": "2\n \n\nThere are two ways:\n\n * Form the pair (Person 1, Person 3) and the pair (Person 2, Person 4).\n * Form the pair (Person 1, Person 4) and the pair (Person 2, Person 3).\n\n* * *"}, {"input": "5\n 30\n 10\n 20\n 40\n 20\n 10\n 10\n 30\n 50\n 60", "output": "516"}]
|
Print the answer.
* * *
|
s833086925
|
Runtime Error
|
p02539
|
Input is given from Standard Input in the following format:
N
h_1
:
h_{2N}
|
mod = 998244353
n, q = map(int, input().split())
lrd = [list(map(int, input().split())) for _ in range(q)]
s = 0
ss = []
tmp = 1
for i in range(n):
ss.append(tmp)
s += tmp
s %= mod
tmp *= 10
tmp %= mod
ss.reverse()
# print(ss,s)
for l, r, d in lrd:
for i in range(l - 1, r):
s -= ss[i]
ss[i] = d * pow(10, n - i - 1, mod)
s += ss[i]
s %= mod
print(s)
|
Statement
There are 2N people numbered 1 through 2N. The height of Person i is h_i.
How many ways are there to make N pairs of people such that the following
conditions are satisfied? Compute the answer modulo 998,244,353.
* Each person is contained in exactly one pair.
* For each pair, the heights of the two people in the pair are different.
Two ways are considered different if for some p and q, Person p and Person q
are paired in one way and not in the other.
|
[{"input": "2\n 1\n 1\n 2\n 3", "output": "2\n \n\nThere are two ways:\n\n * Form the pair (Person 1, Person 3) and the pair (Person 2, Person 4).\n * Form the pair (Person 1, Person 4) and the pair (Person 2, Person 3).\n\n* * *"}, {"input": "5\n 30\n 10\n 20\n 40\n 20\n 10\n 10\n 30\n 50\n 60", "output": "516"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s857753834
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i]) * n**i for i in range(len(str(X))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
S = S()
K = I()
n = len(S)
ind = 0
for i in range(n):
if S[i] != "1":
ind = i
num = S[i]
break
if K > ind:
P(num)
else:
P(1)
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s583360264
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)
int _ = (
#ifndef LOCAL
std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
std::cout.precision(10), std::cout.setf(std::ios::fixed));
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;
int main() {
string S;
ll K;
cin >> S >> K;
smatch m;
regex_match(S, m, regex("^(1*)([1-9]*)$"));
cout << ((m.length(1) >= K) ? '1' : m.str(2).front()) << endl;
return 0;
}
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s422336397
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
s=input()
k=int(input())
if s[0]=="1":
print(int(s[1])
else:
print(int(s[0]))
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s455962581
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
S=int(input())
K=int(input())
for i in range(10**5):
if S[i]!=1
print(S[i])
break
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s503851136
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
s = list(input())
k = int(input())
p = -1
for i in range(len(s)):
if s[i]!='1':
p=i+1
if p=-1:
print(1)
else:
if k<p:
print(1)
else:
print(s[p])
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s422313186
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
N = input()
K = int(input())
ans = '1'
for i in range(K):
if i >= len(N):
break
if N[i] != '1':
ans = N[i]
break
print(ans)
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s780550555
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
#include <bits/stdc++.h>
// #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}
int main() {
string s;cin >> s;
int k;cin >> k;
rep(i,k+3){
if (s[i]!='1'){
cout<<s[i]<<endl;
return 0;
}
}
cout<<1<<endl;
}
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s489256366
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
a=input().split("¥n")
goal=int(a[1])
keta=len(a[0])
for i in range(keta):
if(int(a[0][i])==1):
goal-=1
if(goal<=0):
print("1")
break
else:
print(a[0][i])
break
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s718582741
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
main():
S = input()
K = int(input())
output = solve(S, K)
return output
def solve(S, K):
for s in S:
if s != "1":
return s
return "1"
if __name__ == "__main__":
main()
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s100389950
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
S=input()
K=int(input())
if K<=len(S):
for s in S[:K]:
if s!="1":
break
else:
print("1")
else:
for s in S:
if s!="1" :
print(s)
break
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s295538884
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
s = input()
k = int(input())
onesum = 0
while s[0] == "1" and len(s) > 0
s = s[1:]
onesum += 1
if k <= onesum:
print(1)
else:
print(s[0])
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s754346110
|
Accepted
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
ss = input()
k = int(input())
s = [int(i) for i in ss]
# ls=len(s)
j = 0
q = 0
w = 0
while q == 0:
if s[j] == 1:
w += 1
if k <= w:
print(1)
q = 1
j += 1
else:
print(s[j])
q = 1
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s847410842
|
Accepted
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
print(input()[: int(input())].replace("1", "")[:1] or 1)
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s141846367
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
print(max(1, [int(i) for i in input()[: int(input())] if i != "1"][0]))
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s934604544
|
Wrong Answer
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
s, _ = [input() for _ in range(2)]
s = s.rstrip("1")
print(s[0] if s else "1")
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s951392811
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
S = input()
K = int(input())
l = 0
for i in S:
if i == '1':
l+=1
if l >= K:
print(1)
break
else:
print(i)
break
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s872653450
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
n=list(input())
m=int(input())
i=0
for t in range(100):
if n[t]=="1":
pass
else:
i=t+1
if m=>i:
print(str(n[i]))
else:
print(1)
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s220337385
|
Accepted
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
s = int(input())
k = int(input())
# print(pow(10, 12))
def main(string_s):
for i, j in enumerate(str(string_s)):
# print(i, j)
# print(i, k)
if j != "1":
break
if i + 1 == k:
print("1")
return
if str(s).lstrip("1") == "":
print("1")
return
if str(s).lstrip("1")[0] == "2":
print("2")
elif str(s).lstrip("1")[0] == "3":
print("3")
elif str(s).lstrip("1")[0] == "4":
print("4")
elif str(s).lstrip("1")[0] == "5":
print("5")
elif str(s).lstrip("1")[0] == "6":
print("6")
elif str(s).lstrip("1")[0] == "7":
print("7")
elif str(s).lstrip("1")[0] == "8":
print("8")
elif str(s).lstrip("1")[0] == "9":
print("9")
else:
print("1")
main(s)
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the K-th character from the left in Mr. Infinity's string after 5 \times
10^{15} days.
* * *
|
s101966910
|
Runtime Error
|
p03282
|
Input is given from Standard Input in the following format:
S
K
|
s = list(input())
k = int(input())
c = 0
for i in range(len(s)):
if int(s[i]) != 1:
if i < k:
print(s[i])
break
else:
print(1)
break
|
Statement
Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time
the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.
For example, if S is `1324`, it becomes `1333224444` the next day, and it
becomes `133333333322224444444444444444` the day after next. You are
interested in what the string looks like after 5 \times 10^{15} days. What is
the K-th character from the left in the string after 5 \times 10^{15} days?
|
[{"input": "1214\n 4", "output": "2\n \n\nThe string S changes as follows:\n\n * Now: `1214`\n * After one day: `12214444`\n * After two days: `1222214444444444444444`\n * After three days: `12222222214444444444444444444444444444444444444444444444444444444444444444`\n\nThe first five characters in the string after 5 \\times 10^{15} days is\n`12222`. As K=4, we should print the fourth character, `2`.\n\n* * *"}, {"input": "3\n 157", "output": "3\n \n\nThe initial string is `3`. The string after 5 \\times 10^{15} days consists\nonly of `3`.\n\n* * *"}, {"input": "299792458\n 9460730472580800", "output": "2"}]
|
Print the minimum distance the second rectangle needs to be moved.
* * *
|
s975755630
|
Runtime Error
|
p03778
|
The input is given from Standard Input in the following format:
W a b
|
W,a,b = map(int,input().split())
if((abs(b-a) < W):
print(0)
else:
ans = abs(b - a) - W
print(ans)
|
Statement
AtCoDeer the deer found two rectangles lying on the table, each with height 1
and width W. If we consider the surface of the desk as a two-dimensional
plane, the first rectangle covers the vertical range of [0,1] and the
horizontal range of [a,a+W], and the second rectangle covers the vertical
range of [1,2] and the horizontal range of [b,b+W], as shown in the following
figure:

AtCoDeer will move the second rectangle horizontally so that it connects with
the first rectangle. Find the minimum distance it needs to be moved.
|
[{"input": "3 2 6", "output": "1\n \n\nThis input corresponds to the figure in the statement. In this case, the\nsecond rectangle should be moved to the left by a distance of 1.\n\n* * *"}, {"input": "3 1 3", "output": "0\n \n\nThe rectangles are already connected, and thus no move is needed.\n\n* * *"}, {"input": "5 10 1", "output": "4"}]
|
Print the minimum distance the second rectangle needs to be moved.
* * *
|
s745728518
|
Accepted
|
p03778
|
The input is given from Standard Input in the following format:
W a b
|
f = lambda x: max(abs(x[2] - x[1]) - x[0], 0)
print(f(list(map(int, input().split()))))
|
Statement
AtCoDeer the deer found two rectangles lying on the table, each with height 1
and width W. If we consider the surface of the desk as a two-dimensional
plane, the first rectangle covers the vertical range of [0,1] and the
horizontal range of [a,a+W], and the second rectangle covers the vertical
range of [1,2] and the horizontal range of [b,b+W], as shown in the following
figure:

AtCoDeer will move the second rectangle horizontally so that it connects with
the first rectangle. Find the minimum distance it needs to be moved.
|
[{"input": "3 2 6", "output": "1\n \n\nThis input corresponds to the figure in the statement. In this case, the\nsecond rectangle should be moved to the left by a distance of 1.\n\n* * *"}, {"input": "3 1 3", "output": "0\n \n\nThe rectangles are already connected, and thus no move is needed.\n\n* * *"}, {"input": "5 10 1", "output": "4"}]
|
Print the minimum distance the second rectangle needs to be moved.
* * *
|
s170539763
|
Runtime Error
|
p03778
|
The input is given from Standard Input in the following format:
W a b
|
W,a,b=map(int,input().split())
if a+W<b:
print(b-(W+a)):
else:
print(0)
|
Statement
AtCoDeer the deer found two rectangles lying on the table, each with height 1
and width W. If we consider the surface of the desk as a two-dimensional
plane, the first rectangle covers the vertical range of [0,1] and the
horizontal range of [a,a+W], and the second rectangle covers the vertical
range of [1,2] and the horizontal range of [b,b+W], as shown in the following
figure:

AtCoDeer will move the second rectangle horizontally so that it connects with
the first rectangle. Find the minimum distance it needs to be moved.
|
[{"input": "3 2 6", "output": "1\n \n\nThis input corresponds to the figure in the statement. In this case, the\nsecond rectangle should be moved to the left by a distance of 1.\n\n* * *"}, {"input": "3 1 3", "output": "0\n \n\nThe rectangles are already connected, and thus no move is needed.\n\n* * *"}, {"input": "5 10 1", "output": "4"}]
|
Print the minimum distance the second rectangle needs to be moved.
* * *
|
s642863189
|
Wrong Answer
|
p03778
|
The input is given from Standard Input in the following format:
W a b
|
vals = sorted(list(map(int, input().split())))
print(min(vals[1] - vals[0], vals[2] - vals[1]))
|
Statement
AtCoDeer the deer found two rectangles lying on the table, each with height 1
and width W. If we consider the surface of the desk as a two-dimensional
plane, the first rectangle covers the vertical range of [0,1] and the
horizontal range of [a,a+W], and the second rectangle covers the vertical
range of [1,2] and the horizontal range of [b,b+W], as shown in the following
figure:

AtCoDeer will move the second rectangle horizontally so that it connects with
the first rectangle. Find the minimum distance it needs to be moved.
|
[{"input": "3 2 6", "output": "1\n \n\nThis input corresponds to the figure in the statement. In this case, the\nsecond rectangle should be moved to the left by a distance of 1.\n\n* * *"}, {"input": "3 1 3", "output": "0\n \n\nThe rectangles are already connected, and thus no move is needed.\n\n* * *"}, {"input": "5 10 1", "output": "4"}]
|
Print the minimum distance the second rectangle needs to be moved.
* * *
|
s996642623
|
Runtime Error
|
p03778
|
The input is given from Standard Input in the following format:
W a b
|
w,a,b=map(int,input().split())
if a+w<b:
print(b-a-w)
else:
if a<=b+w and a+w>=b:
print(0)
else:
print(a-b-w)
|
Statement
AtCoDeer the deer found two rectangles lying on the table, each with height 1
and width W. If we consider the surface of the desk as a two-dimensional
plane, the first rectangle covers the vertical range of [0,1] and the
horizontal range of [a,a+W], and the second rectangle covers the vertical
range of [1,2] and the horizontal range of [b,b+W], as shown in the following
figure:

AtCoDeer will move the second rectangle horizontally so that it connects with
the first rectangle. Find the minimum distance it needs to be moved.
|
[{"input": "3 2 6", "output": "1\n \n\nThis input corresponds to the figure in the statement. In this case, the\nsecond rectangle should be moved to the left by a distance of 1.\n\n* * *"}, {"input": "3 1 3", "output": "0\n \n\nThe rectangles are already connected, and thus no move is needed.\n\n* * *"}, {"input": "5 10 1", "output": "4"}]
|
Print the minimum distance the second rectangle needs to be moved.
* * *
|
s168934650
|
Runtime Error
|
p03778
|
The input is given from Standard Input in the following format:
W a b
|
W,a,b=map(int,input().split())
if b>a:
if b-(a+W)==0:
print(0)
exit()
print(b-(a+W))
else:
if a-(b+W)==0:
print(0)
exit()
print(a-(b+W))
|
Statement
AtCoDeer the deer found two rectangles lying on the table, each with height 1
and width W. If we consider the surface of the desk as a two-dimensional
plane, the first rectangle covers the vertical range of [0,1] and the
horizontal range of [a,a+W], and the second rectangle covers the vertical
range of [1,2] and the horizontal range of [b,b+W], as shown in the following
figure:

AtCoDeer will move the second rectangle horizontally so that it connects with
the first rectangle. Find the minimum distance it needs to be moved.
|
[{"input": "3 2 6", "output": "1\n \n\nThis input corresponds to the figure in the statement. In this case, the\nsecond rectangle should be moved to the left by a distance of 1.\n\n* * *"}, {"input": "3 1 3", "output": "0\n \n\nThe rectangles are already connected, and thus no move is needed.\n\n* * *"}, {"input": "5 10 1", "output": "4"}]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.