結果
問題 |
No.1694 ZerOne
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:52:03 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,956 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 98,584 KB |
最終ジャッジ日時 | 2025-04-16 15:52:56 |
合計ジャッジ時間 | 3,640 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 30 |
ソースコード
from collections import deque def count_possible_strings(s): visited = set() queue = deque([s]) visited.add(s) while queue: current = queue.popleft() n = len(current) # Generate all possible t and u pairs where t is before u for lt in range(n): for rt in range(lt, n): t = current[lt:rt+1] t0 = t.count('0') t1 = len(t) - t0 # Look for u after t for lu in range(rt + 1, n): for ru in range(lu, n): u = current[lu:ru+1] u0 = u.count('0') u1 = len(u) - u0 if t0 == u0 and t1 == u1: # Swap t and u new_str = current[:lt] + u + current[rt+1:lu] + t + current[ru+1:] if new_str not in visited: visited.add(new_str) queue.append(new_str) # Generate all possible t and u pairs where u is before t for lu in range(n): for ru in range(lu, n): u = current[lu:ru+1] u0 = u.count('0') u1 = len(u) - u0 # Look for t after u for lt in range(ru + 1, n): for rt in range(lt, n): t = current[lt:rt+1] t0 = t.count('0') t1 = len(t) - t0 if t0 == u0 and t1 == u1: # Swap u and t new_str = current[:lu] + t + current[ru+1:lt] + u + current[rt+1:] if new_str not in visited: visited.add(new_str) queue.append(new_str) return len(visited) s = input().strip() print(count_possible_strings(s))