結果
問題 |
No.291 黒い文字列
|
ユーザー |
![]() |
提出日時 | 2025-06-12 19:06:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,754 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 60,352 KB |
最終ジャッジ日時 | 2025-06-12 19:06:57 |
合計ジャッジ時間 | 2,123 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 13 WA * 13 |
ソースコード
S = input().strip() total_q = S.count('?') def is_possible(x): if x == 0: return True n = len(S) # Check for K positions k_pos = [] used_q_k = 0 current = 0 for _ in range(x): found = False while current < n: if S[current] == 'K' or S[current] == '?': k_pos.append(current) if S[current] == '?': used_q_k += 1 current += 1 found = True break current += 1 if not found: return False # Check for U positions u_pos = [] used_q_u = 0 for k in k_pos: current = k + 1 found = False while current < n: if S[current] == 'U' or S[current] == '?': u_pos.append(current) if S[current] == '?': used_q_u += 1 current += 1 found = True break current += 1 if not found: return False # Check for R positions r_pos = [] used_q_r = 0 for u in u_pos: current = u + 1 found = False while current < n: if S[current] == 'R' or S[current] == '?': r_pos.append(current) if S[current] == '?': used_q_r += 1 current += 1 found = True break current += 1 if not found: return False # Check for O positions o_pos = [] used_q_o = 0 for r in r_pos: current = r + 1 found = False while current < n: if S[current] == 'O' or S[current] == '?': o_pos.append(current) if S[current] == '?': used_q_o += 1 current += 1 found = True break current += 1 if not found: return False # Check for I positions i_pos = [] used_q_i = 0 for o in o_pos: current = o + 1 found = False while current < n: if S[current] == 'I' or S[current] == '?': i_pos.append(current) if S[current] == '?': used_q_i += 1 current += 1 found = True break current += 1 if not found: return False total_used = used_q_k + used_q_u + used_q_r + used_q_o + used_q_i return total_used <= total_q low = 0 high = len(S) // 5 ans = 0 while low <= high: mid = (low + high) // 2 if is_possible(mid): ans = mid low = mid + 1 else: high = mid - 1 print(ans)