結果

問題 No.1028 闇討ち
ユーザー SayanoSayano
提出日時 2020-04-17 22:27:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 801 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 109,280 KB
最終ジャッジ日時 2024-04-14 14:44:58
合計ジャッジ時間 9,646 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 515 ms
51,424 KB
testcase_01 AC 514 ms
44,480 KB
testcase_02 AC 511 ms
44,232 KB
testcase_03 AC 512 ms
44,484 KB
testcase_04 AC 510 ms
44,476 KB
testcase_05 AC 519 ms
44,480 KB
testcase_06 AC 543 ms
44,484 KB
testcase_07 AC 519 ms
44,480 KB
testcase_08 AC 532 ms
44,352 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())

grid = []
for i in range(N):
    row = [int(c) for c in input().split(' ')]
    grid.append(row)
grid = np.array(grid)

j_s = np.tile(np.arange(N), (N,1))
i_s = np.tile(np.arange(N).reshape(N, 1), N)
distances = [
    np.where((i_s + j_s >= x) & (i_s - j_s <= x), j_s, abs(x - i_s))
    for x in range(N)
]
# 各社員に対して、最適な攻撃位置を求める
attack_distance = np.zeros_like(grid)

optimal_sum = 0
for k in range(N):
    ks_house = np.where(grid == k+1, 1, 0)
    ks_house_distance = []
    for x in range(N):
        # 位置(x, 1)から攻撃したときのドローンの距離の総和
        ks_house_distance.append(np.where(ks_house == 1, distances[x], 0).sum())
    
    optimal_sum += np.min(ks_house_distance)
print(optimal_sum)
0