Submission #74092521


Source Code Expand

def count_even_0_to(n):
    if n < 0:
        return 0
    return n // 2 + 1

def black_prefix(a, b):
    # 0 <= x <= a, 0 <= y <= b にある黒点数
    if a < 0 or b < 0:
        return 0
    if a > b:
        a, b = b, a

    k = a // 2
    square = (k + 1) * (2 * k + 1)
    extra = (count_even_0_to(b) - count_even_0_to(a)) * (a + 1)
    return square + extra

def rect_nonneg(x1, x2, y1, y2):
    # 0 <= x1 <= x2, 0 <= y1 <= y2
    if x1 > x2 or y1 > y2:
        return 0
    return (
        black_prefix(x2, y2)
        - black_prefix(x1 - 1, y2)
        - black_prefix(x2, y1 - 1)
        + black_prefix(x1 - 1, y1 - 1)
    )

def count_axis(l, r):
    # 区間 [l,r] の整数のうち偶数の個数
    if l > r:
        return 0
    return r // 2 - (l - 1) // 2

def main():
    L, R, D, U = map(int, input().split())

    ans = 0

    # x<0, x=0, x>0 に分割し、y も同様に分割して数える
    # 負側は絶対値で正側へ写す

    # x>0, y>0
    ans += rect_nonneg(max(L, 1), max(R, 0), max(D, 1), max(U, 0))

    # x<0, y>0
    ans += rect_nonneg(max(-R, 1), max(-L, 0), max(D, 1), max(U, 0))

    # x>0, y<0
    ans += rect_nonneg(max(L, 1), max(R, 0), max(-U, 1), max(-D, 0))

    # x<0, y<0
    ans += rect_nonneg(max(-R, 1), max(-L, 0), max(-U, 1), max(-D, 0))

    # x=0
    if L <= 0 <= R:
        ans += count_axis(D, U)

    # y=0
    if D <= 0 <= U:
        ans += count_axis(L, R)

    # (0,0) を二重計上していれば 1 引く
    if L <= 0 <= R and D <= 0 <= U:
        ans -= 1

    print(ans)

if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task D - Make Target 2
User Yoshi03
Language Python (PyPy 3.11-v7.3.20)
Score 425
Code Size 1656 Byte
Status AC
Exec Time 50 ms
Memory 80256 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 29
Set Name Test Cases
Sample sample00.txt, sample01.txt
All sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt
Case Name Status Exec Time Memory
sample00.txt AC 49 ms 79932 KiB
sample01.txt AC 48 ms 80216 KiB
testcase00.txt AC 48 ms 80036 KiB
testcase01.txt AC 48 ms 80216 KiB
testcase02.txt AC 48 ms 80108 KiB
testcase03.txt AC 49 ms 80092 KiB
testcase04.txt AC 48 ms 79792 KiB
testcase05.txt AC 48 ms 80256 KiB
testcase06.txt AC 48 ms 80072 KiB
testcase07.txt AC 48 ms 80256 KiB
testcase08.txt AC 48 ms 80200 KiB
testcase09.txt AC 48 ms 79964 KiB
testcase10.txt AC 49 ms 80096 KiB
testcase11.txt AC 48 ms 79984 KiB
testcase12.txt AC 48 ms 80088 KiB
testcase13.txt AC 48 ms 80072 KiB
testcase14.txt AC 50 ms 79792 KiB
testcase15.txt AC 48 ms 80084 KiB
testcase16.txt AC 48 ms 80036 KiB
testcase17.txt AC 48 ms 80096 KiB
testcase18.txt AC 48 ms 79772 KiB
testcase19.txt AC 47 ms 79824 KiB
testcase20.txt AC 48 ms 79792 KiB
testcase21.txt AC 48 ms 80064 KiB
testcase22.txt AC 48 ms 79964 KiB
testcase23.txt AC 47 ms 80072 KiB
testcase24.txt AC 48 ms 80052 KiB
testcase25.txt AC 48 ms 80184 KiB
testcase26.txt AC 47 ms 79984 KiB