結果
| 問題 | 
                            No.1694 ZerOne
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 16:29:22 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,024 bytes | 
| コンパイル時間 | 315 ms | 
| コンパイル使用メモリ | 82,688 KB | 
| 実行使用メモリ | 103,168 KB | 
| 最終ジャッジ日時 | 2025-06-12 16:29:27 | 
| 合計ジャッジ時間 | 4,013 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | TLE * 1 -- * 30 | 
ソースコード
from collections import deque
def count_possible_strings(s):
    n = len(s)
    visited = set()
    queue = deque()
    
    visited.add(s)
    queue.append(s)
    
    while queue:
        current = queue.popleft()
        
        for i in range(n):
            for j in range(i+1, n+1):
                t = current[i:j]
                t0 = t.count('0')
                t1 = t.count('1')
                
                for k in range(j, n):
                    for l in range(k+1, n+1):
                        u = current[k:l]
                        u0 = u.count('0')
                        u1 = u.count('1')
                        
                        if t0 == u0 and t1 == u1:
                            new_str = current[:i] + u + current[j:k] + t + current[l:]
                            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))
            
            
            
        
            
gew1fw