結果
問題 | No.2696 Sign Creation |
ユーザー | LyricalMaestro |
提出日時 | 2024-11-02 20:29:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,518 ms / 2,500 ms |
コード長 | 3,265 bytes |
コンパイル時間 | 499 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 107,868 KB |
最終ジャッジ日時 | 2024-11-02 20:29:57 |
合計ジャッジ時間 | 16,874 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
68,304 KB |
testcase_01 | AC | 61 ms
67,644 KB |
testcase_02 | AC | 42 ms
55,116 KB |
testcase_03 | AC | 50 ms
62,540 KB |
testcase_04 | AC | 66 ms
69,836 KB |
testcase_05 | AC | 57 ms
65,360 KB |
testcase_06 | AC | 55 ms
66,180 KB |
testcase_07 | AC | 51 ms
62,364 KB |
testcase_08 | AC | 165 ms
78,104 KB |
testcase_09 | AC | 90 ms
76,644 KB |
testcase_10 | AC | 204 ms
78,928 KB |
testcase_11 | AC | 113 ms
76,444 KB |
testcase_12 | AC | 114 ms
76,240 KB |
testcase_13 | AC | 1,082 ms
85,772 KB |
testcase_14 | AC | 600 ms
85,916 KB |
testcase_15 | AC | 546 ms
85,424 KB |
testcase_16 | AC | 941 ms
85,768 KB |
testcase_17 | AC | 541 ms
76,360 KB |
testcase_18 | AC | 467 ms
78,896 KB |
testcase_19 | AC | 678 ms
82,340 KB |
testcase_20 | AC | 147 ms
76,788 KB |
testcase_21 | AC | 435 ms
89,756 KB |
testcase_22 | AC | 700 ms
78,624 KB |
testcase_23 | AC | 579 ms
84,300 KB |
testcase_24 | AC | 596 ms
84,300 KB |
testcase_25 | AC | 721 ms
81,420 KB |
testcase_26 | AC | 544 ms
77,404 KB |
testcase_27 | AC | 632 ms
78,212 KB |
testcase_28 | AC | 539 ms
78,676 KB |
testcase_29 | AC | 629 ms
76,892 KB |
testcase_30 | AC | 539 ms
76,712 KB |
testcase_31 | AC | 1,518 ms
107,868 KB |
testcase_32 | AC | 59 ms
67,260 KB |
testcase_33 | AC | 81 ms
76,136 KB |
testcase_34 | AC | 74 ms
74,920 KB |
testcase_35 | AC | 41 ms
54,248 KB |
testcase_36 | AC | 41 ms
54,980 KB |
testcase_37 | AC | 42 ms
54,696 KB |
testcase_38 | AC | 40 ms
55,064 KB |
testcase_39 | AC | 51 ms
62,360 KB |
testcase_40 | AC | 49 ms
61,988 KB |
ソースコード
## https://yukicoder.me/problems/no/2696 from collections import deque def main(): H, W, N, D = map(int, input().split()) xy = [] for _ in range(N): x, y = map(int, input().split()) xy.append((x - 1, y -1)) # 座標から星idを取れるようにする star_map = {} for i in range(N): x, y = xy[i] star_map[(x, y)] = i # 連結成分ごとに分ける components_list = [-1] * N component_id = 0 for s in range(N): if components_list[s] == -1: queue = deque() queue.append(s) components_list[s] = component_id while len(queue) > 0: v = queue.popleft() h, w = xy[v] for di in range(-5, 6): for dj in range(-5, 6): if abs(di) + abs(dj) > D: continue if di == 0 and dj == 0: continue new_h = h + di new_w = w + dj if 0 <= new_h < H and 0 <= new_w < W: if (new_h, new_w) in star_map: new_v = star_map[(new_h, new_w)] if components_list[new_v] == -1: components_list[new_v] = component_id queue.append(new_v) component_id += 1 # 星の集合の中にどれくらい星があるかを入れる component_id_map = {} for i in range(N): c_id = components_list[i] if c_id not in component_id_map: component_id_map[c_id] = 0 component_id_map[c_id] += 1 base_size = 0 for key, volume in component_id_map.items(): if volume > 1: base_size += 1 min_size = base_size max_size = base_size # それぞれの座標に星を置いた時の調査 for h in range(H): for w in range(W): if (h, w) in star_map: continue seiza_set = set() b = set() for di in range(-5, 6): for dj in range(-5, 6): if abs(di) + abs(dj) > D: continue if di == 0 and dj == 0: continue new_h = h + di new_w = w + dj if 0 <= new_h < H and 0 <= new_w < W: if (new_h, new_w) in star_map: i = star_map[(new_h, new_w)] x = components_list[i] if component_id_map[x] == 1: b.add(x) else: seiza_set.add(x) ans = 0 if len(seiza_set) > 0: ans = 1 - len(seiza_set) elif len(b) > 0: ans = 1 min_size = min(min_size, base_size + ans) max_size = max(max_size, base_size + ans) print(min_size, max_size) if __name__ == "__main__": main()