結果

問題 No.1265 Balloon Survival
ユーザー FromBooskaFromBooska
提出日時 2023-02-23 22:08:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,623 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 101,492 KB
最終ジャッジ日時 2023-09-30 21:46:26
合計ジャッジ時間 6,043 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,240 KB
testcase_01 AC 71 ms
71,176 KB
testcase_02 AC 71 ms
71,336 KB
testcase_03 AC 70 ms
71,384 KB
testcase_04 AC 77 ms
71,228 KB
testcase_05 AC 71 ms
71,316 KB
testcase_06 AC 72 ms
71,052 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 72 ms
71,432 KB
testcase_10 WA -
testcase_11 AC 73 ms
71,472 KB
testcase_12 WA -
testcase_13 AC 72 ms
71,344 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 72 ms
71,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 近い点同士がペアとなって消える、だから3つ以上同時はない
# 1番の風船とペアになるものは消す
# ペアから漏れたものも消す
# 近い点同士というのは双方から見て相手が一番近い場合のこと

N = int(input())
XY = []
for i in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
INF = 10**20
distance = [[INF]*N for i in range(N)]
for i in range(N):
    for j in range(i+1, N):
        dsq = (XY[i][0]-XY[j][0])**2 + (XY[i][1]-XY[j][1])**2
        distance[i][j] = dsq
        distance[j][i] = dsq

#print(distance)

# 3つ以上の風船が同時に接触することはない、というのだから
# 単に最低値を探せばいい、最低値複数候補から絞る必要なし

paired = [0]*N
pair0 = -1
for i in range(N):
    if paired[i] == 1:
        continue
    
    #print('i', i)
    mn = INF
    mn_idx = -1
    for j in range(N):
        if paired[j] == 1:
            continue
        if i == j:
            continue
            
        if distance[i][j] < mn:
            mn = distance[i][j]
            mn_idx = j
    #print('j', j)

    for k in range(N):
        test = True
        #print('mn', mn, 'k', k, 'distance[k][j]', distance[k][j])
        if distance[k][mn_idx] < mn:
            test = False
            break
            
    if test == True:
        paired[i] = 1
        paired[mn_idx] = 1
        #print('pairing', XY[i], XY[mn_idx])
        if i == 0:
            pair0 = mn_idx
            
#print(paired)
#print(pair0)

ans = N-1 - sum(paired[1:])
if pair0 > 0:
    ans += 1
print(ans)




0