結果
問題 |
No.1376 Simple LPS Problem
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:58:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,450 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 54,584 KB |
最終ジャッジ日時 | 2025-03-20 20:58:52 |
合計ジャッジ時間 | 6,813 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 WA * 17 |
ソースコード
N, K = map(int, input().split()) if K == 1: if N == 1: print(0) else: print(-1) elif K > N: print(-1) else: required_min = (N + 1) // 2 if K < required_min: print(-1) else: if K == N: print('0' * N) else: # Construct the palindrome part if K % 2 == 0: half = K // 2 first_part = ['0'] + ['1'] * (half - 1) first_part = first_part[:half] # Ensure correct length second_part = first_part[::-1] palindrome = ''.join(first_part + second_part) else: m = (K - 1) // 2 first_part = ['0'] + ['1'] * (m - 1) first_part = first_part[:m] # first m-1 characters? middle = ['0'] second_part = first_part[::-1] palindrome = ''.join(first_part + middle + second_part) # Append remaining characters remaining_length = N - K if remaining_length > 0: # The last character of the palindrome is '0' for even, '1' or '0' for odd # We append '1' followed by '0's to break any possible palindromes remaining = '1' + '0' * (remaining_length - 1) result = palindrome + remaining else: result = palindrome print(result)