結果

問題 No.1265 Balloon Survival
ユーザー uni_pythonuni_python
提出日時 2020-11-01 22:55:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,436 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 130,144 KB
最終ジャッジ日時 2023-09-29 11:31:03
合計ジャッジ時間 19,381 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,148 KB
testcase_01 AC 73 ms
71,300 KB
testcase_02 AC 71 ms
71,104 KB
testcase_03 AC 70 ms
71,344 KB
testcase_04 AC 70 ms
71,352 KB
testcase_05 AC 71 ms
71,256 KB
testcase_06 AC 69 ms
71,244 KB
testcase_07 AC 69 ms
71,348 KB
testcase_08 AC 69 ms
71,420 KB
testcase_09 AC 69 ms
71,616 KB
testcase_10 AC 70 ms
71,492 KB
testcase_11 AC 70 ms
71,140 KB
testcase_12 AC 70 ms
71,620 KB
testcase_13 AC 70 ms
71,416 KB
testcase_14 AC 190 ms
81,300 KB
testcase_15 AC 158 ms
81,228 KB
testcase_16 AC 99 ms
76,412 KB
testcase_17 AC 724 ms
105,292 KB
testcase_18 AC 120 ms
79,932 KB
testcase_19 AC 101 ms
76,716 KB
testcase_20 AC 173 ms
81,312 KB
testcase_21 AC 354 ms
90,356 KB
testcase_22 AC 227 ms
85,840 KB
testcase_23 AC 251 ms
86,424 KB
testcase_24 AC 1,432 ms
128,688 KB
testcase_25 AC 1,436 ms
129,628 KB
testcase_26 AC 1,422 ms
130,144 KB
testcase_27 AC 1,382 ms
129,600 KB
testcase_28 AC 1,360 ms
130,112 KB
testcase_29 AC 1,428 ms
130,096 KB
testcase_30 AC 1,355 ms
130,012 KB
testcase_31 AC 1,410 ms
129,604 KB
testcase_32 AC 1,351 ms
130,000 KB
testcase_33 AC 1,378 ms
129,896 KB
testcase_34 AC 69 ms
71,468 KB
testcase_35 AC 69 ms
71,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input=sys.stdin.readline
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))



    N=I()

    if N==1:
        print(0)
        exit()
    if N==2:
        print(1)
        exit()

    X=[0]*N
    Y=[0]*N
    for i in range(N):
        X[i],Y[i]=MI()

    M=10**3+1
    M2=M*M

    def enc(d,i,j):
        temp=d*M2 + i*M + j
        return temp

    def dec(temp):
        d,ij=divmod(temp,M2)
        i,j=divmod(ij,M)
        return d,i,j




    # 取り除いた or 消えた
    used=[0]*N

    L=[0]*(N*(N-1)//2)
    k=0

    for i in range(N):
        for j in range(i+1,N):
            d=(X[i]-X[j])**2 + (Y[i]-Y[j])**2
            L[k]=enc(d,i,j)
            k+=1

    ans=0
    L.sort()
    S=0

    for aaa in L:
        _,i,j=dec(aaa)
        if i==0:
            if used[j]==0:
                ans+=1
                used[j]=1
                S+=1
        if used[i]==0 and used[j]==0:
            used[i]=1
            used[j]=1
            S+=2
        if S==N-1:
            break
            
    print(ans)

main()
0