結果

問題 No.866 レベルKの正方形
ユーザー maspymaspy
提出日時 2020-05-14 15:48:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 5,451 ms / 6,000 ms
コード長 993 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 486,880 KB
最終ジャッジ日時 2023-10-13 11:10:01
合計ジャッジ時間 75,455 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,912 KB
testcase_01 AC 134 ms
29,888 KB
testcase_02 AC 137 ms
30,000 KB
testcase_03 AC 135 ms
30,096 KB
testcase_04 AC 135 ms
30,084 KB
testcase_05 AC 135 ms
30,056 KB
testcase_06 AC 134 ms
29,924 KB
testcase_07 AC 140 ms
29,952 KB
testcase_08 AC 4,957 ms
474,976 KB
testcase_09 AC 4,983 ms
474,892 KB
testcase_10 AC 4,777 ms
474,976 KB
testcase_11 AC 5,246 ms
474,840 KB
testcase_12 AC 4,856 ms
475,068 KB
testcase_13 AC 5,451 ms
474,852 KB
testcase_14 AC 4,869 ms
486,880 KB
testcase_15 AC 4,855 ms
475,124 KB
testcase_16 AC 4,710 ms
475,104 KB
testcase_17 AC 4,843 ms
474,976 KB
testcase_18 AC 5,300 ms
474,992 KB
testcase_19 AC 5,106 ms
486,772 KB
testcase_20 AC 4,690 ms
486,812 KB
testcase_21 AC 3,718 ms
474,920 KB
testcase_22 AC 132 ms
29,956 KB
testcase_23 AC 131 ms
29,988 KB
testcase_24 AC 137 ms
30,040 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]

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