結果
| 問題 |
No.1694 ZerOne
|
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 22:57:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,066 bytes |
| コンパイル時間 | 149 ms |
| コンパイル使用メモリ | 82,728 KB |
| 実行使用メモリ | 101,664 KB |
| 最終ジャッジ日時 | 2025-04-15 22:58:53 |
| 合計ジャッジ時間 | 3,793 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 30 |
ソースコード
from collections import deque
def count_reachable(s):
visited = set()
q = deque()
q.append(s)
visited.add(s)
n = len(s)
while q:
current = q.popleft()
# Generate all possible t and u pairs
# Iterate over all possible t and u pairs where t is before 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 = len(t) - t0
# Now 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 = len(u) - u0
if t0 == u0 and t1 == u1:
# Swap t and u
new_str = current[:t_start] + u + current[t_end+1:u_start] + t + current[u_end+1:]
if new_str not in visited:
visited.add(new_str)
q.append(new_str)
# Also check pairs where u is before t
for u_start in range(n):
for u_end in range(u_start, n):
u = current[u_start:u_end+1]
u0 = u.count('0')
u1 = len(u) - u0
# Find t after u
for t_start in range(u_end + 1, n):
for t_end in range(t_start, n):
t = current[t_start:t_end+1]
t0 = t.count('0')
t1 = len(t) - t0
if t0 == u0 and t1 == u1:
new_str = current[:u_start] + t + current[u_end+1:t_start] + u + current[t_end+1:]
if new_str not in visited:
visited.add(new_str)
q.append(new_str)
return len(visited)
# Read input and output the result
s = input().strip()
print(count_reachable(s))
lam6er