結果
| 問題 | No.1694 ZerOne |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 15:52:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,245 bytes |
| 記録 | |
| コンパイル時間 | 137 ms |
| コンパイル使用メモリ | 81,916 KB |
| 実行使用メモリ | 54,356 KB |
| 最終ジャッジ日時 | 2025-04-16 15:53:49 |
| 合計ジャッジ時間 | 4,110 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 30 |
ソースコード
from collections import deque
def count_possible_strings(S):
visited = set()
queue = deque([S])
visited.add(S)
n = len(S)
while queue:
current = queue.popleft()
# Generate all possible valid swaps
swaps = []
# Find all possible t and u
for t_start in range(n):
for t_end in range(t_start, n):
t = current[t_start:t_end+1]
t0 = t.count('0')
t1 = t.count('1')
# Find u after t
for u_start in range(t_end + 1, n):
for u_end in range(u_start, n):
u = current[u_start:u_end+1]
u0 = u.count('0')
u1 = u.count('1')
if t0 == u0 and t1 == u1:
# Perform swap
new_str = current[:t_start] + u + current[t_end+1:u_start] + t + current[u_end+1:]
swaps.append(new_str)
# Check each generated swap
for s in swaps:
if s not in visited:
visited.add(s)
queue.append(s)
return len(visited)
S = input().strip()
print(count_possible_strings(S))
lam6er