結果
問題 | No.5007 Steiner Space Travel |
ユーザー | titan23 |
提出日時 | 2022-10-06 13:58:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 124 ms / 1,000 ms |
コード長 | 1,762 bytes |
コンパイル時間 | 229 ms |
実行使用メモリ | 82,804 KB |
スコア | 6,321,103 |
最終ジャッジ日時 | 2022-10-06 13:58:12 |
合計ジャッジ時間 | 5,485 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 106 ms
82,276 KB |
testcase_01 | AC | 110 ms
82,800 KB |
testcase_02 | AC | 107 ms
82,696 KB |
testcase_03 | AC | 112 ms
82,800 KB |
testcase_04 | AC | 122 ms
82,496 KB |
testcase_05 | AC | 113 ms
82,784 KB |
testcase_06 | AC | 109 ms
82,548 KB |
testcase_07 | AC | 109 ms
82,568 KB |
testcase_08 | AC | 121 ms
82,508 KB |
testcase_09 | AC | 114 ms
82,592 KB |
testcase_10 | AC | 108 ms
82,316 KB |
testcase_11 | AC | 108 ms
82,480 KB |
testcase_12 | AC | 107 ms
82,484 KB |
testcase_13 | AC | 107 ms
82,564 KB |
testcase_14 | AC | 124 ms
82,504 KB |
testcase_15 | AC | 109 ms
82,608 KB |
testcase_16 | AC | 105 ms
82,640 KB |
testcase_17 | AC | 112 ms
82,596 KB |
testcase_18 | AC | 108 ms
82,584 KB |
testcase_19 | AC | 111 ms
82,484 KB |
testcase_20 | AC | 107 ms
82,804 KB |
testcase_21 | AC | 107 ms
82,588 KB |
testcase_22 | AC | 110 ms
82,564 KB |
testcase_23 | AC | 107 ms
82,624 KB |
testcase_24 | AC | 107 ms
82,468 KB |
testcase_25 | AC | 109 ms
82,532 KB |
testcase_26 | AC | 106 ms
82,572 KB |
testcase_27 | AC | 106 ms
82,552 KB |
testcase_28 | AC | 109 ms
82,628 KB |
testcase_29 | AC | 108 ms
82,468 KB |
ソースコード
import itertools import random N, M = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] class KMeans: def __init__(self, n_clusters, max_iter = 10, random_seed = 0): self.n_clusters = n_clusters self.max_iter = max_iter def fit(self, X): self.labels_ = [] now = 0 while len(self.labels_) < len(X): self.labels_.append(now) now += 1 now %= self.n_clusters random.shuffle(self.labels_) labels_prev = [0]*len(X) count = 0 self.cluster_centers_ = [(0, 0)] * self.n_clusters while (not (self.labels_ == labels_prev) and count < self.max_iter): syuukei = [[] for _ in range(self.n_clusters)] for i in range(len(X)): syuukei[self.labels_[i]].append(X[i]) for i,l in enumerate(syuukei): if l: x, y = sum(x for x,y in l)//len(l), sum(y for x,y in l)//len(l) else: x, y = random.randint(0, 1000), random.randint(0, 1000) self.cluster_centers_[i] = (x, y) labels_prev = self.labels_[:] for i in range(len(X)): dist = 10**18 for j in range(self.n_clusters): tmp = (X[i][0] - self.cluster_centers_[j][0])**2 + (X[i][1] - self.cluster_centers_[j][1])**2 if tmp < dist: dist = tmp self.labels_[i] = j count += 1 model = KMeans(8) model.fit(AB) labels = model.labels_ centers = model.cluster_centers_ ans = [(1, 0)] L = sorted(enumerate(labels), key=lambda x: x[1]) for i in range(L[-1][1]+1): ans.append((2, i)) for j, cluster_number in L: if cluster_number == i: ans.append((1, j)) ans.append((2, i)) ans.append((1, 0)) for c,d in centers: print(c, d) print(len(ans)) for a,b in ans: print(a, b+1)