結果
問題 | No.291 黒い文字列 |
ユーザー | rpy3cpp |
提出日時 | 2015-10-16 23:46:58 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,542 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-07-21 20:47:07 |
合計ジャッジ時間 | 2,088 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
10,624 KB |
testcase_01 | AC | 31 ms
10,752 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 31 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 31 ms
10,752 KB |
testcase_06 | AC | 30 ms
10,752 KB |
testcase_07 | AC | 31 ms
10,752 KB |
testcase_08 | AC | 32 ms
10,752 KB |
testcase_09 | AC | 31 ms
10,752 KB |
testcase_10 | AC | 31 ms
10,752 KB |
testcase_11 | AC | 31 ms
10,752 KB |
testcase_12 | AC | 33 ms
10,752 KB |
testcase_13 | AC | 31 ms
10,752 KB |
testcase_14 | AC | 31 ms
10,752 KB |
testcase_15 | AC | 32 ms
10,624 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 32 ms
10,624 KB |
testcase_19 | AC | 31 ms
10,752 KB |
testcase_20 | AC | 32 ms
10,752 KB |
testcase_21 | AC | 31 ms
10,752 KB |
testcase_22 | WA | - |
testcase_23 | AC | 32 ms
10,752 KB |
testcase_24 | WA | - |
testcase_25 | AC | 31 ms
10,624 KB |
testcase_26 | AC | 31 ms
10,624 KB |
testcase_27 | AC | 31 ms
10,624 KB |
testcase_28 | AC | 31 ms
10,624 KB |
testcase_29 | AC | 31 ms
10,752 KB |
ソースコード
import itertools S = input() def solve(S): S = [c for c in S if c in 'KUROI?'] S = preprocess(S) target = ['U', 'R', 'O', 'I'] count = 0 while len(S) >= 5: S = S[1:] for pattern in generate_patterns(target): idxs = find_pat(S, pattern) if len(idxs) == len(pattern): count += 1 S = [c for i, c in enumerate(S) if i not in idxs] S = preprocess(S) break else: break return count def find_pat(S, pattern): len_pat = len(pattern) idxs = [] idx = 0 for i, c in enumerate(S): if c == pattern[idx]: idxs.append(i) idx += 1 if idx == len_pat: return idxs return idxs def preprocess(S): for i, c in enumerate(S): if c == 'K' or c == '?': S3 = S[i:] break else: return [] for i in range(len(S3) - 1, -1, -1): if S3[i] == 'I' or S3[i] == '?': S4 = S3[:i + 1] break else: return [] if len(S4) < 5: return [] return S4 def generate_patterns(target): n = len(target) yield target[:] for m in range(1, n + 1): for pattern in generate_pat(target, n, m): yield pattern def generate_pat(target, n, m): for idxs in itertools.combinations(range(n), m): pattern = target[:] for idx in idxs: pattern[idx] = '?' yield pattern print(solve(S))