結果

問題 No.1694 ZerOne
ユーザー lam6er
提出日時 2025-03-31 17:30:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,225 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,608 KB
実行使用メモリ 146,832 KB
最終ジャッジ日時 2025-03-31 17:31:28
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from collections import deque

def main():
    s = stdin.readline().strip()
    visited = set()
    queue = deque([s])
    visited.add(s)
    n = len(s)
    
    while queue:
        current = queue.popleft()
        cum0 = [0] * (n + 1)
        for i in range(n):
            cum0[i+1] = cum0[i] + (1 if current[i] == '0' else 0)
        
        # Enumerate all possible t and u pairs
        for i in range(n):
            for j in range(i, n):
                t0 = cum0[j+1] - cum0[i]
                t1 = (j - i + 1) - t0
                if t0 == 0 and t1 == 0:
                    continue
                # Search for u after t
                for k in range(j+1, n):
                    for l in range(k, n):
                        u0 = cum0[l+1] - cum0[k]
                        u1 = (l - k + 1) - u0
                        if t0 == u0 and t1 == u1:
                            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)
    print(len(visited))

if __name__ == "__main__":
    main()
0