結果

問題 No.1144 Triangles
ユーザー mkawa2mkawa2
提出日時 2023-12-01 01:53:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,297 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 116,216 KB
最終ジャッジ日時 2023-12-01 01:53:41
合計ジャッジ時間 32,291 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,600 KB
testcase_01 AC 41 ms
55,600 KB
testcase_02 AC 41 ms
55,600 KB
testcase_03 AC 42 ms
55,600 KB
testcase_04 AC 2,183 ms
115,832 KB
testcase_05 AC 2,225 ms
115,260 KB
testcase_06 AC 2,200 ms
116,188 KB
testcase_07 AC 2,171 ms
116,216 KB
testcase_08 AC 2,185 ms
115,228 KB
testcase_09 AC 41 ms
55,600 KB
testcase_10 AC 41 ms
55,600 KB
testcase_11 AC 42 ms
55,600 KB
testcase_12 AC 40 ms
55,600 KB
testcase_13 AC 41 ms
55,600 KB
testcase_14 AC 2,068 ms
111,812 KB
testcase_15 AC 2,013 ms
111,688 KB
testcase_16 AC 2,104 ms
113,056 KB
testcase_17 AC 2,123 ms
113,632 KB
testcase_18 AC 2,152 ms
114,412 KB
testcase_19 AC 320 ms
79,072 KB
testcase_20 AC 113 ms
76,764 KB
testcase_21 AC 119 ms
76,796 KB
testcase_22 AC 2,051 ms
112,816 KB
testcase_23 AC 263 ms
77,996 KB
testcase_24 AC 2,011 ms
111,016 KB
testcase_25 AC 800 ms
84,480 KB
testcase_26 AC 199 ms
77,448 KB
testcase_27 AC 542 ms
88,688 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
md = 10**9+7
# md = 998244353

def arg_sort(xy):
    def msort(xx):
        if not xx: return
        n = len(xx)
        a = [xx, xx[:]]
        lr = [(0, n, 1, 0)]
        while lr:
            l, r, f, g = lr.pop()
            m = (l+r)//2
            if f:
                lr.append((l, r, 0, g))
                if m-l > 1: lr.append((l, m, 1, g ^ 1))
                if r-m > 1: lr.append((m, r, 1, g ^ 1))
            else:
                i, j, p, q = l, m, m-1, r-1
                a1 = a[g]
                a2 = a[g ^ 1]
                for k in range((r-l)//2):
                    x, y = a2[i]
                    s, t = a2[j]
                    if s*y-t*x > 0:
                        a1[l+k] = a2[j]
                        j += 1
                    else:
                        a1[l+k] = a2[i]
                        i += 1
                    x, y = a2[p]
                    s, t = a2[q]
                    if s*y-t*x > 0:
                        a1[r-1-k] = a2[p]
                        p -= 1
                    else:
                        a1[r-1-k] = a2[q]
                        q -= 1
                if (r-l) & 1: a1[m] = a2[i] if i == p else a2[j]

    z1, z2, z3, z4, z5 = [], [], [], [], []
    for x, y in xy:
        if x == y == 0: z5.append((x, y))
        elif y >= 0:
            if x >= 0: z1.append((x, y))
            else: z2.append((x, y))
        else:
            if x < 0: z3.append((x, y))
            else: z4.append((x, y))

    msort(z1)
    msort(z2)
    msort(z3)
    msort(z4)

    return z1+z2+z3+z4+z5

from collections import deque

n = II()
xy = LLI(n)

def r2l():
    global s, t
    x, y = r.popleft()
    s += x*2
    t += y*2
    l.append((x, y))

def lpop():
    global s, t
    x, y = l.popleft()
    s -= x
    t -= y
    return x, y

def rappend(x, y):
    global s, t
    s -= x
    t -= y
    r.append((x, y))

ans = 0
for i in range(n):
    x0, y0 = xy[i]
    nxy = []
    for _ in range(n-1):
        i += 1
        if i == n: i -= n
        nx, ny = xy[i]
        nxy.append((nx-x0, ny-y0))
    nxy = arg_sort(nxy)
    l, r = deque(), deque()
    s = t = 0
    for i, (x, y) in enumerate(nxy):
        if i:
            r.append((x, y))
            s -= x
            t -= y
        else:
            l.append((x, y))
            s += x
            t += y
    for _ in range(n-1):
        if not l: r2l()
        x, y = lpop()
        while r and x*r[0][1]-y*r[0][0] >= 0: r2l()
        ans += x*t%md-y*s%md
        ans %= md
        rappend(x, y)

ans *= pow(6, md-2, md)
print(ans%md)
0