結果

問題 No.866 レベルKの正方形
ユーザー maspymaspy
提出日時 2020-07-04 17:34:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 5,875 ms / 6,000 ms
コード長 971 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 12,104 KB
実行使用メモリ 497,152 KB
最終ジャッジ日時 2023-10-19 09:28:30
合計ジャッジ時間 86,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 506 ms
42,452 KB
testcase_01 AC 503 ms
42,452 KB
testcase_02 AC 495 ms
42,452 KB
testcase_03 AC 494 ms
42,452 KB
testcase_04 AC 491 ms
42,440 KB
testcase_05 AC 487 ms
42,452 KB
testcase_06 AC 479 ms
42,452 KB
testcase_07 AC 483 ms
42,440 KB
testcase_08 AC 5,453 ms
484,624 KB
testcase_09 AC 5,556 ms
485,328 KB
testcase_10 AC 5,064 ms
485,224 KB
testcase_11 AC 5,505 ms
485,260 KB
testcase_12 AC 5,188 ms
485,304 KB
testcase_13 AC 5,875 ms
485,356 KB
testcase_14 AC 5,347 ms
497,152 KB
testcase_15 AC 5,314 ms
485,376 KB
testcase_16 AC 5,182 ms
485,480 KB
testcase_17 AC 5,334 ms
485,368 KB
testcase_18 AC 5,527 ms
485,340 KB
testcase_19 AC 5,434 ms
497,032 KB
testcase_20 AC 5,050 ms
497,044 KB
testcase_21 AC 4,193 ms
485,416 KB
testcase_22 AC 504 ms
42,408 KB
testcase_23 AC 505 ms
42,396 KB
testcase_24 AC 512 ms
42,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]

INF = np.int32(10 ** 5)


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


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)
low = dp[K - 1]
if K == 26:
    high = np.full_like(low, INF)
else:
    high = dp[K]
for n in range(min(H, W)):
    np.minimum(high[n, n:], n + 1, out=high[n, n:])
    np.minimum(high[n:, n], n + 1, out=high[n:, n])

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