Submission #42044772
Source Code Expand
Copy
INF = pow(10,10)N,M = map(int, input().split())S_list = list()for i in range(N):S = list(input())S_list.append(S)# Sを頂点と辺の形式に直すedge = [set() for _ in range(N+1)]inv_edge = [set() for _ in range(N+1)]for i in range(N):for j in range(M):if S_list[i][j] == "1":edge[i+1].add(i+1+j+1) # SもS_listも0始まりなので頂点番号に直すためにi,jともに+1するinv_edge[i+1+j+1].add(i+1)# dpで1からの最短距離を求めるdist_from_1 = [INF for _ in range(N+1)]dist_from_1[1] = 0
INF = pow(10,10) N,M = map(int, input().split()) S_list = list() for i in range(N): S = list(input()) S_list.append(S) # Sを頂点と辺の形式に直す edge = [set() for _ in range(N+1)] inv_edge = [set() for _ in range(N+1)] for i in range(N): for j in range(M): if S_list[i][j] == "1": edge[i+1].add(i+1+j+1) # SもS_listも0始まりなので頂点番号に直すためにi,jともに+1する inv_edge[i+1+j+1].add(i+1) # dpで1からの最短距離を求める dist_from_1 = [INF for _ in range(N+1)] dist_from_1[1] = 0 for i in range(1,N+1): for j in edge[i]: dist_from_1[j] = min(dist_from_1[j],dist_from_1[i]+1) # dpでNへの最短距離を求める dist_to_N = [INF for _ in range(N+1)] dist_to_N[N] = 0 for i in range(N,0,-1): for j in inv_edge[i]: dist_to_N[j] = min(dist_to_N[j],dist_to_N[i]+1) # 各kに対して通らないときの移動回数を求める ans = list() for k in range(2,N): part_ans = INF for u in range(k+1,min(k+M,N+1)): # k+1~k+M-1の都市に対して、(都市はNまでなのでmin条件を入れる) for v in inv_edge[u]: # 張られている辺を各々確認する if v < k: # もし辺の元がk以下ならkを通らないルートなので回数を算出 dist = dist_from_1[v] + 1 + dist_to_N[u] part_ans = min(part_ans,dist) if part_ans != INF: ans.append(part_ans) else: ans.append(-1) # 回答出力 print(*ans)
Submission Info
Submission Time | |
---|---|
Task | F - Teleporter and Closed off |
User | tonomotohide |
Language | PyPy3 (7.3.0) |
Score | 500 |
Code Size | 1619 Byte |
Status | AC |
Exec Time | 597 ms |
Memory | 224660 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt |
All | colored_00.txt, colored_01.txt, colored_02.txt, colored_03.txt, colored_04.txt, colored_05.txt, colored_06.txt, colored_07.txt, colored_08.txt, colored_09.txt, colored_10.txt, colored_11.txt, colored_12.txt, colored_13.txt, colored_14.txt, colored_15.txt, colored_16.txt, colored_17.txt, colored_18.txt, colored_19.txt, colored_20.txt, colored_21.txt, colored_22.txt, colored_23.txt, colored_24.txt, colored_25.txt, example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
colored_00.txt | AC | 437 ms | 181536 KB |
colored_01.txt | AC | 446 ms | 186072 KB |
colored_02.txt | AC | 431 ms | 186856 KB |
colored_03.txt | AC | 424 ms | 181332 KB |
colored_04.txt | AC | 440 ms | 185600 KB |
colored_05.txt | AC | 455 ms | 191860 KB |
colored_06.txt | AC | 414 ms | 180660 KB |
colored_07.txt | AC | 422 ms | 192044 KB |
colored_08.txt | AC | 436 ms | 182464 KB |
colored_09.txt | AC | 431 ms | 184692 KB |
colored_10.txt | AC | 386 ms | 181876 KB |
colored_11.txt | AC | 425 ms | 185512 KB |
colored_12.txt | AC | 389 ms | 169680 KB |
colored_13.txt | AC | 411 ms | 186236 KB |
colored_14.txt | AC | 478 ms | 191480 KB |
colored_15.txt | AC | 397 ms | 172212 KB |
colored_16.txt | AC | 437 ms | 186300 KB |
colored_17.txt | AC | 439 ms | 180976 KB |
colored_18.txt | AC | 410 ms | 177320 KB |
colored_19.txt | AC | 433 ms | 179632 KB |
colored_20.txt | AC | 554 ms | 201900 KB |
colored_21.txt | AC | 417 ms | 176784 KB |
colored_22.txt | AC | 452 ms | 180728 KB |
colored_23.txt | AC | 438 ms | 182892 KB |
colored_24.txt | AC | 434 ms | 183044 KB |
colored_25.txt | AC | 531 ms | 206456 KB |
example_00.txt | AC | 51 ms | 61568 KB |
example_01.txt | AC | 52 ms | 61804 KB |
hand_00.txt | AC | 597 ms | 224660 KB |
hand_01.txt | AC | 300 ms | 150740 KB |
hand_02.txt | AC | 358 ms | 191040 KB |
hand_03.txt | AC | 394 ms | 193268 KB |
hand_04.txt | AC | 527 ms | 216876 KB |
hand_05.txt | AC | 290 ms | 168244 KB |
hand_06.txt | AC | 385 ms | 190912 KB |
hand_07.txt | AC | 361 ms | 190256 KB |
random_00.txt | AC | 446 ms | 181796 KB |
random_01.txt | AC | 476 ms | 190048 KB |
random_02.txt | AC | 51 ms | 62120 KB |
random_03.txt | AC | 472 ms | 192636 KB |
random_04.txt | AC | 461 ms | 186668 KB |
random_05.txt | AC | 50 ms | 62096 KB |
random_06.txt | AC | 481 ms | 189688 KB |
random_07.txt | AC | 477 ms | 193516 KB |
random_08.txt | AC | 52 ms | 61800 KB |
random_09.txt | AC | 433 ms | 182440 KB |
random_10.txt | AC | 458 ms | 188816 KB |
random_11.txt | AC | 50 ms | 61544 KB |
random_12.txt | AC | 397 ms | 177280 KB |
random_13.txt | AC | 366 ms | 164844 KB |