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}")
def transpose(A):
return ["".join(r) for r in zip(*A)]
def proc(m):
ret = 0
for r in m:
for c in range(len(r)):
right = r[c:]+r[:c]
left = right[::-1]
ret = max(ret, int(right), int(left))
return ret
def B(N, A):
return max([proc(m) for m in [
A,
transpose(A),
transpose([r[i:]+r[:i] for i, r in enumerate(A)]),
transpose([r[::-1][i:]+r[::-1][:i] for i, r in enumerate(A)]),
]])test_all(B)
def C(N, Q, S, qs):
top = 0
ret = []
for q, x in qs:
if q == 1:
top = (top + N - x) % N
else:
ret.append(S[(top + x - 1) % N])
return "\n".join(ret)test_all(C)
def D(N, X, A, B):
*AB, = zip(A, B)
ans = 10 ** 19
acc = 0
for i, (a, b) in enumerate(AB[:min(N, X)], start=1):
acc += a + b
if acc > ans: break
ans = min(ans, acc + b * (X - i))
return anstest_all(D)
def D(N, X, A, B):
*AB, = zip(A, B)
acc = 0
return min((acc := acc + a + b) + b * (X - i) for i, (a, b) in enumerate(AB[:min(N, X)], start=1))test_all(D)
from itertools import accumulate
from operator import add
def main(N, X, A, B):
*acc, = accumulate(map(add, A, B))
return min(B[i] * (X-i-1) + acc[i] for i in range(min(N, X)))test_all(D)