結果

問題 No.869 ふたつの距離
ユーザー maspymaspy
提出日時 2020-05-14 14:57:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,806 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,860 KB
最終ジャッジ日時 2024-09-15 07:07:23
合計ジャッジ時間 61,746 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 42 WA * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def solve_1d(N, A):
    A0 = A
    n = (N + 1) // 2
    m = N - n
    A -= n * (n - 1) // 2 + m * (m - 1) // 2
    assert A >= 0
    x = np.linspace(0, 1, n + 1)[::-1]
    dx = 1 / (n + n)
    y = []
    for i in range(m):
        t = min(n, A)
        A -= t
        y.append(10 + x[t] + dx)
    x = np.concatenate([x[:-1], y])
    assert len(x) == N
    cnt = 0
    for i in range(N):
        cnt += np.sum(np.abs(x[i] - x[i + 1:]) < 10)
    assert cnt == A0
    return x

def other_points(M):
    x = np.linspace(100, 90000, M)
    y = np.zeros_like(x)
    return x, y

def solve(N, A, B):
    left = 0  # B 未満
    right = N  # B以上
    while left + 1 < right:
        x = (left + right) // 2
        if x * (x - 1) // 2 >= B:
            right = x
        else:
            left = x
    n = right
    x0, y0 = other_points(N - n)
    t = solve_1d(n - 1, A)
    theta = t / 20
    x = np.cos(theta) * 20
    y = np.sin(theta) * 20
    far = n * (n - 1) // 2 - B
    eps = 1e-7
    x[:far] *= (1 + eps)
    y[:far] *= (1 + eps)
    x[far:] *= (1 - eps)
    y[far:] *= (1 - eps)
    x = np.concatenate([[0], x, x0])
    y = np.concatenate([[0], y, y0])
    return x, y

N, A, B = map(int, read().split())

x, y = solve(N, A, B)

def check(N, A, B, x, y):
    assert len(x) == len(y) == N
    dx = np.subtract.outer(x, x)
    dy = np.subtract.outer(y, y)
    d = (dx * dx + dy * dy)**.5
    np.fill_diagonal(d, 30)
    n1 = np.count_nonzero(d <= 10) // 2
    n2 = np.count_nonzero(d <= 20) // 2
    assert n1 == A
    assert n2 == B

# check(N, A, B, x, y)

x, y = solve(N, A, B)
xy = np.vstack([x, y]).T
print('\n'.join(' '.join(row) for row in xy.astype(str)))
0