The long hand and the short hand meet 11 times in 12 hours. Naturally, the number of seconds of 12 hours is divided by 11 and the number of seconds is calculated as the number of seconds next to the current time. The difference is the answer.
from bisect import bisect_left
A, B = map(int, input().split())
x = [i * 12 * 60 * 60 // 11 for i in range(12)]
t = (A * 60 + B) % (12 * 60) * 60
print(x[bisect_left(x, t)] - t)
If you read it carefully, it's not "the remainder of dividing the answer by 10 9 </ sup> + 7", but "the remainder of dividing the answer by 10 9 </ sup> + 7" orz. Then it's easy to solve. Many people got caught up in this because of the number of people who solved it (laughs).
m = 1000000007
def make_factorial_table(n):
result = [0] * (n + 1)
result[0] = 1
for i in range(1, n + 1):
result[i] = result[i - 1] * i % m
return result
N, *A = map(int, open(0).read().split())
A.sort()
if A[0] == 0:
print(-1)
exit()
if A[-1] >= 4:
print(m)
exit()
fac = make_factorial_table(3)
t = 1
for a in A:
t *= pow(a, fac[a])
if t > m:
break
print(m % t)
Around the time I drew K, I thought, "Oh, I've solved a similar problem in the past," but I couldn't solve it. [ABC044C --Takahashi-kun and Card](https://atcoder.jp/contests/ It's almost the same as abc044 / tasks / arc060_a) (the difference between the average being just X and the average being X or more).
If a i </ sub> = A i </ sub> -K, then the question is how many ways to choose the total of a i </ sub> to be 0 or more. You can easily find it by doing DP.
m = 1000000007
N, K, *A = map(int, open(0).read().split())
for i in range(N):
A[i] -= K
dp = {}
dp[0] = 1
for a in A:
for k in sorted(dp, reverse=True) if a >= 0 else sorted(dp):
dp.setdefault(k + a, 0)
dp[k + a] += dp[k]
dp[0] -= 1
print(sum(dp[k] for k in dp if k >= 0) % m)
Recommended Posts