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 minimum required number of buses.
* * * | s791517830 | Wrong Answer | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | if __name__ == "__main__":
N, C, K = [int(x) for x in input().split(" ")]
T = [int(input()) for _ in range(N)]
T.sort()
person_counts = 0
bus_counts = 0
for t in T:
if person_counts == 0:
first = t + K
person_counts += 1
if t > first:
bus_counts += 1
person_counts = 1
continue
if t == C - 1:
bus_counts += 1
person_counts = 0
continue
person_counts += 1
if person_counts > 0:
print(bus_counts + 1)
else:
print(bus_counts)
| Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s620190887 | Runtime Error | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | import math
n,c,k=map(int,input().split())
t=[0]*n
s=0
a=0
for i in range(n):
t[i]=int(input())
if i>0 and a>0:
if t[i]-t[i-1]<=k:
s+=(a+n)//c
a=(a+n)%c
else:
s+=math.ceil((a+n)/c)
a=0
print(s) | Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s569435343 | Runtime Error | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | n,c,k=[n,c,k=[int(i) for i in input().split()]
a=sorted([int(input()) for i in range(n)])
b=[i+k for i in a]
i0=[]
ans=0
bi=0
for i in range(n):
i0.append(a[i])
l=len(i0)
if l== c or (b[bi] < a[i] and i!=0) :
ans+=1
i0=[]
bi=i
if l != c and i==n-1:
ans+=1
print(ans) | Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s097580406 | Runtime Error | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | n, c, k = map(int, input().split())
T = [0]*n
for i in range(n):
T[i] = int(input())
T.sort()
ans = 0
jk = 0
t = T[0]
for i in range(n):
if T[i]-t>k:
ans += 1
jk = 0
t = T[i]
continue
jk += 1
if jk==c:
ans += 1
jk = 0
t = T[i]
print(ans if jk== else ans+1) | Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s580909730 | Runtime Error | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | import java.util.*
fun main(args: Array<String>) {
val sc = Scanner(System.`in`)
val n = sc.nextInt()
val c = sc.nextInt()
val k = sc.nextInt()
val t = Array(n) { sc.nextInt() }
var ans = 0
var waitStart = 0
var waitPeople = 0
for (ti in t.sorted()) {
if (ti - waitStart > k || waitPeople == c) {
waitPeople = 0
}
waitPeople++
if (waitPeople == 1) {
waitStart = ti
ans++
}
}
println(ans)
}
| Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s543842657 | Runtime Error | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | from collections import deque
N,C,K = map(int, input().split())
T_list = list() #左がもっとも早く着いた人
for i in range(N):
T = int(input())
T_list.append(T)
T_list.sort(reverse=False)
waiting_deque = deque(T_list)
ans = 0
while 1:
if len(waiting_deque) != 0:
ans += 1
bus_passenger = list()
bus_passenger.append(waiting_deque.popleft())
while 1:
if len(waiting_deque)!=0 and len(bus_passenger) < C and bus_passenger[0] + K => waiting_deque[0]:
bus_passenger.append(waiting_deque.popleft())
else:
#print(bus_passenger)
break
else:
break
print(ans) | Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s005300598 | Wrong Answer | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def roundUp(a, b):
return -(-a // b)
@staticmethod
def toUpperMultiple(a, x):
return Math.roundUp(a, x) * x
@staticmethod
def toLowerMultiple(a, x):
return (a // x) * x
@staticmethod
def nearPow2(n):
if n <= 0:
return 0
if n & (n - 1) == 0:
return n
ret = 1
while n > 0:
ret <<= 1
n >>= 1
return ret
@staticmethod
def sign(n):
if n == 0:
return 0
if n < 0:
return -1
return 1
@staticmethod
def isPrime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
class PriorityQueue:
def __init__(self, l=[]):
self.__q = l
heapq.heapify(self.__q)
return
def push(self, n):
heapq.heappush(self.__q, n)
return
def pop(self):
return heapq.heappop(self.__q)
MOD = int(1e09) + 7
INF = int(1e15)
def main():
# sys.stdin = open("sample.txt")
N, C, K = Scanner.map_int()
T = Scanner.int_cols_list(N)
T.sort()
S = [x + K for x in T]
ans = 0
cnt = 0
lim = 0
for i in range(N):
if cnt == 0:
lim = T[i] + K
elif lim < T[i]:
ans += 1
lim = T[i] + K
cnt += 1
if cnt == C:
ans += 1
cnt = 0
lim = 0
if lim > 0:
ans += 1
print(ans)
return
if __name__ == "__main__":
main()
| Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the minimum required number of buses.
* * * | s982142816 | Wrong Answer | p03785 | The input is given from Standard Input in the following format:
N C K
T_1
T_2
:
T_N | from copy import *
from sys import *
import math
import queue
from collections import defaultdict, Counter, deque
from fractions import Fraction as frac
setrecursionlimit(1000000)
# s[i] is linked with t[len(s)-i-1]
def main():
n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
print(t)
ans = 1
count = 1
first = t[0]
for i in t[1:]:
if count > c or first + k <= i:
ans += 1
count = 1
first = i
else:
count += 1
print(ans)
def zip(a):
mae = a[0]
ziparray = [mae]
for i in range(1, len(a)):
if mae != a[i]:
ziparray.append(a[i])
mae = a[i]
return ziparray
def is_prime(n):
if n < 2:
return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
def list_replace(n, f, t):
return [t if i == f else i for i in n]
def base_10_to_n(X, n):
X_dumy = X
out = ""
while X_dumy > 0:
out = str(X_dumy % n) + out
X_dumy = int(X_dumy / n)
if out == "":
return "0"
return out
def gcd(m, n):
x = max(m, n)
y = min(m, n)
while x % y != 0:
z = x % y
x = y
y = z
return y
class Queue:
def __init__(self):
self.q = deque([])
def push(self, i):
self.q.append(i)
def pop(self):
return self.q.popleft()
def size(self):
return len(self.q)
def debug(self):
return self.q
class Stack:
def __init__(self):
self.q = []
def push(self, i):
self.q.append(i)
def pop(self):
return self.q.pop()
def size(self):
return len(self.q)
def debug(self):
return self.q
class graph:
def __init__(self):
self.graph = defaultdict(list)
def addnode(self, l):
f, t = l[0], l[1]
self.graph[f].append(t)
self.graph[t].append(f)
def rmnode(self, l):
f, t = l[0], l[1]
self.graph[f].remove(t)
self.graph[t].remove(f)
def linked(self, f):
return self.graph[f]
class dgraph:
def __init__(self):
self.graph = defaultdict(set)
def addnode(self, l):
f, t = l[0], l[1]
self.graph[f].append(t)
def rmnode(self, l):
f, t = l[0], l[1]
self.graph[f].remove(t)
def linked(self, f):
return self.graph[f]
main()
| Statement
Every day, N passengers arrive at Takahashi Airport. The i-th passenger
arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each
bus can accommodate up to C passengers. Naturally, a passenger cannot take a
bus that departs earlier than the airplane arrives at the airport. Also, a
passenger will get angry if he/she is still unable to take a bus K units of
time after the arrival of the airplane. For that reason, it is necessary to
arrange buses so that the i-th passenger can take a bus departing at time
between T_i and T_i + K (inclusive).
When setting the departure times for buses under this condition, find the
minimum required number of buses. Here, the departure time for each bus does
not need to be an integer, and there may be multiple buses that depart at the
same time. | [{"input": "5 3 5\n 1\n 2\n 3\n 6\n 12", "output": "3\n \n\nFor example, the following three buses are enough:\n\n * A bus departing at time 4.5, that carries the passengers arriving at time 2 and 3.\n * A bus departing at time 6, that carries the passengers arriving at time 1 and 6.\n * A bus departing at time 12, that carries the passenger arriving at time 12.\n\n* * *"}, {"input": "6 3 3\n 7\n 6\n 2\n 8\n 10\n 6", "output": "3"}] |
Print the number of ways she can travel to the bottom-right cell, modulo
10^9+7.
* * * | s465858308 | Wrong Answer | p04040 | The input is given from Standard Input in the following format:
H W A B | H, W, A, B = map(int, input().split())
MOD = 10**9 + 7
def count_dr(d, r):
# H+WCW
cnt = 1
multiple_nums = list(range(d + r, d, -1))
divide_nums = list(range(1, r + 1))
for num in multiple_nums:
cnt *= num % MOD
for num in divide_nums:
cnt = cnt // num
return cnt
def zouka_combination(zouka, kotei, how_many):
tmp = count_dr(zouka, kotei)
# print(tmp)
# tmp_last = count_dr(a,w-b-1)
result = []
for i in range(1, how_many + 1):
numer = zouka + kotei + i
denom = zouka + i
tmp *= numer
tmp //= denom
result.append(tmp)
return result
exit = zouka_combination(H - A - 1, B - 1, A)
last = ([1] + zouka_combination(0, W - B - 1, A - 1))[::-1]
cnt = 0
for e, l in zip(exit, last):
cnt += e * l
cnt %= MOD
print(count_dr(H - 1, W - 1) - cnt)
| Statement
We have a large square grid with H rows and W columns. Iroha is now standing
in the top-left cell. She will repeat going right or down to the adjacent
cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows
and the leftmost B columns. (That is, there are A×B forbidden cells.) There is
no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 10^9+7. | [{"input": "2 3 1 1", "output": "2\n \n\nWe have a 2\u00d73 grid, but entering the bottom-left cell is forbidden. The number\nof ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\n* * *"}, {"input": "10 7 3 4", "output": "3570\n \n\nThere are 12 forbidden cells.\n\n* * *"}, {"input": "100000 100000 99999 99999", "output": "1\n \n\n* * *"}, {"input": "100000 100000 44444 55555", "output": "738162020"}] |
Print the number of ways she can travel to the bottom-right cell, modulo
10^9+7.
* * * | s827560202 | Accepted | p04040 | The input is given from Standard Input in the following format:
H W A B | # -*- coding: utf-8 -*-
# See:
# http://drken1215.hatenablog.com/entry/2018/06/08/210000
max_value = 500050
mod = 10**9 + 7
fac = [0 for _ in range(max_value)]
finv = [0 for _ in range(max_value)]
inv = [0 for _ in range(max_value)]
def com_init():
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, max_value):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def com(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
def main():
h, w, a, b = map(int, input().split())
x = h - (a + 1)
com_init()
prev = 0
ans = 0
com_xy = [0 for _ in range(w - b)]
com_za = [0 for _ in range(w - b)]
i = 0
j = 0
for y in range(b, w):
com_xy[i] = com(x + y, y)
i += 1
for z in range((w - (b + 1) + a), a - 1, -1):
com_za[j] = com(z, z - a)
j += 1
for xy, za in zip(com_xy, com_za):
ans += (xy - prev) * za
ans %= mod
prev = xy
print(ans)
if __name__ == "__main__":
main()
| Statement
We have a large square grid with H rows and W columns. Iroha is now standing
in the top-left cell. She will repeat going right or down to the adjacent
cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows
and the leftmost B columns. (That is, there are A×B forbidden cells.) There is
no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 10^9+7. | [{"input": "2 3 1 1", "output": "2\n \n\nWe have a 2\u00d73 grid, but entering the bottom-left cell is forbidden. The number\nof ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\n* * *"}, {"input": "10 7 3 4", "output": "3570\n \n\nThere are 12 forbidden cells.\n\n* * *"}, {"input": "100000 100000 99999 99999", "output": "1\n \n\n* * *"}, {"input": "100000 100000 44444 55555", "output": "738162020"}] |
Print the number of ways she can travel to the bottom-right cell, modulo
10^9+7.
* * * | s427730148 | Accepted | p04040 | The input is given from Standard Input in the following format:
H W A B | class Combinatorics:
def __init__(self, N, mod):
"""
Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
over the finite field Z/(mod)Z.
Input:
N (int): maximum n
mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
"""
self.mod = mod
self.fact = {i: None for i in range(N + 1)} # n!
self.inverse = {
i: None for i in range(1, N + 1)
} # inverse of n in the field Z/(MOD)Z
self.fact_inverse = {
i: None for i in range(N + 1)
} # inverse of n! in the field Z/(MOD)Z
# preprocess
self.fact[0] = self.fact[1] = 1
self.fact_inverse[0] = self.fact_inverse[1] = 1
self.inverse[1] = 1
for i in range(2, N + 1):
self.fact[i] = i * self.fact[i - 1] % self.mod
q, r = divmod(self.mod, i)
self.inverse[i] = (-(q % self.mod) * self.inverse[r]) % self.mod
self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i - 1] % self.mod
def perm(self, n, r):
"""
Calculate nPr = n! / (n-r)! % mod
"""
if n < r or n < 0 or r < 0:
return 0
else:
return (self.fact[n] * self.fact_inverse[n - r]) % self.mod
def binom(self, n, r):
"""
Calculate nCr = n! /(r! (n-r)!) % mod
"""
if n < r or n < 0 or r < 0:
return 0
else:
return (
self.fact[n]
* (self.fact_inverse[r] * self.fact_inverse[n - r] % self.mod)
% self.mod
)
def hom(self, n, r):
"""
Calculate nHr = {n+r-1}Cr % mod.
Assign r objects to one of n classes.
Arrangement of r circles and n-1 partitions:
o o o | o o | | | o | | | o o | | o
"""
if n == 0 and r > 0:
return 0
if n >= 0 and r == 0:
return 1
return self.binom(n + r - 1, r)
H, W, A, B = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(H + W, MOD)
ans = com.binom(H - 1 + W - 1, H - 1)
for j in range(B):
ans = (
ans - com.binom(H - A - 1 + j, j) * com.binom(A - 1 + W - j - 1, A - 1)
) % MOD
print(ans)
| Statement
We have a large square grid with H rows and W columns. Iroha is now standing
in the top-left cell. She will repeat going right or down to the adjacent
cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows
and the leftmost B columns. (That is, there are A×B forbidden cells.) There is
no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 10^9+7. | [{"input": "2 3 1 1", "output": "2\n \n\nWe have a 2\u00d73 grid, but entering the bottom-left cell is forbidden. The number\nof ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\n* * *"}, {"input": "10 7 3 4", "output": "3570\n \n\nThere are 12 forbidden cells.\n\n* * *"}, {"input": "100000 100000 99999 99999", "output": "1\n \n\n* * *"}, {"input": "100000 100000 44444 55555", "output": "738162020"}] |
Print the number of ways she can travel to the bottom-right cell, modulo
10^9+7.
* * * | s579071339 | Accepted | p04040 | The input is given from Standard Input in the following format:
H W A B | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li():
return map(int, stdin.readline().split())
def li_():
return map(lambda x: int(x) - 1, stdin.readline().split())
def lf():
return map(float, stdin.readline().split())
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
# nの逆元のリスト
def inv_mod(n: int, mod: int) -> list:
inv = [0, 1]
for i in range(2, n + 1):
inv.append(mod - ((mod // i) * inv[mod % i]) % mod)
return inv
# nの階乗のリスト
def fact(n: int, mod: int) -> list:
fac = [1, 1]
res = 1
for i in range(2, n + 1):
res = res * i % mod
fac.append(res)
return fac
# nの階乗の逆元のリスト
def fact_inv(n: int, inv: list, mod: int) -> list:
facInv = [1, 1]
for i in range(2, n + 1):
facInv.append(facInv[i - 1] * inv[i] % mod)
return facInv
# 二項係数
def nCr(n: int, r: int, mod: int, fac: list, facInv: list) -> int:
if not (0 <= r and r <= n):
return 0
return ((fac[n] * facInv[r]) % mod) * facInv[n - r] % mod
def get_gates(h, w, a, b):
i = 0
gates = []
while h - a - 1 - i >= 0 and b + i < w:
gates.append((h - a - 1 - i, b + i))
i += 1
return gates
h, w, a, b = li()
MOD = 10**9 + 7
gates = get_gates(h, w, a, b)
inv = inv_mod(h + w, MOD)
fac = fact(h + w, MOD)
facInv = fact_inv(h + w, inv, MOD)
ans = 0
for ri, ci in gates:
ans += nCr(ri + ci, ci, MOD, fac, facInv) * nCr(
h + w - 2 - (ri + ci), w - 1 - ci, MOD, fac, facInv
)
ans %= MOD
print(ans)
| Statement
We have a large square grid with H rows and W columns. Iroha is now standing
in the top-left cell. She will repeat going right or down to the adjacent
cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows
and the leftmost B columns. (That is, there are A×B forbidden cells.) There is
no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 10^9+7. | [{"input": "2 3 1 1", "output": "2\n \n\nWe have a 2\u00d73 grid, but entering the bottom-left cell is forbidden. The number\nof ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\n* * *"}, {"input": "10 7 3 4", "output": "3570\n \n\nThere are 12 forbidden cells.\n\n* * *"}, {"input": "100000 100000 99999 99999", "output": "1\n \n\n* * *"}, {"input": "100000 100000 44444 55555", "output": "738162020"}] |
Print the number of ways she can travel to the bottom-right cell, modulo
10^9+7.
* * * | s960411071 | Accepted | p04040 | The input is given from Standard Input in the following format:
H W A B | MOD = 1000000007
H, W, A, B = map(int, input().split())
if H - A > W - B:
H, W = W, H
A, B = B, A
# print(H, W, A, B)
ans1 = [1]
for i in range(H - A - 1):
# print(ans1)
ans1.append((ans1[-1] * (H - A - 1 + B - i) * pow(i + 1, MOD - 2, MOD)) % MOD)
# print(ans1)
c = 1
for i in range(W - H + A - B):
c = (c * (W - B - 1 + A - i) * pow(i + 1, MOD - 2, MOD)) % MOD
ans = c
for i in range(H - A - 1):
# print(ans)
c = (c * (H - 1 - i) * pow(W - H + A - B + 1 + i, MOD - 2, MOD)) % MOD
ans = (ans + c * ans1[i + 1]) % MOD
print(ans)
| Statement
We have a large square grid with H rows and W columns. Iroha is now standing
in the top-left cell. She will repeat going right or down to the adjacent
cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows
and the leftmost B columns. (That is, there are A×B forbidden cells.) There is
no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 10^9+7. | [{"input": "2 3 1 1", "output": "2\n \n\nWe have a 2\u00d73 grid, but entering the bottom-left cell is forbidden. The number\nof ways to travel is two: \"Right, Right, Down\" and \"Right, Down, Right\".\n\n* * *"}, {"input": "10 7 3 4", "output": "3570\n \n\nThere are 12 forbidden cells.\n\n* * *"}, {"input": "100000 100000 99999 99999", "output": "1\n \n\n* * *"}, {"input": "100000 100000 44444 55555", "output": "738162020"}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s268507876 | Runtime Error | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | n, s = map(int, input().split())
q = [list(map(int, input().split())) for i in range(n)]
import numpy as np
import copy
dt = [0] * n
cp = [0] * n
ck = [0] * n
for i in range(n):
dt[i] = 100 * (i + 1) + q[i][1] // q[i][0]
cp[i] = 100 * (i + 1) * q[i][0] + q[i][1]
score = sum(cp)
cnt = np.sum(q, axis=0)[0]
for i in range(n):
id = np.argmin(dt)
score -= cp[id]
cnt -= q[id][0]
dt[id] = 999999999
ck[id] = i + 1
if score <= s:
break
cnt1 = 999
for i in range(n):
if dt[i] == 999999999:
if cp[i] + score >= s:
cnt1 = min(cnt1, q[i][0])
res1 = cnt + cnt1
for i in range(n):
if ck[n - 1 - i] > 0:
id2 = n - 1 - i
break
for i in range(q[id2][0]):
score += (id2 + 1) * 100
if score >= s:
res2 = cnt + i + 1
break
print(min(res1, res2))
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s886919796 | Runtime Error | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | from sys import exit
n, m, x = map(int, input().split())
c = [0] * n
a = []
for i in range(n):
ca = list(map(int, input().split()))
c[i] = ca[0]
a.append(ca[1:])
ave = [[0, i] for i in range(n)]
for i in range(m):
p = 0
for j in range(n):
p += a[j][i]
ave[j][0] += a[j][i] / m
if p < x:
print(-1)
exit()
for i in range(n):
ave[i][0] = c[i] / ave[i][0]
ave.sort()
ans = 0
now = [0] * m
for i in range(n):
for j in range(m):
now[j] += a[ave[i][1]][j]
ans += c[ave[i][1]]
for j in range(m):
f = True
if now[j] < x:
f = False
break
if f:
print(ans)
exit()
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s849447786 | Accepted | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | from itertools import product
max2 = lambda x, y: x if x > y else y
min2 = lambda x, y: x if x < y else y
D, G = map(int, input().split())
pc = [tuple(map(int, input().split())) for _ in range(D)]
pc = [(p, c, 100 * i) for i, (p, c) in enumerate(pc, start=1)]
res = sum(p for p, c, k in pc)
for choice in product((True, False), repeat=D):
t = sum(c + p * k for (p, c, k), f in zip(pc, choice) if f)
steps = sum(p for (p, c, k), f in zip(pc, choice) if f)
if t >= G:
res = min2(res, steps)
continue
for (p, c, k), f in zip(reversed(pc), reversed(choice)):
if not f:
break
if p * k + t >= G:
steps += (G - t - 1) // k + 1
res = min2(res, steps)
print(res)
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s961197256 | Accepted | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | # -*- coding: utf-8 -*-
import itertools
D, G = map(int, input().split())
pi = []
ci = []
score_i_c = []
score_i_h = []
for i in range(D):
p_t, c_t = map(int, input().split())
pi.append(p_t)
ci.append(c_t)
tmp = p_t * 100 * (i + 1) + c_t
score_i_c.append((i, tmp, p_t))
tmp = (p_t - 1) * 100 * (i + 1)
score_i_h.append((i, tmp, p_t))
# 完全に解かなくても行ける場合
step1_list = []
for i, score, num in score_i_h:
if score >= G:
step1_list.append((i, score, num))
ans_list = []
if len(step1_list) > 0:
min_i, _, _ = step1_list[-1]
for i, score, num in step1_list:
tmp_score = 0
tmp_num = 0
for i in range(pi[min_i]):
if tmp_score >= G:
break
else:
tmp_score += (min_i + 1) * 100
tmp_num += 1
ans_list.append(tmp_num)
# 完全に解くケース
step1_list = []
for i in range(D):
tmp = itertools.combinations(score_i_c, i + 1)
step1_list.extend(list(tmp))
# 合計がGを超える組み合わせを抽出
sum_list = []
for l in step1_list:
numbers = []
sum_score = 0
sum_num = 0
for i, score, num in l:
numbers.append(i)
sum_score += score
sum_num += num
if sum_score >= G:
sum_list.append((numbers, sum_score, sum_num))
#
# print(step1_list)
# print(sum_list)
# min_numbers = []
# min_score = 0
# min_num = 10000
# for i,score,num in sum_list:
# if num < min_num:
# min_numbers = i
# min_score = score
# min_num = num
# print(min_numbers,min_score,min_num)
# min_i = min_numbers[-1]
for min_numbers, min_score, min_num in sum_list:
for min_i in min_numbers:
tmp_score = min_score - score_i_c[min_i][1]
tmp_num = min_num - score_i_c[min_i][2]
for i in range(pi[min_i]):
if tmp_score >= G:
break
tmp_score += (min_i + 1) * 100
tmp_num += 1
ans_list.append(tmp_num)
# print(ans_list)
print(min(ans_list))
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s504042128 | Accepted | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list(map(lambda x: int(x) - 1, stdin.readline().split()))
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
# A
def A():
return
# B
def B():
return
# C
def C():
d, g = LI()
pc = LIR(d)
ans = float("INF")
tokumono = list(itertools.product((0, 1), repeat=d))
# print(tokumono)
for toku in tokumono:
# print(toku)
ansa = 0
ansb = 0
for i in range(len(toku)):
if toku[i] == 1:
ansa += pc[i][0]
ansb += pc[i][0] * (i + 1) * 100 + pc[i][1]
for k in range(len(toku) - 1, -1, -1):
if toku[k] == 0:
for i in range(pc[k][0] + 1):
# print(ans, ansb, ansa)
if i == pc[k][0]:
ansb += pc[k][1]
if ansb >= g:
ans = min(ans, ansa)
break
ansa += 1
ansb += (k + 1) * 100
break
print(ans)
return
# D
def D():
N, X = LI()
def dfs(n, x):
# print(n, x)
if x == 1 and n > 0:
return 0
elif x < 2 ** (n + 1) - 1:
return dfs(n - 1, x - 1)
elif x == 2 ** (n + 1) - 1:
return 2**n
elif x == 2 ** (n + 2) - 3:
return 2 ** (n + 1) - 1
else:
return dfs(n - 1, x - 2 ** (n + 1) + 1) + 2**n
a = dfs(N, X)
print(a)
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
C()
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s246414257 | Accepted | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | import sys
from collections import deque
import copy
sys.setrecursionlimit(4100000)
def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def solve(D, G, inputs):
problems = list(map(string_to_int, inputs))
binary_max = 2 ** len(problems)
min_num = -1
for pattern in range(0, binary_max):
binary_pattern = bin(pattern)[2:]
while len(binary_pattern) != D:
binary_pattern = "0" + binary_pattern
incompleted_problem = -1
count_num = 0
count_score = 0
for i in reversed(range(len(binary_pattern))):
if binary_pattern[i] == "1":
count_num += problems[i][0]
count_score += (100 * (i + 1)) * problems[i][0] + problems[i][1]
elif incompleted_problem == -1 and binary_pattern[i] == "0":
incompleted_problem = i
if incompleted_problem != -1:
for _ in range(problems[incompleted_problem][0]):
if count_score >= G:
break
count_num += 1
count_score += 100 * (incompleted_problem + 1)
if count_score >= G and (min_num == -1 or count_num < min_num):
min_num = count_num
return min_num
def string_to_int(string):
return list(map(int, string.split()))
if __name__ == "__main__":
[D, G] = string_to_int(input())
ret = solve(D, G, inputs(D))
print(ret)
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s997514349 | Wrong Answer | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | D, G = map(int, input().split())
p = [] # 各点数台の問題数のリスト
c = [] # 各点数台のコンプリートボーナス
# 各点数台を、完全に解くかどうかのリスト 1問も解かないとして初期化
solve_completely_list = [False] * D
# 入力処理
for d in range(D):
p_i, c_i = map(int, input().split())
p.append(p_i)
c.append(c_i)
def dfs(i, solve_completely_list, completed_amount_list):
if i >= D:
is_larger_than_G = False # フラグ初期化
# total_score計算
total_score = 0
completed_amount = 0
for d in range(D):
if solve_completely_list[d]:
total_score += (d + 1) * 100 * p[d] + c[d]
completed_amount += p[d]
# total_scoreがGより小さいとき
# Gより大きくなるまで、一番大きい配点を足す
# 一番大きい配点をp-1個足してもGより小さい場合、諦めて他の枝に移る
if total_score < G:
# solve_completely_list[D]がTrueのときは、(D-1) * 100を最大の配点とする
# solve_completely_list[i]がFalseであるiのうち最大のiの配点を使う
max_d = -1
for i in reversed(range(D)):
if solve_completely_list[i] == False:
max_d = i
break
# 多分ありえないけど一応
if max_d == -1:
return
for p_d in range(p[max_d - 1] - 1):
total_score += max_d * 100
completed_amount += 1
if total_score >= G:
is_larger_than_G = True
break
else:
is_larger_than_G = True
if is_larger_than_G:
completed_amount_list.append(completed_amount)
return
# 完全に解く(100i 点の問題を pi 問解く)場合
solve_completely_list[i] = True
dfs(i + 1, solve_completely_list, completed_amount_list)
# 1問も解かない場合
solve_completely_list[i] = False
dfs(i + 1, solve_completely_list, completed_amount_list)
completed_amount_list = [] # 回答した数のリスト
dfs(0, solve_completely_list, completed_amount_list)
print(min(completed_amount_list))
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s926759134 | Wrong Answer | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | d, g = map(int, input().split())
k = [list(map(int, input().split())) for i in range(d)]
x = 0
y = 0
z = 0
xcount = 0
# 大きいものから順番に
for v in range(d, 0, -1):
for i in range(1, k[v - 1][0] + 1):
x += 100 * v
if i == k[v - 1][0]:
x += k[v - 1][1]
xcount += 1
if x >= g:
break
else:
continue
break
# print(xcount)
# ボーナスこみでpiだけで賄えるものも個数が最小のもの
m = []
n = []
for j in range(d):
m.append(100 * (j + 1) * k[j][0] + k[j][1])
n.append(k[j][0])
p = []
q = []
r = []
for j in range(len(m)):
if m[j] >= g:
p.append(n[j])
else:
q.append(m[j])
r.append(n[j])
if p != []:
ycount = min(p)
else:
ycount = 1001
# print(ycount)
# ボーナスこみでpiだけで賄えないものと大きいのを足した個数が最小のもの
zcount = 0
add = 0
zar = []
addar = []
h = d - 1
proh = 0
R = sum(r)
hiku = 0
arc = [0 for i in range(d)]
for j in range(len(q)):
add = q[j]
comp = q[j]
for w in range(1, R + 1):
for u in range(len(q)):
# qaz = w - hiku
if h == j:
h -= 1
if (
w == r[u] and j != u
): # 満タンにぴったり一致するときボーナス分と今までと最大のやつを比較
if add + 100 * (h + 1) - comp < q[u]: # 100 * w * (h + 1)
addar.append(q[u])
if h == u:
proh = 1
# 100 * d * (w - 1 - pom[pomcount])
# pom.append(w - 1)
# pomcount += 1
if u == len(q) - 1 and addar != []:
add = add + max(addar) - (add - comp) # + q[j]
# comp = add
arc[q.index(max(addar))] += 1
arc = [0 for i in range(d)]
arc[q.index(max(addar))] = w
for m in range(len(q)):
if arc[m] < k[m][0] and m != j:
h = m
if u == len(q) - 1 and addar == []:
add += 100 * (h + 1)
arc[h] += 1
zcount += 1
if arc[h] == k[h][0]:
hiku += arc[h]
if proh == 0:
add += k[h][1]
h -= 1
if h == j:
h -= 1
proh = 0
addar = []
if add >= g:
zar.append(zcount + r[j])
zcount = 0
h = d - 1
arc = [0 for i in range(d)]
comp = 0
hiku = 0
break
if zar != []:
coz = min(zar)
else:
coz = 1001
# print(coz)
print(min(xcount, ycount, coz))
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the minimum number of problems that needs to be solved in order to have
a total score of G or more points. Note that this objective is always
achievable (see Constraints).
* * * | s845572661 | Accepted | p03290 | Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D | n, g = map(int, input().split())
standard = []
bonus = []
num_of_problems = []
for i in range(n):
a, b = map(int, input().split())
standard.append(a * (i + 1) * 100)
bonus.append(b)
num_of_problems.append(a)
points_after_completion = []
min_num = 10 * 100
for i in range(2**n):
point = 0
num = 0
li = list(range(n))
for j in range(n):
if (i >> j) & 1:
point += standard[n - j - 1] + bonus[n - j - 1]
num += num_of_problems[n - j - 1]
li.remove(n - j - 1)
counter = 0
if li != []:
while point < g and counter <= num_of_problems[li[-1]]:
point += 100 * (li[-1] + 1)
num += 1
counter += 1
if num < min_num and point >= g:
min_num = num
print(min_num)
| Statement
A programming competition site _AtCode_ provides algorithmic problems. Each
problem is allocated a score based on its difficulty. Currently, for each
integer i between 1 and D (inclusive), there are p_i problems with a score of
100i points. These p_1 + … + p_D problems are all of the problems available on
AtCode.
A user of AtCode has a value called _total score_. The total score of a user
is the sum of the following two elements:
* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem. His
objective is to have a total score of G or more points. At least how many
problems does he need to solve for this objective? | [{"input": "2 700\n 3 500\n 5 800", "output": "3\n \n\nIn this case, there are three problems each with 100 points and five problems\neach with 200 points. The perfect bonus for solving all the 100-point problems\nis 500 points, and the perfect bonus for solving all the 200-point problems is\n800 points. Takahashi's objective is to have a total score of 700 points or\nmore.\n\nOne way to achieve this objective is to solve four 200-point problems and earn\na base score of 800 points. However, if we solve three 100-point problems, we\ncan earn the perfect bonus of 500 points in addition to the base score of 300\npoints, for a total score of 800 points, and we can achieve the objective with\nfewer problems.\n\n* * *"}, {"input": "2 2000\n 3 500\n 5 800", "output": "7\n \n\nThis case is similar to Sample Input 1, but the Takahashi's objective this\ntime is 2000 points or more. In this case, we inevitably need to solve all\nfive 200-point problems, and by solving two 100-point problems additionally we\nhave the total score of 2000 points.\n\n* * *"}, {"input": "2 400\n 3 500\n 5 800", "output": "2\n \n\nThis case is again similar to Sample Input 1, but the Takahashi's objective\nthis time is 400 points or more. In this case, we only need to solve two\n200-point problems to achieve the objective.\n\n* * *"}, {"input": "5 25000\n 20 1000\n 40 1000\n 50 1000\n 30 1000\n 1 1000", "output": "66\n \n\nThere is only one 500-point problem, but the perfect bonus can be earned even\nin such a case."}] |
Print the number of ways to move the pieces to achieve our objective, modulo
998244353.
* * * | s503698236 | Wrong Answer | p02878 | Input is given from Standard Input in the following format:
N A B | # F
| Statement
We have two indistinguishable pieces placed on a number line. Both pieces are
initially at coordinate 0. (They can occupy the same position.)
We can do the following two kinds of operations:
* Choose a piece and move it to the right (the positive direction) by 1.
* Move the piece with the smaller coordinate to the position of the piece with the greater coordinate. If two pieces already occupy the same position, nothing happens, but it still counts as doing one operation.
We want to do a total of N operations of these kinds in some order so that one
of the pieces will be at coordinate A and the other at coordinate B. Find the
number of ways to move the pieces to achieve it. The answer can be enormous,
so compute the count modulo 998244353.
Two ways to move the pieces are considered different if and only if there
exists an integer i (1 \leq i \leq N) such that the set of the coordinates
occupied by the pieces after the i-th operation is different in those two
ways. | [{"input": "5 1 3", "output": "4\n \n\nShown below are the four ways to move the pieces, where (x,y) represents the\nstate where the two pieces are at coordinates x and y.\n\n * (0,0)\u2192(0,0)\u2192(0,1)\u2192(0,2)\u2192(0,3)\u2192(1,3)\n * (0,0)\u2192(0,0)\u2192(0,1)\u2192(0,2)\u2192(1,2)\u2192(1,3)\n * (0,0)\u2192(0,0)\u2192(0,1)\u2192(1,1)\u2192(1,2)\u2192(1,3)\n * (0,0)\u2192(0,1)\u2192(1,1)\u2192(1,1)\u2192(1,2)\u2192(1,3)\n\n* * *"}, {"input": "10 0 0", "output": "1\n \n\n* * *"}, {"input": "10 4 6", "output": "197\n \n\n* * *"}, {"input": "1000000 100000 200000", "output": "758840509"}] |
Print the number of ways to move the pieces to achieve our objective, modulo
998244353.
* * * | s663251020 | Runtime Error | p02878 | Input is given from Standard Input in the following format:
N A B | def inc(a, b, inc_a, a_max, b_max, n, n_max):
cnt = 0
n += 1
if inc_a:
a += 1
else:
b += 1
if a == a_max and b == b_max and n == n_max:
return 1
if a > b or a > a_max or b > b_max or n > n_max:
return 0
cnt += inc(a, b, True, a_max, b_max, n, n_max)
cnt += inc(a, b, False, a_max, b_max, n, n_max)
cnt += same(a, b, a_max, b_max, n, n_max)
return cnt
def same(a, b, a_max, b_max, n, n_max):
if b - a == 1:
return 0
cnt = 0
n += 1
a = b
if a == a_max and b == b_max and n == n_max:
return 1
if a > b or a > a_max or b > b_max or n > n_max:
return 0
cnt += inc(a, b, True, a_max, b_max, n, n_max)
cnt += inc(a, b, False, a_max, b_max, n, n_max)
cnt += same(a, b, a_max, b_max, n, n_max)
return cnt
if __name__ == "__main__":
n_max, a_max, b_max = list(map(int, input().split()))
n = 0
a = 0
b = 0
cnt = 0
cnt += inc(a, b, False, a_max, b_max, n, n_max)
cnt += same(a, b, a_max, b_max, n, n_max)
print(cnt)
| Statement
We have two indistinguishable pieces placed on a number line. Both pieces are
initially at coordinate 0. (They can occupy the same position.)
We can do the following two kinds of operations:
* Choose a piece and move it to the right (the positive direction) by 1.
* Move the piece with the smaller coordinate to the position of the piece with the greater coordinate. If two pieces already occupy the same position, nothing happens, but it still counts as doing one operation.
We want to do a total of N operations of these kinds in some order so that one
of the pieces will be at coordinate A and the other at coordinate B. Find the
number of ways to move the pieces to achieve it. The answer can be enormous,
so compute the count modulo 998244353.
Two ways to move the pieces are considered different if and only if there
exists an integer i (1 \leq i \leq N) such that the set of the coordinates
occupied by the pieces after the i-th operation is different in those two
ways. | [{"input": "5 1 3", "output": "4\n \n\nShown below are the four ways to move the pieces, where (x,y) represents the\nstate where the two pieces are at coordinates x and y.\n\n * (0,0)\u2192(0,0)\u2192(0,1)\u2192(0,2)\u2192(0,3)\u2192(1,3)\n * (0,0)\u2192(0,0)\u2192(0,1)\u2192(0,2)\u2192(1,2)\u2192(1,3)\n * (0,0)\u2192(0,0)\u2192(0,1)\u2192(1,1)\u2192(1,2)\u2192(1,3)\n * (0,0)\u2192(0,1)\u2192(1,1)\u2192(1,1)\u2192(1,2)\u2192(1,3)\n\n* * *"}, {"input": "10 0 0", "output": "1\n \n\n* * *"}, {"input": "10 4 6", "output": "197\n \n\n* * *"}, {"input": "1000000 100000 200000", "output": "758840509"}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s826755133 | Accepted | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | N, M = map(int, (input().split()))
n = [0] * (N + 1)
for i in range(M):
n[int(input())] = True
f = [1]
for i in range(1, N + 1):
if n[i]:
f.append(0)
elif i == 1:
f.append(f[0])
else:
f.append((f[i - 1] + f[i - 2]) % (10**9 + 7))
print(f[N])
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s374501557 | Accepted | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def solve(inputs):
[N, M] = list(map(lambda x: int(x), inputs[0].split()))
broke_steps = {}
for b in map(lambda x: int(x), inputs[1:]):
broke_steps[b] = True
SSSS = 1000000007
patterns = [1]
for step in range(1, N + 1):
if step in broke_steps:
ap = 0
elif step == 1:
ap = 1
else:
ap = (patterns[step - 1] + patterns[step - 2]) % SSSS
patterns.append(ap)
return patterns[-1]
if __name__ == "__main__":
first = input()
[N, M] = list(map(lambda x: int(x), first.split()))
inputs_str = inputs(M)
inputs_str.insert(0, first)
ret = solve(inputs_str)
print(ret)
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s885827220 | Wrong Answer | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | print("test")
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s083204980 | Runtime Error | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | import sys
input = sys.stdin.buffer.readline
def main(arg):
# print(arg)
input = arg.split("\n")
N, M = list(map(int, input.pop(0).split(" ")))
print(input)
# return
A = list(map(int, input))
# print(N)
# print(M)
print(A)
# return
if len(A) > 1:
for i in range(1, M):
if A[i] - A[i - 1] == 1:
print(0)
return
dp = [0] * (N - M + 1)
dp[0] = 1
for i in range(1, N - M + 1):
dp1 = dp[i - 1] % 1000000007
dp2 = 0
if i >= 2:
dp2 = (dp[i - 2] * 2) % 1000000007
print("i={0}: dp1={1}, dp2={2}".format(i, dp1, dp2))
dp[i] = max(dp1, dp2)
print(dp[N - M])
# main("6 1\n3")
main(input())
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s120274772 | Runtime Error | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | import sys
inputs = sys.stdin.readline
def main():
ans = 1
a = 0
b = 0
flg2 = 0
N, M = map(int, inputs().split())
A = [0] * (M + 1)
for i in range(M):
a = int(inputs())
A[i] = a - 1 - b
b = a + 1
A[M] = N - b
A.sort()
if A[0] < 0:
print(0)
flg2 = 1
p = 1
q = 1
t = 0
flg = 0
while A[t] < 2:
t = t + 1
if t > M:
print(0)
flg2 = 1
for k in range(2, N + 1):
r = p + q
p = q
q = r
while A[t] == k:
ans = ans * r % 1000000007
t += 1
if t == M + 1:
flg = 1
break
if flg == 1:
break
if flg2 == 0:
print(ans % 1000000007)
main()
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s680702240 | Accepted | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | N, M = list(map(int, input().split()))
A = []
S = [0 for i in range(N + 1)]
S[0] = 1
for i in range(M):
s = int(input())
A.append(s)
S[s] = -1
for i in range(N + 1):
if S[i] == -1:
continue
if i + 1 <= N:
if S[i + 1] == 0:
S[i + 1] = S[i]
elif S[i + 1] > 0:
S[i + 1] += S[i]
if i + 2 <= N:
if S[i + 2] == 0:
S[i + 2] = S[i]
elif S[i + 2] > 0:
S[i + 2] += S[i]
print(S[-1] % 1000000007)
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s500198012 | Accepted | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | ll = lambda: list(map(int, input().split()))
testcases = 1
def abs(x):
if x < 0:
return -x
return x
# testcases = int(input())
for testcase in range(testcases):
[n, m] = ll()
broken = [1] * (n + 1)
for i in range(m):
[ai] = ll()
broken[ai] = 0
ans = [0] * (n + 1)
ans[0] = 1
ans[1] = 1 * broken[1]
for i in range(2, n + 1):
ans[i] = (ans[i - 1] * broken[i] + ans[i - 2] * broken[i]) % (10**9 + 7)
# print(ans)
print(ans[n])
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s258749204 | Runtime Error | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | n, m = map(int, input().split())
ali = [int(input()) for _ in range(m)]
dif = []
cap = 0
for num in ali:
dif.append(num - cap)
cap = num
dif.append(n - cap + 1)
dif[0] += 1
ref = [0, 0, 1, 1]
a, b = 1, 1
for i in range(1000):
a, b = b, a + b
ref.append(b)
ans = 1
for num in dif:
ans *= ref[num]
print(ans % 1000000007)
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s070597879 | Accepted | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y):
return pow(x, y, MOD)
def INV(x, m=MOD):
return pow(x, m - 2, m)
def DIV(x, y, m=MOD):
return (x * INV(y, m)) % m
def LI():
return [int(x) for x in input().split()]
def LF():
return [float(x) for x in input().split()]
def LS():
return input().split()
def II():
return int(input())
N, M = LI()
st = set()
for i in range(M):
st.add(int(input()))
pat1 = 1
pat2 = 0
for i in range(1, N):
tmp = pat2
pat2 = pat1
pat1 = ((pat1 + tmp) % MOD) if not i in st else 0
# print('pat1: {} pat2: {} i:{}'.format(pat1, pat2, i))
print((pat1 + pat2) % MOD)
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s247806666 | Runtime Error | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | CONST = 1000000007
n, m = map(int, input().split())
a_list = [int(input()) for _ in range(m)]
index = 1
prev_p, p = 1, 1
while index < n:
if index == 1:
if index in a_list:
p = 0
pass
elif index in a_list:
prev_p = p
p = 0
if index + 1 in a_list:
pp = 0
break
else:
prev_p = p
p = (p + pp) % CONST
pp = prev_p
index += 1
print((pp + p) % CONST)
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the number of ways to climb up the stairs under the condition, modulo 1\
000\ 000\ 007.
* * * | s235780104 | Runtime Error | p03013 | Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M | class MyClass:
patternCount = 0
def skip(self, maxNum, currentIndex):
if currentIndex >= maxNum or currentIndex in brokenIndexList:
return
if maxNum - 1 == currentIndex:
self.patternCount += 1
return
self.skip(maxNum, currentIndex + 1)
self.skip(maxNum, currentIndex + 2)
maxNum, brokenCount = map(int, input().split())
brokenIndexList = []
for i in range(brokenCount):
brokenIndexList.append(int(input()))
if maxNum == 0:
print(0)
c = MyClass()
c.skip(maxNum, -1)
print(c.patternCount)
| Statement
There is a staircase with N steps. Takahashi is now standing at the foot of
the stairs, that is, on the 0-th step. He can climb up one or two steps at a
time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are
broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step,
without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\
007. | [{"input": "6 1\n 3", "output": "4\n \n\nThere are four ways to climb up the stairs, as follows:\n\n * 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 1 \\to 2 \\to 4 \\to 6\n * 0 \\to 2 \\to 4 \\to 5 \\to 6\n * 0 \\to 2 \\to 4 \\to 6\n\n* * *"}, {"input": "10 2\n 4\n 5", "output": "0\n \n\nThere may be no way to climb up the stairs without setting foot on the broken\nsteps.\n\n* * *"}, {"input": "100 5\n 1\n 23\n 45\n 67\n 89", "output": "608200469\n \n\nBe sure to print the count modulo 1\\ 000\\ 000\\ 007."}] |
Print the answer in N-K lines.
The i-th line should contain `Yes` if the grade for the (K+i)-th term is
greater than the grade for the (K+i-1)-th term, and `No` otherwise.
* * * | s260182000 | Accepted | p02602 | Input is given from Standard Input in the following format:
N K
A_1 A_2 A_3 \ldots A_N | 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**19
MOD = 10**9 + 7
EPS = 10**-10
N, K = MAP()
A = LIST()
for i in range(K, N):
if A[i] > A[i - K]:
Yes()
else:
No()
| Statement
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those
exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms: not given.
* For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.
M-kun scored A_i in the exam at the end of the i-th term.
For each i such that K+1 \leq i \leq N, determine whether his grade for the
i-th term is **strictly** greater than the grade for the (i-1)-th term. | [{"input": "5 3\n 96 98 95 100 20", "output": "Yes\n No\n \n\nHis grade for each term is computed as follows:\n\n * 3-rd term: (96 \\times 98 \\times 95) = 893760\n * 4-th term: (98 \\times 95 \\times 100) = 931000\n * 5-th term: (95 \\times 100 \\times 20) = 190000\n\n* * *"}, {"input": "3 2\n 1001 869120 1001", "output": "No\n \n\nNote that the output should be `No` if the grade for the 3-rd term is equal to\nthe grade for the 2-nd term.\n\n* * *"}, {"input": "15 7\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9", "output": "Yes\n Yes\n No\n Yes\n Yes\n No\n Yes\n Yes"}] |
Print the answer in N-K lines.
The i-th line should contain `Yes` if the grade for the (K+i)-th term is
greater than the grade for the (K+i-1)-th term, and `No` otherwise.
* * * | s189943245 | Runtime Error | p02602 | Input is given from Standard Input in the following format:
N K
A_1 A_2 A_3 \ldots A_N | r, g, b = map(int, input().split())
t = 0
while r >= g:
g *= 2
t += 1
while g >= b:
b *= 2
t += 1
print("No" if t > int(input()) else "Yes")
| Statement
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those
exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms: not given.
* For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.
M-kun scored A_i in the exam at the end of the i-th term.
For each i such that K+1 \leq i \leq N, determine whether his grade for the
i-th term is **strictly** greater than the grade for the (i-1)-th term. | [{"input": "5 3\n 96 98 95 100 20", "output": "Yes\n No\n \n\nHis grade for each term is computed as follows:\n\n * 3-rd term: (96 \\times 98 \\times 95) = 893760\n * 4-th term: (98 \\times 95 \\times 100) = 931000\n * 5-th term: (95 \\times 100 \\times 20) = 190000\n\n* * *"}, {"input": "3 2\n 1001 869120 1001", "output": "No\n \n\nNote that the output should be `No` if the grade for the 3-rd term is equal to\nthe grade for the 2-nd term.\n\n* * *"}, {"input": "15 7\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9", "output": "Yes\n Yes\n No\n Yes\n Yes\n No\n Yes\n Yes"}] |
Print the answer in N-K lines.
The i-th line should contain `Yes` if the grade for the (K+i)-th term is
greater than the grade for the (K+i-1)-th term, and `No` otherwise.
* * * | s047850346 | Runtime Error | p02602 | Input is given from Standard Input in the following format:
N K
A_1 A_2 A_3 \ldots A_N | n = int(input())
a = list(map(int, input().split()))
for i in range(n):
if a[0] < a[i]:
up = True
nin = a[0]
break
elif a[0] > a[i]:
up = False
break
if i == n - 1:
print(1000)
exit()
total = 1000
for i in range(1, n - 1):
if up:
if a[i - 1] <= a[i] and a[i] > a[i + 1]:
total += (total // nin) * (a[i] - nin)
up = False
else:
if a[i - 1] >= a[i] and a[i] < a[i + 1]:
nin = a[i]
up = True
if nin < a[n - 1]:
total += (total // nin) * (a[n - 1] - nin)
print(total)
| Statement
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those
exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms: not given.
* For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.
M-kun scored A_i in the exam at the end of the i-th term.
For each i such that K+1 \leq i \leq N, determine whether his grade for the
i-th term is **strictly** greater than the grade for the (i-1)-th term. | [{"input": "5 3\n 96 98 95 100 20", "output": "Yes\n No\n \n\nHis grade for each term is computed as follows:\n\n * 3-rd term: (96 \\times 98 \\times 95) = 893760\n * 4-th term: (98 \\times 95 \\times 100) = 931000\n * 5-th term: (95 \\times 100 \\times 20) = 190000\n\n* * *"}, {"input": "3 2\n 1001 869120 1001", "output": "No\n \n\nNote that the output should be `No` if the grade for the 3-rd term is equal to\nthe grade for the 2-nd term.\n\n* * *"}, {"input": "15 7\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9", "output": "Yes\n Yes\n No\n Yes\n Yes\n No\n Yes\n Yes"}] |
Print the answer in N-K lines.
The i-th line should contain `Yes` if the grade for the (K+i)-th term is
greater than the grade for the (K+i-1)-th term, and `No` otherwise.
* * * | s447030586 | Runtime Error | p02602 | Input is given from Standard Input in the following format:
N K
A_1 A_2 A_3 \ldots A_N | a, b, c = map(int, input().split())
k = int(input())
re = 0
re1 = 0
su = 0
for i in range(k):
re = re + b * 2
su = su + 1
if re > a:
quit()
for j in range(k - su):
re1 = re1 + c * 2
if re1 > re:
print("Yes")
else:
print("No")
| Statement
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those
exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms: not given.
* For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.
M-kun scored A_i in the exam at the end of the i-th term.
For each i such that K+1 \leq i \leq N, determine whether his grade for the
i-th term is **strictly** greater than the grade for the (i-1)-th term. | [{"input": "5 3\n 96 98 95 100 20", "output": "Yes\n No\n \n\nHis grade for each term is computed as follows:\n\n * 3-rd term: (96 \\times 98 \\times 95) = 893760\n * 4-th term: (98 \\times 95 \\times 100) = 931000\n * 5-th term: (95 \\times 100 \\times 20) = 190000\n\n* * *"}, {"input": "3 2\n 1001 869120 1001", "output": "No\n \n\nNote that the output should be `No` if the grade for the 3-rd term is equal to\nthe grade for the 2-nd term.\n\n* * *"}, {"input": "15 7\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9", "output": "Yes\n Yes\n No\n Yes\n Yes\n No\n Yes\n Yes"}] |
Print the answer in N-K lines.
The i-th line should contain `Yes` if the grade for the (K+i)-th term is
greater than the grade for the (K+i-1)-th term, and `No` otherwise.
* * * | s159779802 | Accepted | p02602 | Input is given from Standard Input in the following format:
N K
A_1 A_2 A_3 \ldots A_N | N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
for i in range(K,N):
if (A[i-K] < A[i]):print("Yes")
else: print("No") | Statement
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those
exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms: not given.
* For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.
M-kun scored A_i in the exam at the end of the i-th term.
For each i such that K+1 \leq i \leq N, determine whether his grade for the
i-th term is **strictly** greater than the grade for the (i-1)-th term. | [{"input": "5 3\n 96 98 95 100 20", "output": "Yes\n No\n \n\nHis grade for each term is computed as follows:\n\n * 3-rd term: (96 \\times 98 \\times 95) = 893760\n * 4-th term: (98 \\times 95 \\times 100) = 931000\n * 5-th term: (95 \\times 100 \\times 20) = 190000\n\n* * *"}, {"input": "3 2\n 1001 869120 1001", "output": "No\n \n\nNote that the output should be `No` if the grade for the 3-rd term is equal to\nthe grade for the 2-nd term.\n\n* * *"}, {"input": "15 7\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9", "output": "Yes\n Yes\n No\n Yes\n Yes\n No\n Yes\n Yes"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s176229937 | Accepted | p03910 | The input is given from Standard Input in the following format:
N | n = int(input())
a = [1]
while sum(a) < n:
a.append(a[-1] + 1)
if sum(a) != n:
b = sum(a) - n
a[b - 1 : b] = []
print(*a, sep="\n")
| Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s611607693 | Runtime Error | p03910 | The input is given from Standard Input in the following format:
N | class BisectSearch:
def __init__(self, f, l=0, r=10**9):
self.f = f
self.l = l
self.r = r
def __call__(self, dist):
f = self.f
l = self.l
r = self.r
if dist <= f(l):
return l
if f(r) <= dist:
return r
while r - l > 1:
n = (r + l) // 2
if f(n) <= dist:
l = n
else:
r = n
return l
n = int(input())
def f(n):
return (n + 1) * n // 2
m = BisectSearch(f, l=1, r=10**7)(n)
m += f(m) != n
A = set(range(1, m + 1))
A.remove(f(m) - n)
print(*A, sep="\n")
| Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s042280832 | Accepted | p03910 | The input is given from Standard Input in the following format:
N | import math
import bisect
import collections
import itertools
import heapq
import sys
sys.setrecursionlimit(10**9)
def gcd(a, b):
return math.gcd # 最大公約数
def lcm(a, b):
return (a * b) // math.gcd(a, b) # 最小公倍数
def iin():
return int(input()) # 整数読み込み
def isn():
return input().split() # 文字列読み込み
def imn():
return map(int, input().split()) # 整数map取得
def iln():
return list(map(int, input().split())) # 整数リスト取得
def iln_s():
return sorted(iln()) # 昇順の整数リスト取得
def iln_r():
return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=""):
return s.join(l) # リストを文字列に変換
def perm(l, n):
return itertools.permutations(l, n) # 順列取得
def comb(l, n):
return itertools.combinations(l, n) # 組み合わせ取得
def 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
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
def sieve_of_e(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return is_prime
N = iin()
total = 0
index = 0
for i in range(1, N + 1):
total += i
if total >= N:
index = i
break
diff = total - N
for i in range(1, index + 1):
if diff == i:
continue
print(i)
| Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s977467334 | Runtime Error | p03910 | The input is given from Standard Input in the following format:
N | import math
n=int(input())
def ts(x):
return x*(x+1)
m=n
for i in range(math.ceil(math.sqrt(2*n)-2),math.floor(math.sqrt(2*n))+1,1):
if ts(i)<=2*n<=ts(i+1):
m=i+1
break
a=n%(m+1)
b=n//(m+1)
if m%2==0:
if a!=0:
print(a)
i=1
c=0
while c!=b:
if i!=a and m+1-i!=a:
print(i)
print(m+1-i)
c+=1
else:
check=[]
if a!=0:
check.append(a)
i = 1
c = 0
while c!=b and i<(m+1)//2:
if i!=a and m+1-i!=a:
check.append(i)
check.append(m+1-i)
c+=1
if c==b:
for i in check:
print(i)
else:
n-=(m+1)//2
a = n % (m + 1)
b = n // (m + 1)
if m % 2 == 0:
if a != 0:
print(a)
i = 1
c = 0
while c != b:
if i != a and m + 1 - i != a:
print(i)
print(m + 1 - i)
c += 1import math
n=int(input())
def ts(x):
return x*(x+1)
m=n
for i in range(math.ceil(math.sqrt(2*n)-2),math.floor(math.sqrt(2*n))+1,1):
if ts(i)<=2*n<=ts(i+1):
m=i+1
break
a=n%(m+1)
b=n//(m+1)
if m%2==0:
if a!=0:
print(a)
i=1
c=0
while c!=b:
if i!=a and m+1-i!=a:
print(i)
print(m+1-i)
c+=1
else:
check=[]
if a!=0:
check.append(a)
i = 1
c = 0
while c!=b and i<(m+1)//2:
if i!=a and m+1-i!=a:
check.append(i)
check.append(m+1-i)
c+=1
if c==b:
for i in check:
print(i)
else:
n-=(m+1)//2
a = n % (m + 1)
b = n // (m + 1)
if m % 2 == 0:
if a != 0:
print(a)
i = 1
c = 0
while c != b:
if i != a and m + 1 - i != a:
print(i)
print(m + 1 - i)
c += 1 | Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s998192362 | Accepted | p03910 | The input is given from Standard Input in the following format:
N | n = int(input())
get = 0
solve = set()
for i in range(1, 10000):
get += i
solve.add(i)
if get >= n:
break
for s in solve:
if s != get - n:
print(s)
| Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s401371464 | Accepted | p03910 | The input is given from Standard Input in the following format:
N | n = int(input())
now = 1
L = []
while now * (now - 1) // 2 < n:
L.append(now)
now += 1
c = sum(L)
if c > n:
L.remove(c - n)
print(*L, sep="\n")
| Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
Among the sets of problems with the total score of N, find a set in which the
highest score of a problem is minimum, then print the indices of the problems
in the set in any order, one per line.
If there exists more than one such set, any of them will be accepted.
* * * | s986579763 | Accepted | p03910 | The input is given from Standard Input in the following format:
N | n = int(input())
chk = 0
add = 1
while chk < n:
chk += add
add += 1
add -= 1
if n == chk:
for i in range(add):
print(i + 1)
else:
exc = chk - n
for i in range(add):
if i + 1 == exc:
continue
print(i + 1)
| Statement
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is
deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest
score of a problem among the ones solved by him.
Determine the set of problems that should be solved. | [{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}] |
The length of the longest increasing subsequence of A. | s776631298 | Accepted | p02317 | n
a0
a1
:
an-1
In the first line, an integer n is given. In the next n lines, elements of A
are given. | from bisect import bisect_left
import sys
input = sys.stdin.readline
def LIS():
N = int(input())
INF = 10000000000
dp = [INF] * (N + 1)
for _ in range(N):
x = int(input())
dp[bisect_left(dp, x)] = x
print(bisect_left(dp, INF - 1))
LIS()
| Longest Increasing Subsequence
For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest
increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... ,
aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik. | [{"input": "5\n 5\n 1\n 3\n 2\n 4", "output": "3"}, {"input": "3\n 1\n 1\n 1", "output": "1"}] |
The length of the longest increasing subsequence of A. | s002653408 | Accepted | p02317 | n
a0
a1
:
an-1
In the first line, an integer n is given. In the next n lines, elements of A
are given. | from bisect import bisect_left
n = int(input())
A = [int(input()) for _ in range(n)]
def LIS(arr):
dp = [arr[0]]
for i in arr[1:]:
if dp[-1] < i:
dp.append(i)
else:
dp[bisect_left(dp, i)] = i
return len(dp)
print(LIS(A))
| Longest Increasing Subsequence
For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest
increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... ,
aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik. | [{"input": "5\n 5\n 1\n 3\n 2\n 4", "output": "3"}, {"input": "3\n 1\n 1\n 1", "output": "1"}] |
The length of the longest increasing subsequence of A. | s449471556 | Accepted | p02317 | n
a0
a1
:
an-1
In the first line, an integer n is given. In the next n lines, elements of A
are given. | import sys, bisect
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
def I():
return int(input())
def F():
return float(input())
def S():
return input()
def LI():
return [int(x) for x in input().split()]
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return [float(x) for x in input().split()]
def LS():
return input().split()
def lis(a):
dp = [INF] * len(a)
for i in a:
idx = bisect.bisect_left(dp, i)
dp[idx] = i
return bisect.bisect_left(dp, INF)
def resolve():
n = I()
a = [I() for _ in range(n)]
print(lis(a))
if __name__ == "__main__":
resolve()
| Longest Increasing Subsequence
For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest
increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... ,
aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik. | [{"input": "5\n 5\n 1\n 3\n 2\n 4", "output": "3"}, {"input": "3\n 1\n 1\n 1", "output": "1"}] |
The length of the longest increasing subsequence of A. | s542626169 | Accepted | p02317 | n
a0
a1
:
an-1
In the first line, an integer n is given. In the next n lines, elements of A
are given. | def LIS(n, a):
lis = 0
dp = [0] * n
dp[0] = a[0]
for i in range(1, n):
cur = a[i]
if cur < dp[0]:
dp[0] = cur
elif cur > dp[lis]:
lis += 1
dp[lis] = cur
else:
idx = find_pos(cur, 0, lis, dp)
dp[idx] = cur
return lis + 1
def find_pos(target, floor, ceiling, dp):
while floor < ceiling:
guess_idx = int(floor + (ceiling - floor) / 2)
guess_val = dp[guess_idx]
if guess_val == target:
return guess_idx
if guess_val < target:
floor = guess_idx + 1
else:
ceiling = guess_idx - 1
if dp[floor] < target:
return floor + 1
return floor
n = int(input())
a = [0] * n
for i in range(n):
a[i] = int(input())
print(LIS(n, a))
| Longest Increasing Subsequence
For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest
increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... ,
aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik. | [{"input": "5\n 5\n 1\n 3\n 2\n 4", "output": "3"}, {"input": "3\n 1\n 1\n 1", "output": "1"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s531971871 | Runtime Error | p02747 | Input is given from Standard Input in the following format:
S | import sys
lines = sys.stdin.readlines()
num_a, num_b, num_m = [int(v) for v in lines[0].split()]
# ----
a_list = [int(v) for v in lines[1].split()[: num_a + 1]]
b_list = [int(v) for v in lines[2].split()[: num_b + 1]]
# print(a_list)
# print(b_list)
result = max(a_list) + max(b_list)
# ignores = set()
for c in lines[3 : num_m + 3]:
a_i, b_i, discount = map(int, c.split())
try:
# ignores.add((int(a_i), int(b_i)))
price = a_list[a_i - 1] + b_list[b_i - 1] - discount
if price < result:
result = price
except IndexError:
print("------")
print(c)
pass
res1 = [
a_list[a_i - 1] + b_list[b_i - 1] - discount
for a_i, b_i, discount in [map(int, l.split()) for l in lines[3 : num_m + 3]]
]
res2 = [a + b for b in b_list for a in a_list]
print(min(min(res1), min(res2)))
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s615841731 | Runtime Error | p02747 | Input is given from Standard Input in the following format:
S | n, m = map(int, input().split())
ans = [[1 for j in range(2**m - 1)] for i in range(2**n - 1)]
for i in range(2**n - 1):
for j in range(2**m - 1):
if i % 2 != j % 2:
ans[i][j] = 0
if (abs(i % 8) == 3) ^ (abs(j % 8) == 3):
ans[i][j] = 1
for arr in ans:
print(*arr, sep="")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s169129067 | Runtime Error | p02747 | Input is given from Standard Input in the following format:
S | import sys
input = sys.stdin.readline
n = int(input())
s = input()
num = 2 ** (n - 1).bit_length()
def segfunc(x, y):
return x | y
seg = [0] * (2 * num - 1)
for i in range(n):
seg[i + num - 1] = 2 ** (ord(s[i]) - 97)
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(i, x):
i += num - 1
seg[i] = x
while i:
i = (i - 1) // 2
seg[i] = segfunc(seg[i * 2 + 1], seg[i * 2 + 2])
def query(l, r):
l += num - 1
r += num - 1
if l == r:
return seg[l]
s = seg[l]
l += 1
while r - l > 1:
if ~l % 2:
s = segfunc(seg[l], s)
if r % 2:
s = segfunc(seg[r], s)
r -= 1
l //= 2
r = (r - 1) // 2
if l == r:
return segfunc(s, seg[l])
return segfunc(s, segfunc(seg[l], seg[r]))
for _ in range(int(input())):
quer = input().split()
if quer[0] == "1":
_, i, c = quer
update(int(i) - 1, 2 ** (ord(c) - 97))
else:
_, l, r = quer
print(sum(map(int, bin(query(int(l) - 1, int(r) - 1))[2:])))
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s985796808 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | print("Yes" * (input() in ["hi" * i for i in range(1, 6)]) or "No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s455050891 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | print("YNeos"["".join(input().split("hi")) != "" :: 2])
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s339666590 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | print("Yes" if input() in ["hi" * i for i in range(1, 6)] else "No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s256878249 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | print(input().replace("hi", "") and "No" or "Yes")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s311867080 | Wrong Answer | p02747 | Input is given from Standard Input in the following format:
S | print("yes" if "hi" in input() else "No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s141714598 | Wrong Answer | p02747 | Input is given from Standard Input in the following format:
S | print("Yes" if "".join(sorted(set(input()))) == "hi" else "No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s389541744 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | # 1st: Code Festival 2015 Qualifying B (0408)
if False:
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
A.sort()
B.sort()
ans = "YES"
if N < M:
ans = "NO"
else:
while B:
a = A.pop()
b = B.pop()
if b > a:
ans = "NO"
break
print(ans)
# 2nd: CF2014QA-C
if False:
A, B = map(int, input().split())
def uruu(n):
ret = 0
ret += n // 4
ret -= n // 100
ret += n // 400
return ret
print(uruu(B) - uruu(A - 1))
# 3rd: Code Formula 2014 - C
if False:
S = input()
stack = list(S[::-1])
# print(stack)
user = []
s = stack.pop()
while stack:
# print(s)
if s == "@":
tmp = ""
x = stack.pop()
while not (x in ("@", " ")):
# print(x)
tmp += x
if not stack:
break
x = stack.pop()
user.append(tmp)
s = x
else:
s = stack.pop()
user = list(set(user))
user.sort()
for u in user:
if u:
print(u)
# 4th: Hitachi Programming Contest 2020 - A
if True:
S = input()
hi = ["hi" * i for i in range(1, 10)]
print("Yes" if S in hi else "No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s094319569 | Wrong Answer | p02747 | Input is given from Standard Input in the following format:
S | s = input()
n = len(s)
if n == 1:
print("No")
elif n == 2:
if s == "hi":
print("Yes")
else:
print("No")
elif n == 3:
if s[0] + s[1] == "hi" or s[1] + s[2] == "hi":
print("Yes")
else:
print("No")
elif n == 4:
if s[0] + s[1] == "hi" or s[1] + s[2] == "hi" or s[2] + s[3] == "hi":
print("Yes")
else:
print("No")
elif n == 5:
if (
s[0] + s[1] == "hi"
or s[1] + s[2] == "hi"
or s[2] + s[3] == "hi"
or s[3] + s[4] == "hi"
):
print("Yes")
else:
print("No")
elif n == 6:
if (
s[0] + s[1] == "hi"
or s[1] + s[2] == "hi"
or s[2] + s[3] == "hi"
or s[3] + s[4] == "hi"
or s[4] + s[5] == "hi"
):
print("Yes")
else:
print("No")
elif n == 7:
if (
s[0] + s[1] == "hi"
or s[1] + s[2] == "hi"
or s[2] + s[3] == "hi"
or s[3] + s[4] == "hi"
or s[4] + s[5] == "hi"
or s[5] + s[6] == "hi"
):
print("Yes")
else:
print("No")
elif n == 8:
if (
s[0] + s[1] == "hi"
or s[1] + s[2] == "hi"
or s[2] + s[3] == "hi"
or s[3] + s[4] == "hi"
or s[4] + s[5] == "hi"
or s[5] + s[6] == "hi"
or s[6] + s[7] == "hi"
):
print("Yes")
else:
print("No")
elif n == 9:
if (
s[0] + s[1] == "hi"
or s[1] + s[2] == "hi"
or s[2] + s[3] == "hi"
or s[3] + s[4] == "hi"
or s[4] + s[5] == "hi"
or s[5] + s[6] == "hi"
or s[6] + s[7] == "hi"
or s[7] + s[8] == "hi"
):
print("Yes")
else:
print("No")
elif n == 10:
if (
s[0] + s[1] == "hi"
or s[1] + s[2] == "hi"
or s[2] + s[3] == "hi"
or s[3] + s[4] == "hi"
or s[4] + s[5] == "hi"
or s[5] + s[6] == "hi"
or s[6] + s[7] == "hi"
or s[7] + s[8] == "hi"
or s[8] + s[9] == "hi"
):
print("Yes")
else:
print("No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s701937933 | Runtime Error | p02747 | Input is given from Standard Input in the following format:
S | r, p, m = range, print, min
n, a, b = [list(map(int, input().split())) for i in r(3)]
l = []
for i in r(n[2]):
x, y, z = map(int, input().split())
l.append(a[x - 1] + b[y - 1] - z)
p(m([m(a) + m(b), m(l)]))
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s146496563 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | print("NYoe s"[input() in ["hi" * x for x in range(6)] :: 2])
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s937298968 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | print("No" if input().replace("hi", "") else "Yes")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s673334557 | Accepted | p02747 | Input is given from Standard Input in the following format:
S | h = input().replace("hi", "")
o = "Yes" if h == "" else "No"
print(o)
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s833966459 | Wrong Answer | p02747 | Input is given from Standard Input in the following format:
S | print("NYoe s"[("hi" * 100).startswith(input()) :: 2])
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s919637318 | Wrong Answer | p02747 | Input is given from Standard Input in the following format:
S | hi = input()
print("Yes" if set(hi[0::2]) == {"h"} and set(hi[1::2]) == {"i"} else "No")
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
If S is a Hitachi string, print `Yes`; otherwise, print `No`.
* * * | s139280294 | Wrong Answer | p02747 | Input is given from Standard Input in the following format:
S | s = "hi"
print("YNeos"[any(c != s[i & 1] for i, c in enumerate(input())) :: 2])
| Statement
A Hitachi string is a concatenation of one or more copies of the string `hi`.
For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are
not.
Given a string S, determine whether S is a Hitachi string. | [{"input": "hihi", "output": "Yes\n \n\n`hihi` is the concatenation of two copies of `hi`, so it is a Hitachi string.\n\n* * *"}, {"input": "hi", "output": "Yes\n \n\n* * *"}, {"input": "ha", "output": "No"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s407756556 | Wrong Answer | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | import sys
sys.setrecursionlimit(4100000)
s = input()
WL = ["dream", "dreamer", "erase", "eraser"]
WLE5 = ["dream", "eamer", "erase", "raser"]
WD = {"dream": 5, "eamer": 7, "erase": 5, "raser": 6}
def hantei(s):
while True:
if len(s) == 0:
return True
elif len(s) <= 4:
return False
saigo = s[-5:]
if saigo in WLE5:
num = WD[saigo]
if len(s) < num:
return False
s = s[:-num]
else:
return False
print("YES" if hantei(s) else "NO")
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s398583389 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | 7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7 | Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s839466942 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | import copy
class UnionFind:
def __init__(self, N):
self._parent = [i for i in range(N)]
self._rank = [1 for i in range(N)]
def find(self, x):
if self._parent[x] == x:
return x
else:
return self.find(self._parent[x])
def unite(self, a, b):
ta = self.find(a)
tb = self.find(b)
if(ta == tb):
return
if self._rank[ta] < self._rank[tb]:
self._parent[ta] = tb # make b as a parent of a
else:
self._parent[tb] = ta # make a as a parent of b
if(ta == tb) rank[ta] += 1
def check(self, a, b):
return self.find(a) == self.find(b)
if __name__ == '__main__':
N,K,L = map(int, input().split())
ans = [1 for _ in range(N+1)]
uf = UnionFind(N+1)
for _ in range(K):
p,q = map(int, input().split())
uf.unite(p,q)
for _ in range(L):
s,r = map(int, input().split())
if uf.check(s,r):
ans[s] += 1
ans[r] += 1
print(*ans[1::]) | Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s054754824 | Wrong Answer | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | print("1 2 2 1")
print("1 2 2 1")
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s827133956 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | H, W = map(int, input().split())
A = [[int(i) for i in input().split()] for _ in range(H)]
dp = [[0] * W for _ in range(H)]
memo = [[-1] * W for _ in range(H)]
mod = 10**9 + 7
result = 0
def aaa(x, y):
move_list = [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]
val = A[x][y]
cnt = 1
for new_x, new_y in move_list:
if 0 <= new_x < H and 0 <= new_y < W and A[new_x][new_y] > val:
cnt += aaa(new_x, new_y) if memo[new_x][new_y] == -1 else memo[new_x][new_y]
cnt %= mod
memo[x][y] = cnt
return cnt
for i in range(H):
for j in range(W):
result += aaa(i, j)
print(result)
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s963283972 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
class UnionFind():
def __init__(self, n):
self.n = n
self.d = [-1] * n
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
else:
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
n, k, l = map(int, input().split())
uf = UnionFind(n)
for i in range(k):
p, q = map(int, input().split())
p -= 1
q -= 1
uf.unite(p, q)
ans = [1] * n
for i in range(l):
r, s = map(int, input().split())
r -= 1
s -= 1
if uf.same(r, s) == True:
# print(uf.d)
print(' '.join(map(str, ans))) | Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s733231867 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | #Union-Find木の構築
import sys
def 解():
iN,iK,iL = [int(_) for _ in input().split()]
aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
def buildTree(a):
aT = [0]*(iN+1)
for p,q in a:
#if p > q :
# p,q = q,p
thisroot = max(aT[q],aT[p],q) #試しにデカい方に合わせる
if p <= aT[q] < thisroot: #2個づつ来るからこんなんでいいだろ
aT[aT[q]] = thisroot
if p <= aT[p] < thisroot:
aT[aT[p]] = thisroot
aT[q] = thisroot
aT[p] = thisroot
return aT
def getRoot(a,i):
if a[i] == i or a[i] == 0:
if a[i] == 0 : a[i] = i
return i
elif i < a[i] :
a[i] = getRoot(a,a[i])
return a[i]
else:
# print("! ",i,a[i])
aT道 = buildTree(aD[0:iK])
aT鉄道 = buildTree(aD[iK:])
aRet = []
dRet = {}
for i in range(1,iN+1):
# いやはやこんなもんもキーになるのか。
Comb = (getRoot(aT道,i), getRoot(aT鉄道,i))
aRet.append(Comb)
if Comb in dRet:
dRet[Comb] += 1
else:
dRet[Comb] = 1
print(" ".join([str(dRet[_]) for _ in aRet]))
解()
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s505332805 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | mport sys
sys.setrecursionlimit(10**5)
def 解():
iN,iK,iL = [int(_) for _ in input().split()]
aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
a道 = aD[0:iK]
a鉄道 = aD[iK:]
d道 = {}
d鉄道 = {}
# for i in range(1,iN+1):
# d道[i] = {i}
# d鉄道[i] ={i}
def fMakeSet(d,x,y):
if x in d:
d[x].add(y)
else:
d[x] = {y}
for p,q in a道:
#d道[p].add(q)
#d道[q].add(p)
fMakeSet(d道,q,p)
fMakeSet(d道,p,q)
for r,s in a鉄道:
fMakeSet(d鉄道,r,s)
fMakeSet(d鉄道,s,r)
def fdfs(d,iS):
dsVisited=set()
def digRoute(iT):
dsVisited.add(iT)
if iT in d:
for i in d[iT] - dsVisited:
#dsVisited.add(i)
digRoute(i)
digRoute(iS)
return dsVisited
def buildGroup(d):
gl = {}
gidx = {}
v = set()
iC = 0
for i in range(1,iN+1):
if i in v:
continue
else:
dsList = fdfs(d,i)
for i in dsList:
gidx[i] = iC
gl[iC]=dsList
iC += 1
v = v | dsList
return (gl,gidx)
dg鉄道,idxdg鉄道 = (buildGroup(d鉄道))
dg道,idxdg道 = (buildGroup(d道))
ak鉄道 = dg鉄道.keys()
ak道 = dg道.keys()
aM = [[ None for _ in range(len(ak道))] for _ in range(len(ak鉄道))]
for i in ak鉄道:
for j in ak道:
aM[i][j]=len(dg鉄道[i] & dg道[j])
aRet = []
for i in range(1,iN+1):
aRet.append(str(aM[idxdg鉄道[i]][idxdg道[i]]))
print( " ".join(aRet))
解()
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s776697203 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | import sys
from collections import defaultdict
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n, k, l = map(int, input().split())
uf_k = UnionFind(n)
uf_l = UnionFind(n)
for i in range(k):
p, q = map(int, input().split())
uf_k.union(p - 1, q - 1)
for i in range(l):
r, s = map(int, input().split())
uf_l.union(r - 1, s - 1)
d = defaultdict(int)
for i in range(n):
d[uf_k.find(i), uf_l.find(i)] += 1
print(*d[uf_k.find(i), uf_l.find(i)] for i in range(n))
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s523634596 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define n_max int(1e5+5)
struct UnionFind{
int A[n_max];
UnionFind( int n){
REP(i,n) A[i]=i;
}
int root(int a){
if(A[a] == a) return a;
int tmp;
tmp = root(A[a]);
A[a] = tmp;
return tmp;
}
bool same(int a, int b){
if(root(a) == root(b)) return true;
return false;
}
void merge(int a,int b){
A[root(a)] = root(b);
}
};
struct town{
int k,l;
int id;
};
bool comp(town a,town b){
if(a.k != b.k) return a.k < b.k;
else return a.l < b.l;
}
int main(){
int n,k,l;
cin >> n >> k >> l;
UnionFind K(n),L(n);
int a,b;
REP(i,k){
scanf("%d%d",&a,&b);
K.merge(a-1,b-1);
}
REP(i,l){
scanf("%d%d",&a,&b);
L.merge(a-1,b-1);
}
town T[n_max];
REP(i,n){
T[i].id=i;
T[i].k = K.root(i);
T[i].l = L.root(i);
}
sort(T,T+n,comp);
int ans[n_max]={};
int i=0;
while(1){
pair<int,int> p;
p.first = T[i].k;
p.second = T[i].l;
vector<int> ind;
ind.push_back(T[i].id);
while(1){
i+=1;
if(i < n and T[i].k == p.first and T[i].l == p.second){
ind.push_back(T[i].id);
}
else{
itrfor(itr,ind) ans[*itr] = ind.size();
break;
}
}
if(i >=n) break;
}
REP(i,n) cout << ans[i] << " ";
} | Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s877901172 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | import sys
sys.setrecursionlimit(4100000)
import math
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
from unionfind import UnionFind, UnionFindCounter
def resolve():
# S = [x for x in sys.stdin.readline().split()][0] # 文字列 一つ
# N = [int(x) for x in sys.stdin.readline().split()][0] # int 一つ
N, K, L = [int(x) for x in sys.stdin.readline().split()] # 複数int
# grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)] # 文字列grid
grid = [
[int(x) - 1 for x in sys.stdin.readline().split()] for _ in range(K + L)
] # int grid
logger.debug("{}".format([]))
p_uf = UnionFind(N)
r_uf = UnionFind(N)
both_uf = UnionFindCounter(N)
for k in range(K):
p, q = grid[k]
p_uf.unite(p, q)
for l in range(K, K + L):
r, s = grid[l]
r_uf.unite(r, s)
if p_uf.isSame(r, s):
both_uf.unite(r, s)
print(" ".join([str(x) for x in both_uf.getCount()]))
if __name__ == "__main__":
resolve()
# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """4 3 1
1 2
2 3
3 4
2 3"""
output = """1 2 2 1"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4 2 2
1 2
2 3
1 4
2 3"""
output = """1 2 2 1"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7"""
output = """1 1 2 1 2 2 2"""
self.assertIO(input, output)
def test_入力例_4(self):
input = """2 1 1
1 2
1 2"""
output = """2 2"""
self.assertIO(input, output)
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s346781840 | Wrong Answer | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | N, K, L = map(int, input().split())
path = []
rail = []
for i in range(0, N):
path.append(-1)
rail.append(-1)
pathindex = 0
for i in range(0, K):
p, q = map(int, input().split())
if path[p - 1] == -1 and path[q - 1] == -1:
path[p - 1] = pathindex
path[q - 1] = pathindex
pathindex += 1
elif path[p - 1] == -1:
path[p - 1] = path[q - 1]
elif path[q - 1] == -1:
path[q - 1] = path[p - 1]
railindex = 0
for i in range(0, L):
p, q = map(int, input().split())
if rail[p - 1] == -1 and rail[q - 1] == -1:
rail[p - 1] = railindex
rail[q - 1] = railindex
railindex += 1
elif rail[p - 1] == -1:
rail[p - 1] = rail[q - 1]
elif rail[q - 1] == -1:
rail[q - 1] = rail[p - 1]
pathlist = []
for i in range(0, pathindex):
pathlist.append([])
for i in range(0, N):
if path[i] != -1:
pathlist[path[i]].append(i)
raillist = []
for i in range(0, railindex):
raillist.append([])
for i in range(0, N):
if rail[i] != -1:
raillist[rail[i]].append(i)
anslist = []
for i in range(0, N):
if path[i] == -1 or rail[i] == -1:
anslist.append(1)
else:
anslist.append(len(list(set(pathlist[path[i]]) & set(raillist[rail[i]]))))
ans = str(anslist[0])
for i in range(1, N):
ans = ans + " " + str(anslist[i])
print(ans)
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s293727355 | Wrong Answer | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | n, k, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(k)]
b = [list(map(int, input().split())) for i in range(l)]
c = [0] * n
a1 = list(set(sum(a, [])))
b1 = list(set(sum(b, [])))
c = [0] * n
for i in b1:
c[i - 1] += 1
for i in a1:
c[i - 1] += 1
print(*c)
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s434814552 | Runtime Error | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | class Node:
def __init__(self, value):
self.value = value
self.connect = []
self.visited = False
def getConnect(self):
return self.connect
def setConnect(self, connects):
self.connect = connects
def getConnectValues(self):
res = []
for node in self.connect:
res.append(node.getValue())
return res
def getValue(self):
return self.value
def addConnect(self, connectNode):
self.connect.append(connectNode)
def addConnects(self, connectNodes):
self.connect += connectNodes
def visitAll(self):
self.visited = True
for i in range(len(self.connect)):
if self.connect[i].visited:
continue
else:
self.connect[i].visitAll()
def computeAllConnects(node, list1):
node.visitAll()
res = []
for i in range(1, len(list1)):
if list1[i].visited:
res.append(list1[i])
node.setConnect(res)
refreshVisited(list1)
def refreshVisited(list1):
for i in range(1, len(list1)):
list1[i].visited = False
def computeDuplicate(list1, list2):
res = []
for i in list1:
if i in list2:
res.append(i)
return res
line1 = input()
line1 = line1.split(" ")
numCities = int(line1[0])
numRoads = int(line1[1])
numRails = int(line1[2])
road = [0]
rail = [0]
res = [0]
for i in range(1, numCities + 1):
road.append(Node(i))
rail.append(Node(i))
for i in range(numRoads):
lineI = input().split(" ")
city1 = road[int(lineI[0])]
city2 = road[int(lineI[1])]
city1.addConnect(city2)
city2.addConnect(city1)
for i in range(numRails):
lineI = input().split(" ")
city1 = rail[int(lineI[0])]
city2 = rail[int(lineI[1])]
city1.addConnect(city2)
city2.addConnect(city1)
for i in range(1, numCities + 1):
computeAllConnects(road[i], road)
computeAllConnects(rail[i], rail)
for i in range(1, numCities + 1):
roadConnects = road[i].getConnectValues()
railConnects = rail[i].getConnectValues()
res.append(len(computeDuplicate(roadConnects, railConnects)))
res = res[1:]
for i in range(0, len(res) - 1):
print(res[i], end=" ")
print(res[len(res) - 1])
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s299288459 | Accepted | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, K, L, PQ, RS):
ans = 0
gr = defaultdict(list)
for p, q in PQ:
gr[p].append(q)
gr[q].append(p)
gt = defaultdict(list)
for r, s in RS:
gt[r].append(s)
gt[s].append(r)
ccr = {}
unused = set(gr.keys())
while unused:
q = [unused.pop()]
con = set([])
while q:
v = q.pop()
con.add(v)
for u in gr[v]:
if u in unused:
q.append(u)
unused.remove(u)
for v in con:
ccr[v] = con
cct = {}
unused = set(gt.keys())
while unused:
q = [unused.pop()]
con = set([])
while q:
v = q.pop()
con.add(v)
for u in gt[v]:
if u in unused:
q.append(u)
unused.remove(u)
for v in con:
cct[v] = con
cache = {}
def cc(t, r):
k = (id(t), id(r))
if k not in cache:
cache[k] = len(t & r)
return cache[k]
ans = []
for i in range(1, N + 1):
if i in cct and i in ccr:
a = cc(cct[i], ccr[i])
else:
a = 1
ans.append(a)
return " ".join(map(str, ans))
def main():
N, K, L = read_int_n()
PQ = [read_int_n() for _ in range(K)]
RS = [read_int_n() for _ in range(L)]
print(slv(N, K, L, PQ, RS))
if __name__ == "__main__":
main()
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s183580819 | Wrong Answer | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | def dfs(r, c, g, color):
s = [r]
color[r] = c
while len(s) != 0:
u = s.pop()
for i in range(len(g[u])):
v = g[u][i]
if color[v] is None:
color[v] = c
s.append(v)
def assignColor(n, g, color):
color_id = 1
for u in range(n):
if color[u] is None:
dfs(u, color_id, g, color)
color_id += 1
N, K, L = [int(v) for v in input().split()]
road = [[] for i in range(N)]
train = [[] for i in range(N)]
for i in range(K):
p, q = [int(v) - 1 for v in input().split()]
road[p].append(q)
road[q].append(p)
for i in range(L):
r, s = [int(v) - 1 for v in input().split()]
train[r].append(s)
train[s].append(r)
road_color = [None] * N
train_color = [None] * N
assignColor(N, road, road_color)
assignColor(N, train, train_color)
print(" ".join([str(v) for v in road_color]))
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print N integers. The i-th of them should represent the number of the cities
connected to the i-th city by both roads and railways.
* * * | s737658543 | Wrong Answer | p03855 | The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L | N, K, L = [int(x) for x in input().split()]
in_K = [[int(x) for x in input().split()] for i in range(K)]
in_L = [[int(x) for x in input().split()] for i in range(L)]
in_K.sort()
in_L.sort()
ar = {}
br = {}
val = 0
for i in range(K):
p, q = in_K[i]
if not p in ar.keys() and not q in ar.keys():
val += 1
ar[p] = val
ar[q] = val
else:
if p in ar.keys():
ar[q] = ar[p]
else:
ar[p] = ar[q]
for i in range(1, N + 1):
if not i in ar.keys():
val += 1
ar[i] = val
val = 0
for i in range(L):
p, q = in_L[i]
if not p in br.keys() and not q in br.keys():
val += 1
br[p] = val
br[q] = val
else:
if p in br.keys():
br[q] = br[p]
else:
br[p] = br[q]
for i in range(1, N + 1):
if not i in br.keys():
val += 1
br[i] = val
ab_dict = {}
for i in range(1, N + 1):
if not (ar[i], br[i]) in ab_dict.keys():
ab_dict[(ar[i], br[i])] = 1
else:
ab_dict[(ar[i], br[i])] += 1
ans = []
for i in range(1, N + 1):
ans.append(ab_dict[(ar[i], br[i])])
print(*ans)
| Statement
There are N cities. There are also K roads and L railways, extending between
the cities. The i-th road bidirectionally connects the p_i-th and q_i-th
cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th
cities. No two roads connect the same pair of cities. Similarly, no two
railways connect the same pair of cities.
We will say city A and B are _connected by roads_ if city B is reachable from
city A by traversing some number of roads. Here, any city is considered to be
connected to itself by roads. We will also define _connectivity by railways_
similarly.
For each city, find the number of the cities connected to that city by both
roads and railways. | [{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}] |
Print Q lines. The i-th line (1 ≤ i ≤ Q) must contain the index of the lowest
common ancestor of Vertex v_i and w_i.
* * * | s412094811 | Accepted | p03506 | Input is given from Standard Input in the following format:
N Q
v_1 w_1
:
v_Q w_Q | N, Q = map(int, input().split())
vws = [tuple(map(int, input().split())) for _ in range(Q)]
anss = []
if N == 1:
anss = [min(v, w) for v, w in vws]
else:
for v, w in vws:
v, w = v - 1, w - 1
while v != w:
if v > w:
v = (v - 1) // N
else:
w = (w - 1) // N
anss.append(v + 1)
print("\n".join(map(str, anss)))
| Statement
You are given an integer N. Consider an infinite N-ary tree as shown below:

Figure: an infinite N-ary tree for the case N = 3
As shown in the figure, each vertex is indexed with a unique positive integer,
and for every positive integer there is a vertex indexed with it. The root of
the tree has the index 1. For the remaining vertices, vertices in the upper
row have smaller indices than those in the lower row. Among the vertices in
the same row, a vertex that is more to the left has a smaller index.
Regarding this tree, process Q queries. The i-th query is as follows:
* Find the index of the lowest common ancestor (see Notes) of Vertex v_i and w_i. | [{"input": "3 3\n 5 7\n 8 11\n 3 9", "output": "2\n 1\n 3\n \n\nThe queries in this case correspond to the examples shown in Notes.\n\n* * *"}, {"input": "100000 2\n 1 2\n 3 4", "output": "1\n 1"}] |
Print Q lines. The i-th line (1 ≤ i ≤ Q) must contain the index of the lowest
common ancestor of Vertex v_i and w_i.
* * * | s804897609 | Accepted | p03506 | Input is given from Standard Input in the following format:
N Q
v_1 w_1
:
v_Q w_Q | N, Q = map(int, input().split())
if N == 1:
for i in range(Q):
V, W = map(int, input().split())
print(min(V, W))
else:
p = []
p.append(1)
for i in range(40):
p.append(p[-1] * N)
for i in range(Q):
V, W = map(int, input().split())
v = []
w = []
dv = 0
dw = 0
while V > (p[dv + 1] - 1) // (N - 1):
dv = dv + 1
while W > (p[dw + 1] - 1) // (N - 1):
dw = dw + 1
v.append(V)
e = V
for j in range(dv, 0, -1):
e = (e - (p[j] - 1) // (N - 1) - 1) // N + (p[j - 1] - 1) // (N - 1) + 1
v.append(e)
v.reverse()
w.append(W)
e = W
for j in range(dw, 0, -1):
e = (e - (p[j] - 1) // (N - 1) - 1) // N + (p[j - 1] - 1) // (N - 1) + 1
w.append(e)
w.reverse()
ans = 1
j = 0
while j < len(v) and j < len(w) and v[j] == w[j]:
ans = v[j]
j = j + 1
print(ans)
| Statement
You are given an integer N. Consider an infinite N-ary tree as shown below:

Figure: an infinite N-ary tree for the case N = 3
As shown in the figure, each vertex is indexed with a unique positive integer,
and for every positive integer there is a vertex indexed with it. The root of
the tree has the index 1. For the remaining vertices, vertices in the upper
row have smaller indices than those in the lower row. Among the vertices in
the same row, a vertex that is more to the left has a smaller index.
Regarding this tree, process Q queries. The i-th query is as follows:
* Find the index of the lowest common ancestor (see Notes) of Vertex v_i and w_i. | [{"input": "3 3\n 5 7\n 8 11\n 3 9", "output": "2\n 1\n 3\n \n\nThe queries in this case correspond to the examples shown in Notes.\n\n* * *"}, {"input": "100000 2\n 1 2\n 3 4", "output": "1\n 1"}] |
Print the answer.
* * * | s826727229 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | 7
5 15
1 10 16 2 7 20 12 | Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s361299971 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | N=int(input())
A,B=map(int,input().split())
p = list(map(int,input().split()))
c=[]
d=[]
e=[]
for i in range(N):
if p[i]<=A:
c.append(p[i])
if A+1 <= p[i] <= B:
d.append(p[i])
if B+1 <= p[i]:
e.append(p[i])
print(min(len(c),len(d),len(e))))
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s373570272 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | n=int(input())
a,b=map(int, input().split())
p=list(map(int, input().split())
c=[0]*3
for i in p:
if i <=a:
c[0] +=1
elif i>b:
c[2] +=1
else:
c[1]+=1
print(min(c)) | Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s246129940 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | n=int(input())
a,b=map(int, input().split())
p=list(map(int, input().split())
c=[0,0,0]
for i in p:
if i <=a:
c[0] +=1
elif i>b:
c[2] +=1
else:
c[1]+=1
print(min(c)) | Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s802038880 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | N, A, B, *P = map(int, open(0).read().split())
b = len(p for p in P if p > A)
c = len(p for p in P if p > B)
print(min(N - b, b - c, c))
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s375370186 | Accepted | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | # _*_ coding:utf-8 _*_
# Atcoder_AISingProgramming_Contest-B
# TODO https://aising2019.contest.atcoder.jp/tasks/aising2019_b
def solveProblem(problemSeed, FirstScore, SecondScore, ScoreList):
firstBarrier = 0
secondBarrier = 0
lastBarrier = 0
for problemNo in range(0, len(ScoreList), +1):
problemScore = ScoreList[problemNo]
if problemScore <= FirstScore:
firstBarrier = firstBarrier + 1
elif (FirstScore + 1 <= problemScore) and (problemScore <= SecondScore):
secondBarrier = secondBarrier + 1
else: # secondScore + 1 <= problemScore
lastBarrier = lastBarrier + 1
problemPattern = min(firstBarrier, secondBarrier, lastBarrier)
answer = problemPattern
return answer
if __name__ == "__main__":
N = int(input().strip())
A, B = map(int, input().strip().split(" "))
Ps = list(map(int, input().strip().split(" ")))
solution = solveProblem(N, A, B, Ps)
print("{}".format(solution))
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s729584251 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
comb = 0
cont = 0
for i in range(0, len(P) - 1):
if comb == 0 and P[i] <= A:
comb += 1
now_i = i
while P[now_i + 1] == P[now_i]:
cont += 1
now_i += 1
if comb == 1 and P[i] >= A + 1 and P[i] <= B:
comb += 1
now_i = i
while P[now_i + 1] == P[now_i]:
cont += 1
now_i += 1
if comb == 2 and P[i] >= B + 1:
comb += 1
now_i = i
while P[now_i + 1] == P[now_i]:
cont += 1
now_i += 1
if comb == 3:
cont += 1
now_i = i
while P[now_i + 1] == P[now_i]:
cont += 1
now_i += 1
if comb == 0 and P[-1] <= A:
comb += 1
now_i = i
if comb == 1 and P[-1] >= A + 1 and P[-1] <= B:
comb += 1
now_i = i
if comb == 2 and P[-1] >= B + 1:
comb += 1
now_i = i
if comb == 3:
cont += 1
now_i = i
print(cont)
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s194124472 | Accepted | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | _, a, b, *p = map(int, open(0).read().split())
print(min([(a < x) + (b < x) for x in p].count(i) for i in [0, 1, 2]))
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s010831637 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | N = int(input())
A,B = map(int,input().split())
*P, = map(int,input().split())
a = len([p for p in P if p<=A])
a = min(a,
len([p for p in P if A<p<=B])
a = min(a,
len([p for p in P if B<p])
print(a) | Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s269018635 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | N=int(input())
A,B = list(map(int, input().split()))
lis = list(map(int, input().split())))
lis_1=[]
lis_2=[]
lis_3=[]
for i in lis:
if i <= A:
lis_1.append(i)
elif i > A and i <=B:
lis_2.append(i)
else:
lis_3.append(i)
print(min[len(lis_1),len(lis_2),len(lis_3)]) | Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s215810943 | Accepted | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | while True:
try:
n = int(input())
a, b = map(int, input().split())
list = map(int, input().split())
a_count, b_count, c_count = [0 for _ in range(3)]
for num in list:
if num <= a:
a_count += 1
elif num > b:
c_count += 1
else:
b_count += 1
print(min(a_count, b_count, c_count))
except EOFError:
exit()
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Print the answer.
* * * | s558087037 | Runtime Error | p03156 | Input is given from Standard Input in the following format:
N
A B
P_1 P_2 ... P_N | n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split())
count = []
for i in n:
if 1<= p[i] and p[i] <= 5:
count1 += 1
elif 6 <= p[i] and p[i] <=15:
count2 += 1
elif 16 <= p[i] and p[i] <=19:
count3 += 1
count.append(count1)
count.append(count2)
count.append(count3)
print(min(count))
| Statement
You have written N problems to hold programming contests. The i-th problem
will have a score of P_i points if used in a contest.
With these problems, you would like to hold as many contests as possible under
the following condition:
* A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.
The same problem should not be used in multiple contests. At most how many
contests can be held? | [{"input": "7\n 5 15\n 1 10 16 2 7 20 12", "output": "2\n \n\nTwo contests can be held by putting the first, second, third problems and the\nfourth, fifth, sixth problems together.\n\n* * *"}, {"input": "8\n 3 8\n 5 5 5 10 10 10 15 20", "output": "0\n \n\nNo contest can be held, because there is no problem with a score of A = 3 or\nless.\n\n* * *"}, {"input": "3\n 5 6\n 5 6 10", "output": "1"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.