結果
| 問題 |
No.1694 ZerOne
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:23:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,224 bytes |
| コンパイル時間 | 197 ms |
| コンパイル使用メモリ | 82,360 KB |
| 実行使用メモリ | 55,256 KB |
| 最終ジャッジ日時 | 2025-06-12 13:27:08 |
| 合計ジャッジ時間 | 3,954 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 30 |
ソースコード
from collections import deque
def count_distinct_strings(s):
visited = set()
q = deque()
q.append(s)
visited.add(s)
n = len(s)
while q:
current = q.popleft()
# Generate all possible swaps
# Find all possible t and u pairs
for t_start in range(n):
for t_end in range(t_start, n):
t = current[t_start:t_end+1]
cnt0_t = t.count('0')
cnt1_t = t.count('1')
# Find u that is 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]
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+1:u_start] + t + current[u_end+1:]
if new_str not in visited:
visited.add(new_str)
q.append(new_str)
return len(visited)
s = input().strip()
print(count_distinct_strings(s))
gew1fw