結果

問題 No.866 レベルKの正方形
ユーザー maspymaspy
提出日時 2020-03-19 22:24:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 944 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 471,380 KB
最終ジャッジ日時 2023-08-20 21:09:58
合計ジャッジ時間 44,773 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
29,960 KB
testcase_01 AC 136 ms
29,976 KB
testcase_02 AC 137 ms
29,944 KB
testcase_03 AC 137 ms
29,856 KB
testcase_04 AC 134 ms
29,948 KB
testcase_05 AC 136 ms
29,904 KB
testcase_06 AC 134 ms
30,016 KB
testcase_07 AC 136 ms
29,872 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 5,223 ms
471,140 KB
testcase_22 AC 136 ms
29,988 KB
testcase_23 AC 137 ms
29,900 KB
testcase_24 AC 141 ms
29,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

H, W, K = map(int, readline().split())
C = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W]


def calc_alphabet(a):
    INF = np.int32(10 ** 5)
    dp = (C != a) * INF
    for n in range(1, H):
        np.minimum(dp[n - 1] + 1, dp[n], out=dp[n])
    for n in range(1, W):
        np.minimum(dp[:, n - 1] + 1, dp[:, n], out=dp[:, n])
        np.minimum(dp[:-1, n - 1] + 1, dp[1:, n], out=dp[1:, n])
    return dp


dp = np.empty((26, H, W), np.int32)
for i in range(26):
    a = chr(ord('a') + i).encode()
    dp[i] = calc_alphabet(a)


dp.sort(axis=0)
high = dp[K]
low = dp[K - 1]
for n in range(H):
    np.minimum(high[n, n:], n + 1, out=high[n, n:])
for n in range(W):
    np.minimum(high[n:, n], n + 1, out=high[n:, n])

x = high - low
answer = np.maximum(x, 0).sum()
print(answer)
0