結果

問題 No.3061 Cut and Maximums
ユーザー gew1fw
提出日時 2025-06-12 19:25:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 54,228 KB
最終ジャッジ日時 2025-06-12 19:25:09
合計ジャッジ時間 4,404 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input().strip()
n = len(S)
found = False

for start in range(n):
    for end in range(start + 1, n):
        length = end - start + 1
        valid = True
        B = set()  # Characters in odd positions (1-based) of the substring
        C = set()  # Characters in even positions (1-based) that need to be replaced with space
        
        for i in range(length):
            pos = start + i
            char = S[pos]
            if (i + 1) % 2 == 1:  # Odd position (1-based)
                if char == ' ':
                    valid = False
                    break
                B.add(char)
            else:  # Even position (1-based)
                if char != ' ':
                    C.add(char)
        
        if not valid:
            continue
        
        # Collect characters in the surrounding areas (A)
        A = set()
        # Check before start
        for i in range(start):
            c = S[i]
            if c != ' ':
                A.add(c)
        # Check after end
        for i in range(end + 1, n):
            c = S[i]
            if c != ' ':
                A.add(c)
        
        # Check if B and (A ∪ C) are disjoint
        if B.intersection(A) or B.intersection(C):
            continue
        
        found = True
        break
    if found:
        break

print("Yes" if found else "NO")
0