結果
問題 |
No.3061 Cut and Maximums
|
ユーザー |
![]() |
提出日時 | 2025-05-14 13:21:29 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,161 bytes |
コンパイル時間 | 309 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 54,504 KB |
最終ジャッジ日時 | 2025-05-14 13:23:55 |
合計ジャッジ時間 | 5,504 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 33 |
ソースコード
import sys def solve(): S = sys.stdin.readline().strip() N = len(S) if N == 0: print("NO") return for i in range(N): # Start index of the segment in S that will form T for j in range(i, N): # End index of the segment in S (inclusive) # Length of the segment S[i..j], which is the candidate for T's length t_candidate_len = j - i + 1 if t_candidate_len < 2: # T must be of length at least 2 continue current_kept_chars = set() current_erased_chars = set() possible_to_form_T_with_this_segment = True # Phase 1: Analyze the segment S[i..j] which is supposed to become T # k_in_t is the 0-based index within the candidate T string for k_in_t in range(t_candidate_len): original_char_s_idx = i + k_in_t # Index in original string S original_char = S[original_char_s_idx] if k_in_t % 2 == 0: # This position in T must be a Letter (L-pos) if not original_char.isalpha(): # Original char at L-pos is a space, cannot form T this way possible_to_form_T_with_this_segment = False break # This letter must be "kept" if original_char in current_erased_chars: # Contradiction: letter needed for L-pos was marked for erasure possible_to_form_T_with_this_segment = False break current_kept_chars.add(original_char) else: # This position in T must be a Space (S-pos) if original_char.isalpha(): # Original char is a letter, so it must be erased if original_char in current_kept_chars: # Contradiction: letter for S-pos (to be space) was marked as "kept" possible_to_form_T_with_this_segment = False break current_erased_chars.add(original_char) # If original_char is already a space, it naturally fits an S-pos. if not possible_to_form_T_with_this_segment: continue # Try next segment S[i..j] # Phase 2: Analyze characters outside the segment S[i..j] # These parts (S[0..i-1] and S[j+1..N-1]) must become all spaces. # Any letter in these parts must be erased. # If such a letter is in current_kept_chars (needed for T), it's a contradiction. # Characters before S[i] for p_outer in range(i): char_in_outer_part = S[p_outer] if char_in_outer_part.isalpha(): if char_in_outer_part in current_kept_chars: # This letter is needed for T (as kept), but it's outside T's segment. # Outer parts must be spaces. Contradiction. possible_to_form_T_with_this_segment = False break current_erased_chars.add(char_in_outer_part) # Mark for erasure # If char_in_outer_part is already a space, it's fine. if not possible_to_form_T_with_this_segment: continue # Characters after S[j] for p_outer in range(j + 1, N): char_in_outer_part = S[p_outer] if char_in_outer_part.isalpha(): if char_in_outer_part in current_kept_chars: possible_to_form_T_with_this_segment = False break current_erased_chars.add(char_in_outer_part) if not possible_to_form_T_with_this_segment: continue # If all checks passed, a valid transformation is found. print("Yes") return # If no segment S[i..j] leads to a valid transformation print("NO") solve()