結果
| 問題 | No.1694 ZerOne |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:51:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,814 bytes |
| 記録 | |
| コンパイル時間 | 176 ms |
| コンパイル使用メモリ | 82,228 KB |
| 実行使用メモリ | 93,220 KB |
| 最終ジャッジ日時 | 2025-03-31 17:52:22 |
| 合計ジャッジ時間 | 3,889 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 30 |
ソースコード
from collections import deque
from sys import stdin
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
# For all possible pairs of non-overlapping substrings
for t_len in range(1, n):
for t_start in range(n - t_len + 1):
t_end = t_start + t_len
t = current[t_start:t_end]
cnt0_t = t.count('0')
cnt1_t = t.count('1')
# Look for u that is non-overlapping and after t
u_max_start = t_end
for u_len in range(1, n - u_max_start + 1):
for u_start in range(u_max_start, n - u_len + 1):
u_end = u_start + u_len
u = current[u_start:u_end]
cnt0_u = u.count('0')
cnt1_u = u.count('1')
if cnt0_t == cnt0_u and cnt1_t == cnt1_u:
# Perform swap
new_str = (
current[:t_start] +
u +
current[t_end:u_start] +
t +
current[u_end:]
)
if new_str not in visited:
visited.add(new_str)
queue.append(new_str)
# Also consider u before t
for u_len in range(1, n):
for u_start in range(n - u_len + 1):
u_end = u_start + u_len
u = current[u_start:u_end]
cnt0_u = u.count('0')
cnt1_u = u.count('1')
# Look for t that is after u
for t_len in range(1, n - u_end + 1):
for t_start in range(u_end, n - t_len + 1):
t_end_new = t_start + t_len
t = current[t_start:t_end_new]
cnt0_t = t.count('0')
cnt1_t = t.count('1')
if cnt0_u == cnt0_t and cnt1_u == cnt1_t:
new_str = (
current[:u_start] +
t +
current[u_end:t_start] +
u +
current[t_end_new:]
)
if new_str not in visited:
visited.add(new_str)
queue.append(new_str)
return len(visited)
s = stdin.readline().strip()
print(count_possible_strings(s))
lam6er