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 answer as an integer.
* * * | s713229123 | Accepted | p02659 | Input is given from Standard Input in the following format:
A B | A, B = map(float, input().split())
A = int(round(A))
B_0 = B // 1
B_1 = B % 1
ans_0 = round(A * B_0)
ans_1 = A * round(B_1 * 100) // 100
print(int(round(ans_0 + ans_1)))
| Statement
Compute A \times B, truncate its fractional part, and print the result as an
integer. | [{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}] |
Print the answer as an integer.
* * * | s836596887 | Wrong Answer | p02659 | Input is given from Standard Input in the following format:
A B | l = list(map(float, input().split()))
print(int((l[0] * l[1] * 100 // 100)))
| Statement
Compute A \times B, truncate its fractional part, and print the result as an
integer. | [{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}] |
Print the answer as an integer.
* * * | s080921729 | Wrong Answer | p02659 | Input is given from Standard Input in the following format:
A B | lst = input().split()
a = int(lst[0])
b = float(lst[1])
print(str(a * b).split('.')[0])
| Statement
Compute A \times B, truncate its fractional part, and print the result as an
integer. | [{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}] |
For each map, your program should output a line containing the minimum number
of moves. If the map includes 'dirty tiles' which the robot cannot reach, your
program should output -1. | s482661657 | Runtime Error | p00721 | The input consists of multiple maps, each representing the size and
arrangement of the room. A map is given in the following format.
> _w h
> _ _c_ 11 _c_ 12 _c_ 13 ... _c_ 1 _w_
> _c_ 21 _c_ 22 _c_ 23 ... _c_ 2 _w_
> ...
> _c_ _h_ 1 _c_ _h_ 2 _c_ _h_ 3 ... _c_ _hw_
> _
The integers _w_ and _h_ are the lengths of the two sides of the floor of the
room in terms of widths of floor tiles. _w_ and _h_ are less than or equal to
20. The character _c yx_ represents what is initially on the tile with
coordinates (_x, y_) as follows.
> '`.`' : a clean tile
> '`*`' : a dirty tile
> '`x`' : a piece of furniture (obstacle)
> '`o`' : the robot (initial position)
>
In the map the number of 'dirty tiles' does not exceed 10. There is only one
'robot'.
The end of the input is indicated by a line containing two zeros. | from heapq import heappush, heappop
INF = 10**20
direct = ((0, -1), (0, 1), (-1, 0), (1, 0))
def dist(fr, to, mp):
que = []
heappush(que, (0, fr))
visited = [[False] * len(mp[0]) for _ in range(len(mp))]
visited[fr[1]][fr[0]] = True
while que:
d, point = heappop(que)
x, y = point
for dx, dy in direct:
nx, ny = x + dx, y + dy
if (nx, ny) == to:
return d + 1
if not visited[ny][nx] and mp[ny][nx] == ".":
visited[ny][nx] = True
heappush(que, (d + 1, (nx, ny)))
else:
return -1
def shortest(fr, rest, edges):
if rest == []:
return 0
ret = INF
for d, to in edges[fr]:
if to in rest:
ret = min(ret, d + shortest(to, [i for i in rest if i != to], edges))
return ret
while True:
w, h = map(int, input().split())
if w == 0:
break
mp = ["x" + input() + "x" for _ in range(h)]
mp.insert(0, "x" * (w + 2))
mp.append("x" * (w + 2))
stains = []
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp[y][x] in ("*", "o"):
stains.append((x, y))
stain_num = len(stains)
edges = [[] for _ in range(stain_num)]
miss_flag = False
for i in range(stain_num):
for j in range(i + 1, stain_num):
fr = stains[i]
to = stains[j]
d = dist(fr, to, mp)
if d == -1:
miss_flag = True
edges[i].append((d, j))
edges[j].append((d, i))
if miss_flag:
print(-1)
continue
print(shortest(0, [i for i in range(1, stain_num)], edges))
| F: Cleaning Robot
Here, we want to solve path planning for a mobile robot cleaning a rectangular
room floor with furniture.
Consider the room floor paved with square tiles whose size fits the cleaning
robot (1 × 1). There are 'clean tiles' and 'dirty tiles', and the robot can
change a 'dirty tile' to a 'clean tile' by visiting the tile. Also there may
be some obstacles (furniture) whose size fits a tile in the room. If there is
an obstacle on a tile, the robot cannot visit it. The robot moves to an
adjacent tile with one move. The tile onto which the robot moves must be one
of four tiles (i.e., east, west, north or south) adjacent to the tile where
the robot is present. The robot may visit a tile twice or more.
Your task is to write a program which computes the minimum number of moves for
the robot to change all 'dirty tiles' to 'clean tiles', if ever possible. | [{"input": "5\n .......\n .o...*.\n .......\n .*...*.\n .......\n 15 13\n .......x.......\n ...o...x....*..\n .......x.......\n .......x.......\n .......x.......\n ...............\n xxxxx.....xxxxx\n ...............\n .......x.......\n .......x.......\n .......x.......\n ..*....x....*..\n .......x.......\n 10 10\n ..........\n ..o.......\n ..........\n ..........\n ..........\n .....xxxxx\n .....x....\n .....x.*..\n .....x....\n .....x....\n 0 0", "output": "49\n -1"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s335276766 | Accepted | p03224 | Input is given from Standard Input in the following format:
N | N = int(input())
chk = (2 * N) ** (1 / 2)
k = chk // 1
if N != k * (k + 1) // 2:
print("No")
else:
print("Yes")
k = int(k)
print(k + 1)
ans_list = [[0 for i in range(k)] for j in range(k + 1)]
W1 = 0
H1 = 0
W2 = 0
H2 = 1
for i in range(N):
ans_list[H1][W1] = i + 1
ans_list[H2][W2] = i + 1
if H1 == W1:
H1 = 0
W1 = W1 + 1
H2 = W1 + 1
W2 = 0
else:
H1 += 1
W2 += 1
for i in range(k + 1):
print(str(k) + " " + " ".join(str(n) for n in ans_list[i]))
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s263472143 | Runtime Error | p03224 | Input is given from Standard Input in the following format:
N | N = int(input())
t = [2,1]
h = [[1],[1]]
while t[1]<=N:
if t[1]==N:
print("Yes")
print(t[0])
[print("{0} {1}".format(len(h[i])," ".join([str(j) for j in h[i]]))) for i in ra
nge(len(h))]
break
else:
[h[i].append(t[1]+1+i) for i in range(len(h))]
h.append([t[1]+1+i for i in range(len(h))])
t[1]+=t[0]
t[0]+=1
else:
print("No")
exit()
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s049081858 | Wrong Answer | p03224 | Input is given from Standard Input in the following format:
N | def main():
N = int(input())
if N == 1:
ret1 = """
Yes
2
1 1
1 1"""
if N == 3:
ret1 = """
Yes
3
2 1 2
2 3 1
2 2 3"""
else:
ret1 = "No"
# 出力
print("{}".format(ret1))
if __name__ == "__main__":
main()
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s537189428 | Wrong Answer | p03224 | Input is given from Standard Input in the following format:
N | print("NO")
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s409804938 | Runtime Error | p03224 | Input is given from Standard Input in the following format:
N | N = int(input())
if N == 1:
print('Yes')
print('1 1')
print('1 1)
elif N == 3:
print('Yes')
print('2 1 2')
print('2 3 1')
print('2 2 3')
else:
print('No') | Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s558620190 | Wrong Answer | p03224 | Input is given from Standard Input in the following format:
N | input()
print("No")
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s216290446 | Runtime Error | p03224 | Input is given from Standard Input in the following format:
N | n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
m = sorted(
(-1) ** (i + 1) if i == 0 or i == n - 1 else 2 * ((-1) ** (i + 1)) for i in range(n)
)
f = lambda x, y: x * y
a = abs(sum(map(f, l, m)))
b = abs(sum(map(f, l[::-1], m)))
print(max(a, b))
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not
exist, print `No`. If such a tuple exists, print `Yes` first, then print such
subsets in the following format:
k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}
where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.
If there are multiple such tuples, any of them will be accepted.
* * * | s075282888 | Wrong Answer | p03224 | Input is given from Standard Input in the following format:
N | N = int(input())
for i in range(2000):
if i * (i - 1) // 2 == N:
c = 1
X = [[] for _ in range(i)]
for j in range(i):
for k in range(j + 1, i):
X[j].append(c)
X[k].append(c)
c += 1
for x in X:
print(len(x), *x)
break
else:
print("No")
| Statement
You are given an integer N. Determine if there exists a tuple of subsets of
\\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:
* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.
If such a tuple exists, construct one such tuple. | [{"input": "3", "output": "Yes\n 3\n 2 1 2\n 2 3 1\n 2 2 3\n \n\nIt can be seen that (S_1,S_2,S_3)=(\\\\{1,2\\\\},\\\\{3,1\\\\},\\\\{2,3\\\\}) satisfies\nthe conditions.\n\n* * *"}, {"input": "4", "output": "No"}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s471944561 | Accepted | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# 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)]
#####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
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####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 - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
A = IL()
dic = DD(int)
for i in range(1, N + 2):
a = A[i - 1]
if not dic[a]:
dic[a] = i
else:
l, r = dic[a], i
for i in range(1, N + 2):
ans = nCr(N + 1, i)
ans -= nCr(N + l - r, i - 1)
print(ans % MOD)
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s167532146 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | N=int(input())
A=list(map(int,input().split()))
from collections import Counter
two=0
a=Counter(A)
for k,v in a.items():
if v==2:
two=k
LR=[]
for i in range(N+1):
if A[i]==two:
LR.append(i)
L=LR[0]
R=LR[1]
mod=10**9+7
P=[1 for i in range(10**6+1)]
for i in range(10**6):
P[i+1]=P[i]*(i+1)%mod
L+=1
R+=1
def comb(a,b):
if a>=b:
return P[a]*pow(P[a-b],mod-2,mod)*pow(P[b],mod-2,mod)%mod
else:
return 0
for i in range(1,N+2):
print((comb(N+1,i)-comb(N+L-R,i-1))%mo | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s057581042 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import sys
finput=lambda:sys.stdin.readline().strip()
def main():
p=10**9+7
n=int(finput())
a=list(map(int,finput().split()))
k=sum(a)-(n*(n+1))//2
pk=[i for i in range(n+1) if a[i]==k]
fact=[1]*(n+2)
ifact=[1]*(n+2)
for i in range(1,n+2):
fact[i]=fact[i-1]*i % p
a=fact[-1]
inv=1
m=p-2
while m>0:
if m&1:
inv=a*inv % p
m>>=1
a=a*a % p
ifact[-1]=inv
for i in range(n+1,0,-1):
ifact[i-1]=ifact[i]*i
ans0=[0]*(n+2)
ans1=[0]*(n+2)
ans2=[0]*(n+2)
sn=pk[0]+n-pk[1]
for i in range(n):
ans0[i]=fact[n-1]*ifact[n-i-1]*ifact[i]%p
ans1[i+1]=ans0[i]*2-(sn>i)*(fact[sn]*ifact[sn-i]*ifact[i] % p)
ans2[i+2]=ans0[i]import sys
finput=lambda:sys.stdin.readline().strip()
def main():
p=10**9+7
n=int(finput())
a=list(map(int,finput().split()))
k=sum(a)-(n*(n+1))//2
pk=[i for i in range(n+1) if a[i]==k]
fact=[1]*(n+2)
ifact=[1]*(n+2)
for i in range(1,n+2):
fact[i]=fact[i-1]*i % p
a=fact[-1]
inv=1
m=p-2
while m>0:
if m&1:
inv=a*inv % p
m>>=1
a=a*a % p
ifact[-1]=inv
for i in range(n+1,0,-1):
ifact[i-1]=ifact[i]*i
ans0=[0]*(n+2)
ans1=[0]*(n+2)
ans2=[0]*(n+2)
sn=pk[0]+n-pk[1]
for i in range(0,n+2):
if i<n:
ans0[i]=fact[n-1]*ifact[n-i-1]*ifact[i]%p
ans1[i+1]=ans0[i]*2-(sn>=i)*(fact[sn]*ifact[sn-i]*ifact[i] % p)
ans2[i+2]=ans0[i]
if i>0:
print((ans0[i]+ans1[i]+ans2[i]) % p)
if __name__=='__main__':
main()
print((ans0[i]+ans1[i]+ans2[i]) % p)
if __name__=='__main__':
main()
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s120605309 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | class BigCombination(object):
__slots__ = ["mod", "factorial", "inverse"]
def __init__(self, mod: int 10**9+7, max_n: int 10**6):
fac, inv = [1], []
fac_append, inv_append = fac.append, inv.append
for i in range(1, max_n+1):
fac_append(fac[-1] * i % mod)
inv_append(pow(fac[-1], mod-2, mod))
for i in range(max_n, 0, -1):
inv_append(inv[-1] * i % mod)
self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]
def get_combination(self, n, r):
return self.factorial[n] * self.inverse[r] * self.inverse[n-r] % self.mod
def get_permutation(self, n, r):
return self.factorial[n] * self.inverse[n-r] % self.mod
N = int(input())
A = [int(x) for x in input().split()]
se = []
c = sum(A) - N * (N + 1) / 2
for i in range(len(A)):
if A[i] == c:
se.append(i)
l = se[0]
r = se[1]
import math
Big = BigCombination()
print(N)
for i in range(2,N+2):
k = Big.get_combination(N+1, i)
t = Big.get_combination(l+N-r,i-1)
print(l+N-r,i-1)
if l+N-r == 0 :t = 0
res = k -t
print(res) | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s965314763 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | #include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;
using namespace boost;
struct Mod {
static constexpr auto kMod = 1000000007L;
// can be implicitly converted
Mod(int64_t n) : n(n) {}
Mod operator*(Mod m) const { return (n * (m.n % kMod)) % kMod; }
Mod& operator*=(Mod m) {
*this = *this * m;
return *this;
}
Mod pow(int64_t p) {
if (p == 0) {
return 1;
}
if (p == 1) {
return n;
}
int64_t r = this->pow(p / 2).n;
if (p % 2 == 0) {
return r * r % kMod;
} else {
return (r * r % kMod) * n % kMod;
}
}
Mod operator/(Mod m) const {
if (n == 0) {
return 0;
}
return *this * m.pow(kMod - 2);
}
Mod& operator/=(Mod m) {
*this = *this / m;
return *this;
}
Mod operator+(Mod m) const { return (n + m.n) % kMod; }
Mod& operator+=(Mod m) {
*this = *this + m;
return *this;
}
Mod operator-(Mod m) const { return (kMod + n - m.n) % kMod; }
Mod& operator-=(Mod m) {
*this = *this - m;
return *this;
}
int64_t n;
};
Mod combi(int64_t a, int64_t b) {
Mod c(1);
for (auto i : irange(0L, b)) {
c *= a - i;
c /= i + 1;
}
return c;
}
main() {
int64_t n;
cin >> n;
unordered_map<int64_t, int64_t> a;
int64_t dist = -1;
for (auto i : irange(0L, n + 1)) {
int64_t aa;
cin >> aa;
if (a.count(aa) > 0) {
dist = i - a[aa];
}
a[aa] = i;
}
Mod c = 1; // C(n + 1, 0)
Mod d = 1; // C(n - dist, 0)
for (auto k : irange(1L, n + 2)) {
// C(n + 1, k) = C(n + 1, k - 1) * (n - k + 2) / k
c *= n - k + 2;
c /= k;
// C(n - dist, k - 1) = C(n - dist, k - 2) * (n - dist - k + 2) / (k - 1)
if (k >= 2) {
d *= n - dist - k + 2;
d /= k - 1;
}
if (k - 1 <= n - dist) {
cout << (c - d).n << endl;
} else {
cout << c.n << endl;
}
}
} | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s956119202 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | # 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
# mを法とするaの乗法的逆元
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
n = int(input())
A = list(map(int, input().split()))
C = [-1] * (n+1)
lr = 0
for i, a in enumerate(A):
if C[a] == -1:
C[a] = i
else:
lr = C[a] + n - i
break
def combination(n):
lst = [1]
mod = 10**9+7
for i in range(1, n+1):
lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
return lst
NC = combination(n+1)
LRC = combination(lr)
for i in range(1, n+2):
print(NC[i] - (LRC[i-1] if i-1 <= lr else 0)) | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s368228826 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import sys
finput=lambda:sys.stdin.readline().strip()
def main():
p=10**9+7
n=int(finput())
a=list(map(int,finput().split()))
k=sum(a)-(n*(n+1))//2
pk=[i for i in range(n+1) if a[i]==k]
fact=[1]*(n+2)
ifact=[1]*(n+2)
for i in range(1,n+2):
fact[i]=fact[i-1]*i % p
a=fact[-1]
inv=1
m=p-2
while m>0:
if m&1:
inv=a*inv % p
m>>=1
a=a*a % p
ifact[-1]=inv
for i in range(n+1,0,-1):
ifact[i-1]=ifact[i]*i
ans0=[0]*(n+2)
ans1=[0]*(n+2)
ans2=[0]*(n+2)
sn=pk[0]+n-pk[1]
for i in range(n):
ans0[i]=fact[n-1]*ifact[n-i-1]*ifact[i]%p
ans1[i+1]=ans0[i]*2
ans2[i+2]=ans0[i]
if sn>i:
ans1[i+1]-=fact[sn]*ifact[sn-i]*ifact[i] % p
print((ans0[i]+ans1[i]+ans2[i]) % p)
if __name__=='__main__':
main()
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s077372880 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | N=int(input())
A=[int(x) for x in input().split()]
#重複始点終点調査
se=[]
for i in range(len(A)):
if A[i]==sum(A)-N*(N+1)/2:
se.append(i)
mod=10**9+7
#階乗計算
factorial=[1]
for i in range(1,N+2):
factorial.append(factorial[i-1]*i %mod)
#逆元計算
inverse=[0]*(N+2)
inverse[N+2-1] = pow(factorial[N+2-1], mod-2,mod)
for i in range(N+2-2, -1, -1):
inverse[i] = inverse[i+1] * (i+1) % mod
#combination計算
def nCr(n,r):
if n<r or n==0 or r==0:
return 0
return factorial[n] * inverse[r] * inverse[n-r] % mod
print(N)
if N==1:
print(N)
else:
for i in range(1,N+1):
ans = nCr(N+1, i+1)
if if se[0] + N -se[1] >= i:
ans-=nCr(se[0]+N-se[1],i)
print(int(ans)) | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s504355047 | Wrong Answer | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import sys
import math
N = int(input())
a = list(map(int, input().split()))
"""
def combination(n,k):
if k == 0:
return 1
elif k == n:
return 1
else:
return math.factorial(n)/math.factorial(n-k)/math.factorial(k)
#hoge = "1 2 1 3"
#a_array = list(map(int,hoge.split(" ")))
#a_array = [2,3,1,4,5,1,6,7]
#a_array = [1,2,1,3]
#N = len(a_array)-1
#print(N)
#print(a_array)
indexes = [i for i, x in enumerate(a_array) if x == 1]
#print(indexes)
r = indexes[0] + N-indexes[1]
#print(r)
for i in range(1,N+2):
if r >= i-1:
print(int(combination(N+1,i)-combination(r,i-1)))
else:
print(int(combination(N+1,i)))
"""
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s701596784 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | from math import factorial
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
F = [(factorial(i) % (pow(10, 9)+7)) for i in range(n+2)]
G = [(pow(F[i], (pow(10, 9)+5)) % (pow(10, 9)+7)) for i in range(n+2)]
b = [key for key,val in Counter(a).items() if val > 1]
c = [i for i, x in enumerate(a) if x == b[0]]
B = c[1] - c[0] - 1
X = n + c[0] - c[1]
for k in range(1:n+2):
if k <= X+1:
Y = (F[n+1] * G[k] * G[n+1-k]) - (F[X] * G[k-1] * G[X-k+1])
print(Y)
else:
Y = (F[n+1] * G[k] * G[n+1-k])
print(Y) | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s247403540 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | N=int(input())
A=[int(x) for x in input().split()]
#重複始点終点調査
se=[]
c=sum(A)-N*(N+1)/2:
for i in range(len(A)):
if A[i]==c:
se.append(i)
l=se[0]
r=se[1]
mod=10**9+7
#階乗計算
factorial=[1]
inverse=[1]
for i in range(1,N+2):
factorial.append(factorial[-1]*i %mod)
inverse.append((pow(factorial[i], mod-2, mod)))
#combination計算
def nCr(n,r):
if n<r or n==0 or r==0:
return 0
return factorial[n] * inverse[r] * inverse[n-r] % mod
print(N)
for i in range(2,N+2):
print(int(nCr(N+1,i)-nCr(l+N-r,i-1))%mod)
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s593998315 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import sys
#import math
N = int(input())
a = list(map(int, input().split()))
def combination(n,k):
if k == 0:
return 1
elif k == n:
return 1
else:
return 1:
#return math.factorial(n)/math.factorial(n-k)/math.factorial(k)
#hoge = "1 2 1 3"
#a_array = list(map(int,hoge.split(" ")))
#a_array = [2,3,1,4,5,1,6,7]
#a_array = [1,2,1,3]
#N = len(a_array)-1
#print(N)
#print(a_array)
indexes = [i for i, x in enumerate(a_array) if x == 1]
#print(indexes)
r = indexes[0] + N-indexes[1]
#print(r)
for i in range(1,N+2):
if r >= i-1:
print(int(combination(N+1,i)-combination(r,i-1)))
else:
print(int(combination(N+1,i)))
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s317952713 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
n=int(input())
m=n+1
a=list(map(int,input().split()))
# MOD combination
def cmb(n, r, mod=10**9+7):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
ma=0
dic={}
for i in range(m):
if not a[i] in dic:
dic[a[i]]=i
else:
ma=i-dic[a[i]]-1
for k in range(1,m+1):
if k==1:
print(n)
continue
tmp=(cmb(m,k)
if m-2-ma>=k-1:
tmp-=cmb(m-2-ma,k-1)
print(tmp%mod) | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s078316992 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | print("reference: maspy")
# 基本的に重複がない
# n+1Ck − (n+1)-(r-l+1)Ck−1
MOD = 10 ** 9 + 7
U = 10 ** 5 + 1
# (a ^ n % MOD) を2部探索的に求められる。
def power_mod(a, n):
if n == 0:
return 1
x = (power_mod(a, n // 2) ** 2) % MOD
return x if n % 2 == 0 else (a * x) % MOD
"""
# practice 1
def power_mod(a, n):
if n == 0:
return 1
x = (power_mod(a, n // 2) ** 2) % MOD
return x if n % 2 == 0 else (a * x) % MOD
# practice 2
def power_mod(a, n):
if n == 0:
return 1
x = (power_mod(a, n // 2) ** 2) % MOD
return x if n % 2 == 0 else (a * x) % MOD
"""
# 逆元を求めている。
def make_fact(fact, fact_inv):
for i in range(1, U + 1):
fact[i] = (fact[i - 1] * i) % MOD
fact_inv[U] = power_mod(fact[U], MOD - 2)
for i in range(U, 0, -1): # [U, 1]
fact_inv[i - 1] = (fact_inv[i] * i) % MOD
def comb(n, k):
if k < 0 or k > n:
return 0
x = fact[n]
x *= fact_inv[k]
x %= MOD
x *= fact_inv[n-k]
x %= MOD
return x
fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
make_fact(fact, fact_inv)
# ここまではcombのtableを作っている。
# 重複の起きる場所の間隔だけが問題
n = int(input())
A = [int(x) for x in input().split()]
memo = dict()
for i, a in enumerate(A): # lenを使うならこちらを積極的に。
if a in memo: # 離脱条件を先に。
d = i - memo[a]
break
memo[a] = i # ある数字が何番目にいるか。
rest = n - d
for k in range(1, n + 2): # [1, n + 1]
ans = comb(n + 1, k) - comb(rest, k - 1)
ans %= MOD
print(ans) | Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s138103689 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | # 繰り返し二乗法 (mod 有り)
def mod_rep_pow(a, n, mod=(10 ** 9 + 7)):
res = 1
while n > 0:
if n % 2 == 0:
a = a ** 2 % mod
n //= 2
else:
res = res * a % mod
n -= 1
return (res % mod)
# 繰り返し二乗法 (mod 有り) を利用して nCk を高速に返す
# mod が素数のときのみ利用可能 (フェルマーの小定理を利用しているため)
def mod_comb(n, k, mod=(10 ** 9 + 7)):
res1 = 1
for i in range(n, (n - k), -1):
res1 *= i
res1 %= mod
res2 = 1
for i in range(1, (k + 1)):
res2 *= i
res2 %= mod
return ((res1 * mod_rep_pow(res2, (mod - 2), mod)) % mod)
n = int(input().strip())
a = list(map(int, input().split()))
not_unique = sum(a) - sum([i for i in range(1, n + 1)])
b = []
for i in range(n + 1):
if a[i] == not_unique:
b.append(i)
x = n - (b[1] - b[0])
for i in range(1, n + 2):
print(mod_comb(n + 1, i) # - mod_comb(x, (i - 1)))
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s307573150 | Runtime Error | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import sys
input=sys.stdin.readline
def solve():
N = int(input())
d = {i:-1 for i in range(1, N+1)}
*l, = map(int, input().split())
MOD = 10**9+7
n = N+1
fac = [1]*(n+1)
rev = [1]*(n+1)
for i in range(1,n+1):
fac[i] = i*fac[i-1]%MOD
rev[i] = pow(fac[i], MOD-2, MOD)
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD if a>=b else 0
for i, j in enumerate(l):
if d[j] != -1:
break
d[j] = i
v = d[j]+N-i
for i in range(1, N+2):
print((comb(N+1, i)-comb(v, i-1))%MOD)
if __name__ == "__main__":
solve()
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s412007519 | Accepted | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | # -*- coding: utf-8 -*-
import sys
from collections import Counter
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
class FactInvMOD:
"""階乗たくさん使う時用のテーブル準備"""
def __init__(self, MAX, MOD):
"""MAX:階乗に使う数値の最大以上まで作る"""
MAX += 1
self.MAX = MAX
self.MOD = MOD
# 階乗テーブル
factorial = [1] * MAX
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
factorial[i] = factorial[i - 1] * i % MOD
# 階乗の逆元テーブル
inverse = [1] * MAX
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[MAX - 1] = pow(factorial[MAX - 1], MOD - 2, MOD)
for i in range(MAX - 2, 0, -1):
# 最後から戻っていくこのループならMAX回powするより処理が速い
inverse[i] = inverse[i + 1] * (i + 1) % MOD
self.fact = factorial
self.inv = inverse
def nCr(self, n, r):
"""組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく)"""
if n < r:
return 0
# 10C7 = 10C3
r = min(r, n - r)
# 分子の計算
numerator = self.fact[n]
# 分母の計算
denominator = self.inv[r] * self.inv[n - r] % self.MOD
return numerator * denominator % self.MOD
def nPr(self, n, r):
"""順列"""
if n < r:
return 0
return self.fact[n] * self.inv[n - r] % self.MOD
def nHr(self, n, r):
"""重複組み合わせ"""
# r個選ぶところにN-1個の仕切りを入れる
return self.nCr(r + n - 1, r)
N = INT()
A = LIST()
# 唯一2つある値を見つける
target = 0
for k, v in Counter(A).items():
if v == 2:
target = k
break
idx = A.index(target)
# 2つある値の1回目と2回目の出現位置の間にいくつ数があるか
btw = A[idx + 1 :].index(target)
fim = FactInvMOD(N + 1, MOD)
for i in range(1, N + 2):
# 部分列の総数 - 重複分
ans = fim.nCr(N + 1, i) - fim.nCr(N - 1 - btw, i - 1)
print(ans % MOD)
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s710465544 | Accepted | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | import collections
import sys
input = sys.stdin.readline
ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
class Combinations:
def __init__(self, max_num, mod):
self.mod = mod
self.factorials = [1]
for i in range(1, max_num + 1):
self.factorials.append((self.factorials[-1] * i) % mod)
self.invs = [pow(self.factorials[-1], mod - 2, mod)]
for i in reversed(range(1, max_num + 1)):
self.invs.append(self.invs[-1] * i % mod)
self.invs = self.invs[::-1]
def __call__(self, n, k):
if n < 0 or k < 0 or k > n:
return 0
return self.factorials[n] * self.invs[k] * self.invs[n - k] % self.mod
MOD = 10**9 + 7
n = ri()
ls = ril()
counter = collections.Counter(ls)
d = counter.most_common()[0][0]
l, r = [i for i in range(n + 1) if ls[i] == d]
combinations = Combinations(n + 1, MOD)
for k in range(1, n + 2):
res = combinations(n + 1, k) - combinations(l + n - r, k - 1)
res += MOD
res %= MOD
print(res)
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s937498402 | Accepted | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | MOD = 10**9 + 7
class Fp(int):
def __new__(self, x=0):
return super().__new__(self, x % MOD)
def inv(self):
return self.__class__(super().__pow__(MOD - 2, MOD))
def __add__(self, value):
return self.__class__(super().__add__(value))
def __sub__(self, value):
return self.__class__(super().__sub__(value))
def __mul__(self, value):
return self.__class__(super().__mul__(value))
def __floordiv__(self, value):
return self.__class__(self * self.__class__(value).inv())
def __pow__(self, value):
return self.__class__(super().__pow__(value % (MOD - 1), MOD))
__radd__ = __add__
__rmul__ = __mul__
def __rsub__(self, value):
return self.__class__(-super().__sub__(value))
def __rfloordiv__(self, value):
return self.__class__(self.inv() * value)
def __iadd__(self, value):
self = self + value
return self
def __isub__(self, value):
self = self - value
return self
def __imul__(self, value):
self = self * value
return self
def __ifloordiv__(self, value):
self = self // value
return self
def __ipow__(self, value):
self = self**value
return self
def __neg__(self):
return self.__class__(super().__neg__())
class Combination:
def __init__(self, max_n):
self.max_n = 0
self.fact = [Fp(1)]
self.ifact = [Fp(1)]
self.make_fact_list(max_n)
def C(self, n, k):
return self.fact[n] * self.ifact[k] * self.ifact[n - k] if 0 <= k <= n else 0
def H(self, n, k):
return self.C(n + k - 1, k) if n or k else 1
def P(self, n, k):
return self.fact[n] * self.ifact[n - k] if 0 <= k <= n else 0
def make_fact_list(self, max_n):
if max_n <= self.max_n:
return
self.fact += [Fp(0)] * (max_n - self.max_n)
self.ifact += [Fp(0)] * (max_n - self.max_n)
for i in range(self.max_n + 1, max_n + 1):
self.fact[i] = self.fact[i - 1] * i
self.ifact[i] = self.ifact[i - 1] // i
self.max_n = max_n
N = int(input())
A = list(map(int, input().split()))
B = [-1] * (N + 1)
for i, a in enumerate(A):
if B[a] >= 0:
break
B[a] = i
L = B[a]
R = N - i
M = i - B[a] - 2
print(N)
comb = Combination(N + 1)
for k in range(2, N + 2):
print(comb.C(N + 1, k) - comb.C(L + R, k - 1))
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print n+1 lines. The k-th line should contain the number of the different
subsequences of the given sequence with length k, modulo 10^9+7.
* * * | s797440459 | Accepted | p03674 | Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1} | from collections import Counter
class Mint:
MOD = 1000000007 # Must be a prime
CACHE_FACTORIALS = [1, 1]
def __init__(self, v):
if self.__isally(v):
self.v = v.v % self.MOD
else:
self.v = v % self.MOD
@property
def inv(self):
return Mint(self.__minv(self.v))
@classmethod
def factorial(cls, v):
for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
return Mint(cls.CACHE_FACTORIALS[int(v)])
@classmethod
def perm(cls, n, r):
if n < r or r < 0:
return 0
return cls.factorial(n) // cls.factorial(n - r)
@classmethod
def comb(cls, n, r):
if n < r or r < 0:
return 0
return cls.perm(n, r) // cls.factorial(r)
@classmethod
def __isally(cls, v) -> bool:
return isinstance(v, cls)
@classmethod
def __minv(cls, v) -> int:
return pow(v, cls.MOD - 2, cls.MOD)
@classmethod
def __mpow(cls, v, w) -> int:
return pow(v, w, cls.MOD)
def __str__(self):
return str(self.v)
__repr__ = __str__
def __int__(self):
return self.v
def __eq__(self, w):
return self.v == w.v if self.__isally(w) else self.v == w
def __add__(self, w):
return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
__radd__ = __add__
def __sub__(self, w):
return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)
def __rsub__(self, u):
return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)
def __mul__(self, w):
return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
__rmul__ = __mul__
def __floordiv__(self, w):
return (
Mint(self.v * self.__minv(w.v))
if self.__isally(w)
else Mint(self.v * self.__minv(w))
)
def __rfloordiv__(self, u):
return (
Mint(u.v * self.__minv(self.v))
if self.__isally(u)
else Mint(u * self.__minv(self.v))
)
def __pow__(self, w):
return (
Mint(self.__mpow(self.v, w.v))
if self.__isally(w)
else Mint(self.__mpow(self.v, w))
)
def __rpow__(self, u):
return (
Mint(self.__mpow(u.v, self.v))
if self.__isally(u)
else Mint(self.__mpow(u, self.v))
)
N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i + 1)
l = i
m = j - i - 1
n = N - j
for k in range(1, N + 2):
ans = (
Mint.comb(l + m + n, k)
+ Mint.comb(l + m + n, k - 1) * 2
- Mint.comb(l + n, k - 1)
+ Mint.comb(l + m + n, k - 2)
)
print(ans)
| Statement
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which
consists of the n integers 1,...,n. It is known that each of the n integers
1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences
(not necessarily contiguous) of the given sequence with length k, modulo
10^9+7. | [{"input": "3\n 1 2 1 3", "output": "3\n 5\n 4\n 1\n \n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and\n2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and\n2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\n* * *"}, {"input": "1\n 1 1", "output": "1\n 1\n \n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\n* * *"}, {"input": "32\n 29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9", "output": "32\n 525\n 5453\n 40919\n 237336\n 1107568\n 4272048\n 13884156\n 38567100\n 92561040\n 193536720\n 354817320\n 573166440\n 818809200\n 37158313\n 166803103\n 166803103\n 37158313\n 818809200\n 573166440\n 354817320\n 193536720\n 92561040\n 38567100\n 13884156\n 4272048\n 1107568\n 237336\n 40920\n 5456\n 528\n 33\n 1\n \n\nBe sure to print the numbers modulo 10^9+7."}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s059527684 | Wrong Answer | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | n = int(input())
lst = list(map(int, input().split()))
lst.sort()
print(lst)
i = n // 2
j = i - 1
print(lst[i] - lst[j])
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s263565569 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | x = int(input())
y = input().split()
for u in range(len(y)):
y[u] = int(y[u])
y = sorted(y)
count = y[int(len(y) / 2)] - y[int((len(y) / 2)) - 1]
print(count)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s964889299 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | n = int(input())
# print(n)
di = []
for i in map(int, input().split()):
di.append(i)
di.sort()
n1 = int(n / 2)
m = di[n1] - di[n1 - 1]
print(m)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s098018835 | Runtime Error | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | N = int(int(input()) / 2)
N -= (N + 1) % 2
a = sorted(input().split())
print(int(a[N + 1]) - int(a[N]))
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s602061569 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_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 ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
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()
D = LIST()
D.sort()
D1 = D[: N // 2]
D2 = D[N // 2 :]
print(D2[0] - D1[-1])
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s789691896 | Wrong Answer | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | n = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
len = n // 2
print(A[len] - A[len - 1])
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s000482261 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | nb = int(input())
liste = [int(x) for x in input().split()]
liste.sort()
index1 = (nb // 2) - 1
index2 = nb // 2
roger = liste[index2] - liste[index1]
print(roger)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s413468758 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | n = int(input())
dd = list(map(int, input().split()))
dd.sort()
# print(dd)
fir = dd[len(dd) // 2 - 1]
sec = dd[len(dd) // 2]
cou = 0
i = fir + 1
# print(fir,sec)
# while i <= sec:
# cou += 1
# i += 1
print(sec - i + 1)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s834316564 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | n = int(input())
dn = list(map(int, input().split()))
dn.sort()
u = dn[n // 2]
l = dn[n // 2 - 1]
print(u - l)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s828019259 | Accepted | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | N = int(input())
P = list(map(int, input().split()))
P.sort()
# print(P)
A = P[int(N / 2) - 1]
B = P[int(N / 2)]
# print(A,B)
print(B - A)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
Print the number of choices of the integer K that make the number of problems
for ARCs and the number of problems for ABCs the same.
* * * | s199590913 | Wrong Answer | p02989 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | N = int(input())
d = [int(i) for i in input().split()]
# N = 6
# d = list(sorted([9, 1, 4, 4, 6, 7]))
# N = 8
# d = sorted([9, 1, 14, 5, 5, 4, 4, 14])
# N = 14
# d = sorted(
# [
# 99592,
# 10342,
# 29105,
# 78532,
# 83018,
# 11639,
# 92015,
# 77204,
# 30914,
# 21912,
# 34519,
# 80835,
# 100000,
# 1,
# ]
# )
l = len(d) // 2
boundary = d[l - 1]
next_d = boundary
boundary_cnt = 0
for i in d[l:]:
if i == boundary:
boundary_cnt += 1
if boundary > 2:
next_d = boundary
break
elif i > boundary:
next_d = i
break
print(next_d - boundary)
| Statement
Takahashi made N problems for competitive programming. The problems are
numbered 1 to N, and the difficulty of Problem i is represented as an integer
d_i (the higher, the harder).
He is dividing the problems into two categories by choosing an integer K, as
follows:
* A problem with difficulty K or higher will be _for ARCs_.
* A problem with difficulty lower than K will be _for ABCs_.
How many choices of the integer K make the number of problems for ARCs and the
number of problems for ABCs the same? | [{"input": "6\n 9 1 4 4 6 7", "output": "2\n \n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and\n4 will be for ABCs, and the objective is achieved. Thus, the answer is 2.\n\n* * *"}, {"input": "8\n 9 1 14 5 5 4 4 14", "output": "0\n \n\nThere may be no choice of the integer K that make the number of problems for\nARCs and the number of problems for ABCs the same.\n\n* * *"}, {"input": "14\n 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1", "output": "42685"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s150269305 | Accepted | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | # -*- 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 #
#############
H, W = IL()
S = SLs(H)
dx = [
-1,
0,
1,
0,
]
dy = [
0,
-1,
0,
1,
]
for x in range(H):
for y in range(W):
if S[x][y] == "#":
flag = 0
for i in range(4):
nx = dx[i] + x
ny = dy[i] + y
if 0 <= nx < H and 0 <= ny < W:
if S[nx][ny] == "#":
flag = 1
if flag == 0:
NE()
Y()
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s646761206 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | H, W = map(int, input().split())
S = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)]
for y in range(1, H+1):
for x in range(1, W+1):
if S[y][x] = '#' and (S[y-1][x] + S[y+1][x] + S[y][x-1] + S[y][x+1]).count('#') == 0:
print("No")
exit()
print("Yes") | Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s903531424 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | H,W = map(int, input().split())
s = [input() for _ in range(H)]
import sys
for j in range(H):
for i in range(W):
if s[j][i] =='#':
if j+1<W and i+1<H and j-1>=0 and i-1>=0:
if (s[j+1][i]=='#' or s[j][i+1]=='#'or s[j][i-1]=='#',or s[j-1][i]=='#'):
continue
if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-1]!='#':
sys.exit()
print('Yes')
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s783475258 | Wrong Answer | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | row, column = map(int, input().split())
S = [list(input()) for i in range(row)]
status = "Yes"
coords = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(row):
for j in range(column):
if S[i][j] == "#":
status = "No"
for dx, dy in coords:
if 0 <= i + dy < row and 0 <= j + dx < column:
if S[i + dy][j + dx] == "#":
status = "Yes"
print(status)
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s979751836 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | h,w = map(int,input())
L = [input() for i in range(h)]
ans = "ahe"
if L[0][0]=="#" and (L[0][1]=="." and L[1][0]=="."):
ans="No"
elif L[0][w]=="#" and (L[0][w-1]=="." and L[1][w]=="."):
ans="No"
elif L[h][0]=="#" and (L[h][1]=="." and L[h-1][0]=="."):
ans="No"
elif L[h][w]=="#" and (L[h][w-1]=="." and L[h-1][w]=="."):
ans="No"
for i in range(1,w):
if L[0][i]=="#" and (L[0][i+1]=="." and L[1][i] =="." and L[1][i-1]):
ans="No"
for i in range(1,w):
if L[h][i]=="#" and (L[h][i+1]=="." and L[h-1][i] =="." and L[h][i-1]):
ans="No"
for i in range(1,h):
if L[i][0]=="#" and (L[i][1]=="." and L[i+1][0]=="." and L[i-1][0]=="."):
ans="No"
for i in range(1,h):
if L[i][w]=="#" and (L[i][w-1]=="." and L[i+1][w]=="." and L[i-1][w]==".")
for i in range(1,h):
for j in range(1,w):
if L[i][j]=="#" and (L[i+1][j]=="." and L[i-1][j]=="." and L[i][j+1]=="." and L[i][j-1]=="."):
ans="No"
if ans !="No":
ans ="Yes"
print(ans) | Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s372712892 | Accepted | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | H, W = map(int, input().split())
i = []
for _ in range(H):
i.append(input())
result = "Yes"
# .
# .#. が無いか調べる
# .
for j in range(H - 1):
for k in range(W):
if i[j][k] == ".":
if k == 0 or j == H - 1 or i[j + 1][k - 1] == ".":
if i[j + 1][k] == "#":
if j == H - 1 or k == W - 1 or i[j + 1][k + 1] == ".":
if j > H - 3 or i[j + 2][k] == ".":
result = "No"
print(result)
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s568914342 | Wrong Answer | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | b = input().split(" ")
H = int(b[0])
W = int(b[1])
a = [0 for i in range(H)]
j = "YES"
for i in range(H):
a[i] = input()
for i0 in range(H):
for i1 in range(W):
if i1 == 0:
if i0 == 0:
if a[0][1] == "." and a[1][0] == "." and a[i0][i1] == "#":
j = "NO"
elif i0 == H - 1:
if a[H - 2][0] == "." and a[H - 1][1] == "." and a[i0][i1] == "#":
j = "NO"
else:
if (
a[i0 - 1][0] == "."
and a[i0 + 1][0] == "."
and a[i0][1] == "."
and a[i0][i1] == "#"
):
j = "NO"
elif i1 == W - 1:
if i0 == 0:
if a[0][W - 2] == "." and a[1][W - 1] == "." and a[i0][i1] == "#":
j = "NO"
elif i0 == H - 1:
if (
a[H - 2][W - 1] == "."
and a[H - 1][W - 2] == "."
and a[i0][i1] == "#"
):
j = "NO"
else:
if (
a[i0 - 1][W - 1] == "."
and a[i0 + 1][W - 1] == "."
and a[i0][W - 2] == "."
and a[i0][i1] == "#"
):
j = "NO"
else:
if i0 == 0:
if (
a[0][i1 - 1] == "."
and a[1][i1] == "."
and a[0][i1 + 1] == "."
and a[i0][i1] == "#"
):
j = "NO"
elif i0 == H - 1:
if (
a[H - 1][i1 - 1] == "."
and a[H - 1][i1 + 1] == "."
and a[H - 2][i1] == "."
and a[i0][i1] == "#"
):
j = "NO"
else:
if (
a[i0 - 1][i1] == "."
and a[i0 + 1][i1] == "."
and a[i0][i1 - 1] == "."
and a[i0][i1 + 1] == "."
and a[i0][i1] == "#"
):
j = "NO"
print(j)
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s075884020 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | import sys
h, w = map(int, input().split())
s = []
for i in range(h):
s.append(input())
ans = True
flag = False
for i in range(h):
for j in range(w):
if s[i][j] == '#':
if i==0 and j==0:
if(s[i+1][j] == '.' and s[i][j+1] == '.'):
ans = False
break
elif i==0 and j==w-1:
if(s[i][j-1] == '.' and s[i][j+1] == '.'):
ans = False
break
elif i==h-1 and j==0:
if(s[i-1][j] == '.' and s[i][j+1] == '.')
ans = False
break
elif i==h-1 and j==w-1:
if(s[i-1][j] == '.' and s[i][j-1] == '.'):
ans = False
break
if i == 0:
if(s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
ans = False
break
elif j == 0:
if(s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
ans = False
break
elif i == h-1:
if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.'):
ans = False
break
elif j == w-1:
if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.'):
ans = False
break
else:
if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
ans = False
break
if not(ans):
break
if ans:
print('Yes')
else:
print('No')
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s258948218 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | h,w=map(int,input().split())
S=[]
for i in range(h):
s=list(map(int,input.split())
S.append(s)
for i in range(h):
for j in range(w):
if S[i+1][j]==S[i][j+1]==S[i-1][j]==S[i][j-1]==".":
print("No")
quit()
print("Yes") | Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s858949890 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | H,W = map(int,input().split())
s = [list(input()) for _ in range(H)]
dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
for i in range(H):
for j in range(W):
if s[i][j] == ".": continue
cnt = 0
for d in dir4:
nx = i + d[0]
ny = j + d[1]
if not (0 <= nx < H): continue
if not (0 <= ny < W): continue
if s[nx][ny] == "#": cnt += 1
if cnt == 0:
print("No")
exit()
print("Yes")
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s152992720 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | H, W = list(map(int, input().split()))
count = 0
s = [[None]*(W+2)]*(H+2)
for i in range(1, H+1):
s[i] = input().split()
for i in range(1, H+1):
for j in range(1, W+1):
if s[i][j] == '#':
if s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
print(No)
break
count_list = [[i, j] for i in range(1, H+1) for j in range(1 W+1) if s[i][j] == '#']
count_black = len(count_list)
if count == count_list:
print(Yes) | Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s445510269 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | height,width = map(int, input().split())
map_list = []
for i in range(height):
map_list.append(list(input()))
map_list[i].append('0')
map_list.append(['0'] * width)
for h in range(height):
for w in range(width):
if map_list[h][w] == '#':
if '#' in [map_list[h-1][w], map_list[h+1][w], map_list[h][w-1], map_list[h][w+1]]:
else:
print("No")
exit()
print("Yes")
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s839551298 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
S.append(list(input()))
for i in range(0,H):
for j in range(0,W):
if S[i][j] == "#":
if i != 0 and S[i-1][j] == "#" : continue
elif i != H-1 and S[i+1][j] == "#": continue
elif j != 0 and S[i][j-1] == "#": continue
elif j != W-1 and S[i][j+1] == "#":continue
else flag = "No"
print(flag)
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
If square1001 can achieve his objective, print `Yes`; if he cannot, print
`No`.
* * * | s374747529 | Runtime Error | p03361 | Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W} | N, M = map(int, input().split())
arr = [list(input()) for i in range(N)]
newmat = [[0 for i in range(M)] for j in range(N)]
nocheck = 0
for i in range(N):
for j in range(M):
if arr[i][j] is '#':
newmat[i][j] = 1
else:
newmat[i][j] = 0
for i in range(N):
for j in range(M):
if newmat[i][j] == 1:
if i == 0 and j == 0:
if newmat[i][j+1] == 0 and newmat[i+1][j] == 0:
nocheck = 1
elif i == 0 and j == (M-1):
if newmat[i][j-1] == 0 and newmat[i+1][j] == 0:
nocheck = 1
elif i == (N-1) and j == 0:
if newmat[i][j+1] == 0 and newmat[i-1][j] == 0:
nocheck = 1
elif i == (N-1) and j == (M-1):
if newmat[i][j-1] == 0 and newmat[i-1][j] == 0:
nocheck = 1
elif i == 0 and j != 0:
if newmat[i][j+1] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
nocheck = 1
elif i != 0 and j == 0:
if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i-1][j] == 0:
nocheck = 1
elif i == (N-1) and j != (M-1):
if newmat[i][j+1] == 0 and newmat[i-1][j] == 0 and newmat[i][j-1] == 0:
nocheck = 1
elif i != (N-1) and j == (M-1):
if newmat[i-1][j] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
nocheck = 1
else:
if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i][j - 1] == 0 and newmat[i-1][j]:
nocheck = 1
if(nocheck == 0):
print("Yes")else:
print("No")
| Statement
We have a canvas divided into a grid with H rows and W columns. The square at
the i-th row from the top and the j-th column from the left is represented as
(i, j).
Initially, all the squares are white. square1001 wants to draw a picture with
black paint. His specific objective is to make Square (i, j) black when s_{i,
j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that
are horizontally or vertically adjacent and paint those squares black, for
some number of times (possibly zero). He may choose squares that are already
painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective. | [{"input": "3 3\n .#.\n ###\n .#.", "output": "Yes\n \n\nOne possible way to achieve the objective is shown in the figure below. Here,\nthe squares being painted are marked by stars.\n\n\n\n* * *"}, {"input": "5 5\n #.#.#\n .#.#.\n #.#.#\n .#.#.\n #.#.#", "output": "No\n \n\nsquare1001 cannot achieve his objective here.\n\n* * *"}, {"input": "11 11\n ...#####...\n .##.....##.\n #..##.##..#\n #..##.##..#\n #.........#\n #...###...#\n .#########.\n .#.#.#.#.#.\n ##.#.#.#.##\n ..##.#.##..\n .##..#..##.", "output": "Yes"}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s160419966 | Wrong Answer | p02823 | Input is given from Standard Input in the following format:
N A B | print(2**20)
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s860566936 | Runtime Error | p02823 | Input is given from Standard Input in the following format:
N A B | import math
finished = False
solutions = []
def rec(A, B, n):
global solutions
global N
if A == B:
solutions.append(n)
if math.floor(N / 2) > n:
if A == 1:
rec(A + 1, B + 1, n + 1)
rec(A + 1, B - 1, n + 1)
rec(A, B + 1, n + 1)
rec(A, B - 1, n + 1)
elif A == N:
rec(A, B + 1, n + 1)
rec(A, B - 1, n + 1)
rec(A - 1, B + 1, n + 1)
rec(A - 1, B - 1, n + 1)
elif B == 1:
rec(A + 1, B + 1, n + 1)
rec(A + 1, B, n + 1)
rec(A - 1, B + 1, n + 1)
rec(A - 1, B, n + 1)
elif B == N:
rec(A + 1, B, n + 1)
rec(A + 1, B - 1, n + 1)
rec(A - 1, B, n + 1)
rec(A - 1, B - 1, n + 1)
else:
rec(A + 1, B + 1, n + 1)
rec(A + 1, B - 1, n + 1)
rec(A - 1, B + 1, n + 1)
rec(A - 1, B - 1, n + 1)
in_string = input()
in_arr = in_string.split()
global N
global A
global B
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])
rec(A, B, 0)
solutions.sort()
print(solutions[0])
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s356280172 | Runtime Error | p02823 | Input is given from Standard Input in the following format:
N A B |
n, a, b = tuple(map(int, input().split(' ')))
if a==1 and b==n:
print(n-1)
if (b-a)%2==0:
print((b-a)//2)
else:
if n-b < a-1:
print(n-a)
elif n-b > a-1:
print(b-1)
else:
print(n-a | Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s102822150 | Accepted | p02823 | Input is given from Standard Input in the following format:
N A B | # -*- coding: utf-8 -*-
# 整数値龍力 複数の入力
def input_multiple_number():
return map(int, input().split())
N_given, A_given, B_given = input_multiple_number()
cnt = 0
while True:
if (B_given - A_given) % 2 == 0:
print(cnt + (B_given - A_given) // 2)
exit(0)
else:
if (N_given - B_given) > (A_given - 1):
cnt += A_given - 1
cnt += 1
A_given = 1
B_given -= cnt
else:
cnt += N_given - B_given
cnt += 1
B_given = N_given
A_given += cnt
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s363466006 | Runtime Error | p02823 | Input is given from Standard Input in the following format:
N A B | def Main(N: int, A: int, B: int):
num_A_up = A
num_B_up = B
num_A_down = A
num_B_down = B
while num_A_down != num_B_up and num_A_up != num_B_down:
num_A_up += 1
num_A_down -= 1
num_B_up += 1
num_B_down -= 1
if num_A_up > N - 1:
num_A_up = N
if num_B_up > N - 1:
num_B_up = N
if num_B_down < 1:
num_B_down = 1
if num_A_down < 1:
num_A_down = 1
print(f" {num_A_down} , {num_A_up} , {num_B_down} , {num_B_up} ")
if num_A_down - num_B_down == 0 or num_A_up - num_B_up == 0:
break
return num_B_up - B
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s774267752 | Wrong Answer | p02823 | Input is given from Standard Input in the following format:
N A B | INP = list(map(int, input().split()))
print(int((INP[1] - INP[0] + 1) / 2))
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s681950482 | Wrong Answer | p02823 | Input is given from Standard Input in the following format:
N A B | s = input().split()
k = int(s[0])
a = int(s[1])
b = int(s[2])
n = int(max(a, b))
m = int(min(a, b))
res = n - m
resp = n + m
if res % 2 == 0:
print(int(n / 2 - m / 2))
elif k - n > m - 1:
print(k - n)
elif m - 1 > k - n:
print(k - m)
elif m - 1 == k - n:
print(n - resp // 2)
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s348910527 | Accepted | p02823 | Input is given from Standard Input in the following format:
N A B | import sys
## io ##
def IS():
return sys.stdin.readline().rstrip()
def II():
return int(IS())
def MII():
return list(map(int, IS().split()))
def MIIZ():
return list(map(lambda x: x - 1, MII()))
## dp ##
def DD2(d1, d2, init=0):
return [[init] * d2 for _ in range(d1)]
def DD3(d1, d2, d3, init=0):
return [DD2(d2, d3, init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str:
return format(x, "b") # rev => int(res, 2)
def to_oct(x: int) -> str:
return format(x, "o") # rev => int(res, 8)
def to_hex(x: int) -> str:
return format(x, "x") # rev => int(res, 16)
MOD = 10**9 + 7
def divc(x, y) -> int:
return -(-x // y)
def divf(x, y) -> int:
return x // y
def gcd(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
return x * y // gcd(x, y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0]
def get_primes(MAX_NUM=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True] * (MAX_NUM + 1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX_NUM**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, MAX_NUM + 1, i):
is_prime[j] = False
return [i for i in range(MAX_NUM + 1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
# ======================================================#
def main():
n, a, b = MII()
if (b - a) % 2 == 0:
print((b - a) // 2)
else:
if n - a < b - 1:
print((n - b + 1) + (n - (a + (n - b + 1))) // 2)
else:
print(a + ((b - a) - 1) // 2)
if __name__ == "__main__":
main()
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s195055992 | Accepted | p02823 | Input is given from Standard Input in the following format:
N A B | n, a, b = map(int, input().split())
if (a - 1) >= (n - b):
count = n - b
a = a + (n - b)
b = n
else:
count = a - 1
b = b - (a - 1)
a = 1
# print(count)
if (b - a) % 2 == 0:
print(min(min(b - 1, n - a), (b - a) // 2))
elif a == 1 and (b - a) % 2 != 0:
print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1) + count)
# print(count)
elif b == n and (b - a) % 2 != 0:
print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1) + count)
elif (b - a) == 3:
print(min(b - 1, n - a) - 1 + count)
elif (b - a) >= 5 and (b - a) % 2 != 0:
print(min(b - 1, n - a) - 2 + count)
else:
print(min(b - 1, n - a) + count)
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s345883489 | Accepted | p02823 | Input is given from Standard Input in the following format:
N A B | # -*- 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 = 10**18
MOD = 10**9 + 7
N, X, Y = MAP()
# 簡単のため大小関係を固定
X, Y = min(X, Y), max(X, Y)
# 偶奇が合ってるなら直接会いに行く
if X % 2 == Y % 2:
ans = abs(X - Y) // 2
# 合わないなら、どっちかの端で調整してから向かう
else:
cnt1 = abs(X - 1) + 1
Y1 = Y - cnt1
cnt2 = abs(Y - N) + 1
X2 = X + cnt2
ans = min(cnt1 + abs(1 - Y1) // 2, cnt2 + abs(N - X2) // 2)
print(ans)
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s126782312 | Runtime Error | p02823 | Input is given from Standard Input in the following format:
N A B | N, A, B = map(int, input().split())
N -= 1
A -= 1
B -= 1
def is_valid(p):
x, y = p
return 0 <= x < N and 0 <= y < N
def meet(p):
x, y = p
return abs(x - y) // 2
def dist(p1, p2):
x1, y1 = p1
x2, y2 = p2
return (abs(x1 - x2) + abs(y1 - y2)) // 2
oo = []
if (A + B) % 2:
o = []
for i in [0, N]:
for j in [1, -1]:
o.append((i, B + j * abs(A - i)))
o.append((A + j * abs(B - i), i))
for x, y in filter(is_valid, o):
for i in [1, -1]:
for j in [1, -1]:
xx = max(0, min(x + i, N))
yy = max(0, min(y + i, N))
oo.append(meet((xx, yy)) + dist((A, B), (x, y)) + 1)
print(min(oo))
else:
print(meet((A, B)))
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s468952088 | Wrong Answer | p02823 | Input is given from Standard Input in the following format:
N A B | print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
print("なんでA問題から答えがあわないの!!!")
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Print the smallest number of rounds after which the friends can get to play a
match against each other.
* * * | s378769942 | Runtime Error | p02823 | Input is given from Standard Input in the following format:
N A B | import math
nyu = list(map(int, input().split()))
N = nyu[0]
A = nyu[1]
B = nyu[2]
if (A + B) % 2 == 0: # 偶奇が一致
kaisu = int(math.log2(B - A))
print(kaisu)
else:
if (N - B) >= (A - 1):
# Bが左端にいく
nA = 1
nB = B - A
if nA == nB:
print(A)
else:
kaisu = int(math.log2(nB - nA))
if kaisu + A <= B - 1:
print(kaisu + A)
else:
print(B - 1)
else:
newB = N
newA = A + (N - B) + 1
if nA == nB:
print(N - B) + 1
else:
kaisu = int(math.log2(nB - nA))
if kaisu + (N - B) + 1 <= N - A:
print(kaisu + (N - B) + 1)
else:
print(N - A)
| Statement
2N players are running a competitive table tennis training on N tables
numbered from 1 to N.
The training consists of _rounds_. In each round, the players form N pairs,
one pair per table. In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.
The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.
Similarly, the loser of the match on table X plays on table X+1 in the next
round, except for the loser of the match on table N who stays at table N.
Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at
will. What is the smallest number of rounds after which the friends can get to
play a match against each other? | [{"input": "5 2 4", "output": "1\n \n\nIf the first friend loses their match and the second friend wins their match,\nthey will both move to table 3 and play each other in the next round.\n\n* * *"}, {"input": "5 2 3", "output": "2\n \n\nIf both friends win two matches in a row, they will both move to table 1."}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s009704965 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | N, T = [int(x) for x in input().split()]
t_list = [int(x) for x in input().split()]
t_s = t_e = ans = 0
for t in t_list:
if t > t_e:
ans += t_e - t_s
t_s = t
t_e = t + T
ans += t_e - t_s
print(ans)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s181401989 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | #N,Tの取得
N,M = map(int, input().split())
#秒のリストを取得
tl = list(map(int, input().split()))
bt = 0 #直前のスイッチを押した時間
gt = T #秒数総和
for t in tl(1:):
if t - bt > T:
gt += T #スイッチオフの時はT秒追加
else:
gt += t - bt #スイッチがオンのとき、前回からの経過時間を加算
bt = t
print(str(gt)) | Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s835981193 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | #N,Tの取得
N,T = map(int, input().split()))
#秒のリストを取得
tl = list(map(int, input().split()))
bt = 0 #直前のスイッチを押した時間
gt = T #秒数総和
for t in tl(1:):
if t - bt > T:
gt += T #スイッチオフの時はT秒追加
else:
gt += t - bt #スイッチがオンのとき、前回からの経過時間を加算
bt = t
print(str(gt)) | Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s907028564 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | N, T = map(int, input().split)
t = input().split()
int(amount) = 0
if t[0] <= T:
amount += t[0]
else:
amount += T
for index in range(N - 1):
t_sub = int(t[index + 1]) - int(t[index])
if t_sub <= T:
amount += t_sub
else:
amount += T
amount += T
print(amount)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s670774226 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | _, T, *t = map(int, open(0).read().split())
print(sum(min(T, j - i) for i, j in zip(t, t[1:])) + T)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s581287503 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | n, t, *a = map(int, open(0).read().split())
print(t * n - sum([t - i + j for i, j in zip(a[1:], a) if i - j <= t]))
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s284910996 | Wrong Answer | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | n, t = map(int, input().split())
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s095438794 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | n, t = list(input())
ts = list(input())
print(sum([min(t, next - prev) for prev, next in zip(ts, ts[1:])], t))
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s647129166 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | (n, t) = (int(i) for i in input().split())
T = [int(j) for j in input().split()]
if n == 1:
print(t)
else:
S = [a - b for a, b in zip(T[1:], T[:-1])]
U = [u if u <= t else t for u in S]
print(sum(U) + t)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s247196963 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | N, T = map(int, input().split())
t = list(map(int, input().split()))
discount = 0
for i in range(N - 1):
if t[i + 1] - t[i] < T:
discount += (T - (t[i + 1] - t[i]))
X = N * T - discount
print(X | Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s153274921 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N |
N, T = map(int, input().split())
t = list(map(int, input().split()))
s, e = 0, 0
ans = 0
for i in range(N):
if t[i] <= e:
e = t[i] + T
else:
ans += e - s
s = t[i]
e = t[i] + T
ans += e - s
print(ans)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s090915512 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | a, b, c = map(int, input().split(" "))
for i in range(1, c):
if (a * i) % b == c:
print("YES")
break
else:
print("NO")
a * (任意の整数) % b = cとできるか?
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s119681067 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | N, T = map(int, input().split())
L = [int(i) for i in input().split()]
gap=[]
time=T
for i in range(N-1)
gap.append(L[i+1]-L[i])
for i in range(N-1):
time += min(B[i],T)
print(time) | Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s588546365 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
return int(input())
def getInts():
return [int(i) for i in input().split()]
def getIntLines(n=1):
res = []
for _ in range(n):
res.append(getInt())
return res
def getIntsLines(n=1):
res = []
for _ in range(n):
res.append(getInts())
return res
def debug(*args, sep=" ", end="\n"):
for item in args:
stderr.write(str(item))
stderr.write(sep)
stderr.write(end)
n, t = getInts()
tl = getInts()
ans = 0
last = 0
last_head = 0
for v in tl:
if v <= last:
last += (v + t) - last
else:
ans += last - last_head
last_head = v
last = last_head + t
ans += last - last_head
print(ans)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s530620645 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | n, T = map(int, input().split())
(*s,) = map(int, input().split())
print(T + sum([min(s[i] - s[i - 1], T) for i in range(1, n)]))
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s836689007 | Wrong Answer | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | from __future__ import print_function
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
return
# import re
# import array
# import copy
# import functools
# import operator
# import math
# import string
import fractions
# from fractions import Fraction
from fractions import gcd
# import collections
# import itertools
# import bisect
# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue
# from itertools import accumulate
# from collections import deque
# from collections import Counter
from operator import mul
from functools import reduce
# def lcm(n,m):
# return int(n*m/gcd(n,m))
def coprimize(p, q):
common = fractions.gcd(p, q)
return (p // common, q // common)
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
# import random
# import time
# import entrypoints
n, t = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
# aa = [a[0]] + [(a[i+1] + a[i]) for i in range(0, n - 1)]
# eprint("aa ", end=": ")
# eprint(aa)
# aa = []
# aa.append(a[0])
# for i in range(1, n):
# aa.append(a[i] + aa[i - 1])
a.append(sys.maxsize)
eprint("aa ", end=": ")
eprint(a)
ans = 0
first_flag = 1
continuous_flag = 0
l_continuous = []
l_distinct = []
for i in range(n):
if a[i] + t >= a[i + 1]:
if not (i in l_continuous):
l_continuous.append(i)
if a[i + 1] != sys.maxsize and not ((i + 1) in l_continuous):
l_continuous.append(i + 1)
else:
if not (i in l_continuous):
l_distinct.append(i)
eprint("l_continuous ", end=": ")
eprint(l_continuous)
eprint("l_distinct ", end=": ")
eprint(l_distinct)
i_start = 0
i_end = 0
for i in l_continuous:
first_flag = 1
if (i in l_continuous) and ((i + 1) in l_continuous):
if first_flag == 1:
i_start = 0
else:
i_end = i
ans += a[i_end] - a[i_start] + t
for i in l_distinct:
ans += t
print(ans)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s382027154 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | n, T, *t = map(int, open(0).read().split())
print(T + sum(min(j - i, T) for i, j in zip(t, t[1:])))
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s980429291 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | n,t=map(int,input().split())
a=[int(i) for i in input().split()]
p=a[0]
c=0
for i a:
c+=t-i if p+t>i else t
print(c) | Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s877119371 | Runtime Error | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | a = list(input().split(" "))
b = list(input().split(" "))
oyu = []
for i in b:
oyu[int(i) : int(i) + int(a[1])] = [1] * int(a[1])
sum(oyu)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s581183520 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | def getinputdata():
# 配列初期化
array_result = []
data = input()
array_result.append(data.split(" "))
flg = 1
try:
while flg:
data = input()
array_temp = []
if data != "":
array_result.append(data.split(" "))
flg = 1
else:
flg = 0
finally:
return array_result
arr_data = getinputdata()
n = int(arr_data[0][0])
t = int(arr_data[0][1])
arr = [int(x) for x in arr_data[1]]
mysum = 0
# print(n, t, arr)
for i in range(0, n - 1):
if arr[i + 1] - arr[i] >= t:
mysum += t
else:
mysum += arr[i + 1] - arr[i]
print(mysum + t)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
Assume that the shower will emit water for a total of X seconds. Print X.
* * * | s545856939 | Accepted | p03731 | Input is given from Standard Input in the following format:
N T
t_1 t_2 ... t_N | A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
C = A[1]
for i in range(A[0] - 1):
ii = i + 1
if B[ii] - B[i] < A[1]:
C = C + B[ii] - B[i]
else:
C = C + A[1]
print(C)
| Statement
In a public bath, there is a shower which emits water for T seconds when the
switch is pushed.
If the switch is pushed when the shower is already emitting water, from that
moment it will be emitting water for T seconds. Note that it does not mean
that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person
will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total? | [{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s659807943 | Runtime Error | p02570 | Input is given from Standard Input in the following format:
D T S | n = int(input())
a_list = list(map(int, input().split()))
ama_a = sum(a_list)
ans = 0
mod = 10**9 + 7
for i in a_list:
ans += i**2
ans = ama_a**2 - ans
ans *= (mod + 1) / 2
ans %= mod
print(int(ans))
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s748379594 | Accepted | p02570 | Input is given from Standard Input in the following format:
D T S | dis, limit, speed = map(int, input().split())
time = dis / speed
judge = "Yes" if time <= limit else "No"
print(judge)
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s861312420 | Runtime Error | p02570 | Input is given from Standard Input in the following format:
D T S | #!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math, sys
n = int(sys.stdin.readline())
a = tuple(map(int, sys.stdin.readline().split()))
# n = int(input())
# a = list(map(int,input().split()))
g = math.gcd(a[0], a[1])
for i in range(2, n):
g = math.gcd(g, a[i])
M = max(a)
acc = a[0]
for i in range(n):
acc = math.gcd(acc, a[i])
if acc != 1:
print("not coprime")
exit()
LIMIT = max(a)
minPrime = [0] * (LIMIT + 1)
minPrime[1] = 1
def make():
for i in range(2, LIMIT + 1):
if minPrime[i] == 0:
minPrime[i] = i
# print(i)
for j in range(i + i, LIMIT + 1, i):
# print(i,j)
if minPrime[j] == 0:
minPrime[j] = i
make()
def factrial(N):
ret = []
while minPrime[N] != N:
ret.append(minPrime[N])
N = N // minPrime[N]
if N != 1:
ret.append(N)
return ret
judge = set([])
for e in a:
asf = set(factrial(e))
if judge & asf != set():
print("setwise coprime")
exit()
# judge |= asf
judge = judge | asf # too slow
print("pairwise coprime")
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s780796602 | Runtime Error | p02570 | Input is given from Standard Input in the following format:
D T S | n = int(input())
a = list(map(int, input().split()))
import sys
import math
def setwise_coprime(a):
ans = a[0]
for i in range(1, n):
ans = math.gcd(ans, a[i])
return ans
# エラストテネスのふるい
def create_sieve(n):
sieve = [0] * (n + 1)
for i in range(2, n + 1):
if sieve[i] == 0:
for j in range(i * i, n + 1, i):
sieve[j] = i
return sieve
# 高速素因数分解
def fast_factorization(n, sieve):
prime = {}
while n > 1:
p = sieve[n]
# nが素数の場合
if p == 0:
prime[n] = prime.get(n, 0) + 1
break
# nが素数ではない場合
else:
prime[p] = prime.get(p, 0) + 1
n = n // p
return prime
check = set()
if setwise_coprime(a) == 1:
# 素因数のダブリをcheck
sieve = create_sieve(10**6)
for i in range(n):
if a[i] != 1:
s = fast_factorization(a[i], sieve)
for i in s:
if i in check:
print("setwise coprime")
sys.exit()
else:
check.add(i)
print("pairwise coprime")
else:
print("not coprime")
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s295962585 | Wrong Answer | p02570 | Input is given from Standard Input in the following format:
D T S | (d, t, s) = tuple([int(x) for x in input().split(" ")])
print("YES" if d / s <= t else "NO")
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s176851074 | Accepted | p02570 | Input is given from Standard Input in the following format:
D T S | [D, T, S] = [int(_) for _ in input().split()]
print(["No", "Yes"][D <= T * S])
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s794035549 | Wrong Answer | p02570 | Input is given from Standard Input in the following format:
D T S | # 輸入字串並分隔,以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num = list(map(int, str_in.strip().split()))
# print(num) #D,T,S
# 若T<(D/S)->遲到
if num[1] > (num[0] / num[2]):
print(
"Yes\n\nIt takes",
num[0] / num[2],
"minutes to go",
num[0],
"meters to the place at a speed of",
num[2],
"meters per minute. They have planned to meet in",
num[1],
"minutes so he will arrive in time.",
)
elif num[1] == (num[0] / num[2]):
print(
"Yes\n\nIt takes",
num[0] / num[2],
"minutes to go ",
num[0],
"meters to the place at a speed of",
num[2],
"meters per minute. They have planned to meet in",
num[1],
"minutes so he will arrive just on time.",
)
else:
print("No\n\nHe will be late.")
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s576959198 | Runtime Error | p02570 | Input is given from Standard Input in the following format:
D T S | n, m = map(int, input().split())
li = []
ans = 0
if m != 0:
for i in range(m):
a, b = map(int, input().split())
if len(li) == 0:
li.append([a, b])
else:
flag = 0
for j in range(len(li)):
if a in li[j] and b not in li[j]:
li[j].append(b)
flag = 1
elif a not in li[j] and b in li[j]:
li[j].append(a)
flag = 1
elif a in li[j] and b in li[j]:
break
elif flag == 0 and j == len(li) - 1:
li.append([a, b])
# print(li)
ans = max([len(li[i]) for i in range(len(li))])
print(ans if m != 0 else 1)
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.
* * * | s481360980 | Runtime Error | p02570 | Input is given from Standard Input in the following format:
D T S | N = int(input())
A = list(map(int, input().split()))
sumA = sum(A) % (1000000007)
sumA2 = (sumA * sumA) % (1000000007)
square = 0
for i in range(N):
square += (A[i] ** 2) % (1000000007)
square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
buf = buf + (1000000007)
res = (buf * ((1000000007 + 1) // 2)) % 1000000007
print(round(res))
| Statement
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's
house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of
S meters per minute.
Will he arrive in time? | [{"input": "1000 15 80", "output": "Yes\n \n\nIt takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters\nper minute. They have planned to meet in 15 minutes so he will arrive in time.\n\n* * *"}, {"input": "2000 20 100", "output": "Yes\n \n\nIt takes 20 minutes to go 2000 meters to the place at a speed of 100 meters\nper minute. They have planned to meet in 20 minutes so he will arrive just on\ntime.\n\n* * *"}, {"input": "10000 1 1", "output": "No\n \n\nHe will be late."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.