結果

問題 No.1144 Triangles
ユーザー mkawa2mkawa2
提出日時 2022-09-06 13:05:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,125 bytes
コンパイル時間 1,461 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 252,504 KB
最終ジャッジ日時 2024-11-21 14:36:39
合計ジャッジ時間 56,932 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
61,320 KB
testcase_01 AC 36 ms
216,148 KB
testcase_02 AC 36 ms
60,556 KB
testcase_03 AC 38 ms
61,356 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 38 ms
60,308 KB
testcase_10 AC 37 ms
213,852 KB
testcase_11 AC 37 ms
60,764 KB
testcase_12 AC 36 ms
210,748 KB
testcase_13 AC 35 ms
60,732 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 282 ms
85,324 KB
testcase_20 AC 83 ms
235,656 KB
testcase_21 AC 86 ms
83,712 KB
testcase_22 TLE -
testcase_23 AC 543 ms
78,596 KB
testcase_24 TLE -
testcase_25 AC 2,789 ms
112,068 KB
testcase_26 AC 321 ms
77,380 KB
testcase_27 AC 1,164 ms
105,384 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(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 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

class Vector:
    def __init__(self, x, y, init_x=1, init_y=0):
        self.x = x
        self.y = y
        self.norm2 = x*x+y*y
        self.norm = self.norm2**0.5
        self.zone = 2
        if x == y == 0: self.zone = -1
        elif init_x*y-init_y*x > 0: self.zone = 1
        elif init_x*y-init_y*x < 0: self.zone = 3
        elif init_x*x+init_y*y > 0: self.zone = 0

    def __repr__(self):
        return "({},{})".format(self.x, self.y)

    def __eq__(self, other):
        if self.zone != other.zone: return False
        return self.outer(other) == 0

    def __lt__(self, other):
        if self.zone == other.zone: return self.outer(other) > 0
        return self.zone < other.zone

    def __add__(self, other): return Vector(self.x+other.x, self.y+other.y)

    def __sub__(self, other): return Vector(self.x-other.x, self.y-other.y)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __neg__(self):
        return Vector(-self.x, -self.y)

    def __mul__(self, val):
        return Vector(val*self.x, val*self.y)

    __rmul__ = __mul__

    def __truediv__(self, val):
        assert val != 0
        return Vector(self.x/val, self.y/val)

    def dot(self, v): return self.x*v.x+self.y*v.y

    def outer(self, v): return self.x*v.y-self.y*v.x

    def rot90(self): return Vector(-self.y, self.x)

def naive(i):
    x, y = xy[i]
    res = 0
    for j in range(n):
        if j == i: continue
        s, t = xy[j]
        v1 = Vector(s-x, t-y)
        for k in range(j):
            if k == i: continue
            p, q = xy[k]
            v2 = Vector(p-x, q-y)
            res += abs(v1.outer(v2))
    return res

def sp(i):
    p, q = xy[i]
    vv = [Vector(x-p, y-q) for j, (x, y) in enumerate(xy) if j != i]
    vv.sort()
    s = Vector(0, 0)
    for i in range(1, n-1): s += vv[i]
    j = 1
    res = 0
    for i, v in enumerate(vv):
        if j == i:
            s -= vv[j]
            j = (j+1)%(n-1)
        while vv[j].outer(v) < 0:
            s -= vv[j]
            j = (j+1)%(n-1)
        res += s.outer(v)
        res %= md
        s += v
    return res

n = II()
xy = LLI(n)

ans = 0
for i in range(n):
    ans += sp(i)
    ans %= md
    # print(sp(i), naive(i))

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