結果

問題 No.1694 ZerOne
ユーザー gew1fw
提出日時 2025-06-12 13:24:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,287 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,148 KB
実行使用メモリ 111,088 KB
最終ジャッジ日時 2025-06-12 13:30:10
合計ジャッジ時間 3,963 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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 t and u pairs
        # t is [i, j], u is [k, l], i <= j < k <= l
        # Check all possible pairs of non-overlapping substrings
        for i in range(n):
            for j in range(i, n):
                # Calculate count0 and count1 for t
                t0 = current[i:j+1].count('0')
                t1 = j - i + 1 - t0
                # Now find u starting from j+1 onwards
                for k in range(j+1, n):
                    for l in range(k, n):
                        u0 = current[k:l+1].count('0')
                        u1 = l - k + 1 - u0
                        if t0 == u0 and t1 == u1:
                            # Swap t and u
                            # Create new string
                            new_str = current[:i] + current[k:l+1] + current[j+1:k] + current[i:j+1] + current[l+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))
0