結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-01-01 12:21:53 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 539 ms / 2,000 ms |
| コード長 | 612 bytes |
| コンパイル時間 | 119 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 44,544 KB |
| 最終ジャッジ日時 | 2024-11-21 23:27:35 |
| 合計ジャッジ時間 | 18,917 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
S = np.array(list(read().decode('utf-8').rstrip()),'U1')
L = len(S)
INF = 10 ** 9
left_c = np.full(L,-INF,np.int32)
left_c[1:] = np.where(S[:-1] == 'c',np.arange(L-1),-INF)
np.maximum.accumulate(left_c,out=left_c)
L = len(S)
right_w = np.full(L,INF,np.int32)
right_w[:-1] = np.where(S[1:] == 'w',np.arange(1,L),INF)
right_w = np.minimum.accumulate(right_w[::-1])[::-1]
x = right_w - left_c + 1
x[S!='w'] = INF
answer = x.min()
if answer > L:
answer = -1
print(answer)
maspy