def test_all(f):
for i, data in enumerate(eval(f'test_data{f.__name__[0]}')):
exp = data["out"]
ans = f(*data["in"])
result = "AC" if exp == ans else "WA"
print(f"{i+1} {result}: expected: {exp}, output: {ans}")
コンテスト中の終了間際提出が変数名間違えるという凡ミスしてたので修正したのが以下。
でも結局RE x 4...
import numpy as np
def D(T, NDK):
for n, D, k in NDK:
D = D % n
if n % D == 0:
cycle = n // D
else:
cycle = np.lcm(D, n) // D
if cycle == 0:
d = 0
m = k
else:
d, m = divmod(k - 1, cycle)
m += 1
# print(k, m, cycle)
print((d + (D * (m - 1))) % n)
return test_all(D)
import numpy as np
def D(T, NDK):
for N, D, K in NDK:
if D % N == 0:
cycle = 1
else:
D = D % N
cycle = np.lcm(D, N) // D
K -= 1
print(D * K % N + K // cycle)
return test_all(D)
from itertools import combinations
from collections import defaultdict
def E(N, A):
ans = 0
for i, j in combinations(range(N), 2):
if A[i] == A[j]: continue
ans += min(i + 1, N - j)
return ans
test_all(E)
def E(N, A):
p = defaultdict(list)
for i, a in enumerate(A, 1):
p[a].append(i)
res = 0
for i in range(1, N + 1): res += (N + 1 - i) * (i // 2)
for v in p.values():
l = 0; r = len(v) - 1
while l < r:
if v[l] < (N + 1 - v[r]):
res -= (r - l) * v[l]
l += 1
else:
res -= (r - l) * (N + 1 - v[r])
r -= 1
return res
test_all(E)